--- a/libpurple/protocols/zephyr/zephyr.c Sat Dec 19 03:11:32 2020 -0600
+++ b/libpurple/protocols/zephyr/zephyr.c Sun Dec 20 00:47:13 2020 -0600
@@ -107,12 +107,6 @@
-parse_tree null_parse_tree = {
/* struct I need for html<->zephyr */
@@ -955,31 +949,35 @@
-static int free_parse_tree(parse_tree* tree) {
+free_parse_tree(parse_tree *tree)
+ for (i = 0; i < tree->num_children; i++) { + free_parse_tree(tree->children[i]);
- for(i=0;i<tree->num_children;i++){
- if (tree->children[i]) {
- free_parse_tree(tree->children[i]);
- if (tree != &null_parse_tree) {
- g_free(tree->contents);
+ g_free(tree->contents); -static parse_tree *tree_child(parse_tree* tree,int index) {
- if (index < tree->num_children) {
- return tree->children[index];
- return &null_parse_tree;
+tree_child(const parse_tree *tree, int index) + g_return_val_if_fail(tree && tree->num_children > index, NULL); + return tree->children[index]; +tree_child_contents(const parse_tree *tree, int index) + parse_tree *child = tree_child(tree, index); + return child ? child->contents : ""; static parse_tree *find_node(parse_tree* ptree,gchar* key)
@@ -987,19 +985,19 @@
- return &null_parse_tree;
- tc = tree_child(ptree,0)->contents;
+ tc = tree_child_contents(ptree, 0); /* g_strcasecmp() is deprecated. What is the encoding here??? */
if (ptree->num_children > 0 && tc && !g_ascii_strcasecmp(tc, key)) {
- parse_tree *result = &null_parse_tree;
+ parse_tree *result = NULL; for(i = 0; i < ptree->num_children; i++) {
result = find_node(ptree->children[i],key);
- if(result != &null_parse_tree) {
@@ -1161,37 +1159,30 @@
if (newparsetree != NULL) {
- if ( (spewtype = tree_child(find_node(newparsetree,"tzcspew"),2)->contents) ) {
+ if ( (spewtype = tree_child_contents(find_node(newparsetree, "tzcspew"), 2)) ) { if (!g_ascii_strncasecmp(spewtype,"message",7)) {
parse_tree *msgnode = tree_child(find_node(newparsetree,"message"),2);
- parse_tree *bodynode = tree_child(msgnode,1);
- /* char *zsig = g_strdup(" "); */ /* purple doesn't care about zsigs */
- char *msg = zephyr_tzc_deescape_str(bodynode->contents);
+ /*char *zsig = g_strdup(" ");*/ /* purple doesn't care about zsigs */ + char *msg = zephyr_tzc_deescape_str(tree_child_contents(msgnode, 1)); size_t bufsize = strlen(msg) + 3;
char *buf = g_new0(char,bufsize);
g_snprintf(buf,1+strlen(msg)+2," %c%s",'\0',msg);
memset((char *)¬ice, 0, sizeof(notice));
- notice.z_opcode = tree_child(find_node(newparsetree,"opcode"),2)->contents;
- notice.z_class = zephyr_tzc_deescape_str(tree_child(find_node(newparsetree,"class"),2)->contents);
- notice.z_class_inst = tree_child(find_node(newparsetree,"instance"),2)->contents;
- notice.z_recipient = local_zephyr_normalize(zephyr,tree_child(find_node(newparsetree,"recipient"),2)->contents);
- notice.z_sender = local_zephyr_normalize(zephyr,tree_child(find_node(newparsetree,"sender"),2)->contents);
+ notice.z_opcode = tree_child_contents(find_node(newparsetree, "opcode"), 2); + notice.z_class = zephyr_tzc_deescape_str(tree_child_contents(find_node(newparsetree, "class"), 2)); + notice.z_class_inst = tree_child_contents(find_node(newparsetree, "instance"), 2); + notice.z_recipient = local_zephyr_normalize(zephyr, tree_child_contents(find_node(newparsetree, "recipient"), 2)); + notice.z_sender = local_zephyr_normalize(zephyr, tree_child_contents(find_node(newparsetree, "sender"), 2)); notice.z_default_format = "Class $class, Instance $instance:\n" "To: @bold($recipient) at $time $date\n" "From: @bold($1) <$sender>\n\n$2";
notice.z_message_len = strlen(msg) + 3;
handle_message(gc, ¬ice);
- /* free_parse_tree(msgnode);
- free_parse_tree(bodynode);
else if (!g_ascii_strncasecmp(spewtype,"zlocation",9)) {
/* check_loc or zephyr_zloc respectively */
@@ -1199,10 +1190,11 @@
+ gboolean has_locations; - user = tree_child(find_node(newparsetree,"user"),2)->contents;
+ user = tree_child_contents(find_node(newparsetree, "user"), 2); if ((b = purple_blist_find_buddy(purple_connection_get_account(gc), user)) == NULL) {
gchar *stripped_user = zephyr_strip_local_realm(zephyr,user);
@@ -1210,15 +1202,10 @@
locations = find_node(newparsetree,"locations");
- locval = tree_child(tree_child(tree_child(tree_child(locations,2),0),0),2)->contents;
- if (!locval || !g_ascii_strcasecmp(locval," ") || !*locval) {
+ locval = tree_child_contents(tree_child(tree_child(tree_child(locations, 2), 0), 0), 2); + has_locations = (locval && *locval && !purple_strequal(locval, " ")); bname = b ? purple_buddy_get_name(b) : NULL;
+ name = b ? bname : user; if ((b && pending_zloc(zephyr,bname)) || pending_zloc(zephyr,user) || pending_zloc(zephyr,local_zephyr_normalize(zephyr,user))){
PurpleNotifyUserInfo *user_info = purple_notify_user_info_new();
@@ -1226,31 +1213,26 @@
/* TODO: Check whether it's correct to call add_pair_html,
or if we should be using add_pair_plaintext */
- purple_notify_user_info_add_pair_html(user_info, _("User"), (b ? bname : user));
+ purple_notify_user_info_add_pair_html(user_info, _("User"), name); balias = b ? purple_buddy_get_local_alias(b) : NULL;
purple_notify_user_info_add_pair_plaintext(user_info, _("Alias"), balias);
purple_notify_user_info_add_pair_plaintext(user_info, NULL, _("Hidden or not logged-in"));
/* TODO: Need to escape the two strings that make up tmp? */
- tmp = g_strdup_printf(_("<br>At %s since %s"),
- tree_child(tree_child(tree_child(tree_child(locations,2),0),0),2)->contents,
- tree_child(tree_child(tree_child(tree_child(locations,2),0),2),2)->contents);
+ tmp = g_strdup_printf(_("<br>At %s since %s"), locval, + tree_child_contents(tree_child(tree_child(tree_child(locations, 2), 0), 2), 2)); purple_notify_user_info_add_pair_html(user_info, _("Location"), tmp);
- purple_notify_userinfo(gc, b ? bname : user,
- user_info, NULL, NULL);
+ purple_notify_userinfo(gc, name, user_info, NULL, NULL); purple_notify_user_info_destroy(user_info);
- purple_protocol_got_user_status(purple_connection_get_account(gc), b ? bname : user, "available", NULL);
- purple_protocol_got_user_status(purple_connection_get_account(gc), b ? bname : user, "offline", NULL);
+ purple_protocol_got_user_status(purple_connection_get_account(gc), name, has_locations ? "available" : "offline", NULL); else if (!g_ascii_strncasecmp(spewtype,"subscribed",10)) {