GSList* hybrid_logs_read(HybridAccount *account, const gchar *id, const gchar *logname) { gchar *log_path = NULL; gchar *log_name = NULL; gchar *tmp; GSList *list = NULL; xmlnode *root = NULL, *node, *child; HybridLogEntry *entry; log_path = hybrid_logs_get_path(account, id); log_name = g_strdup_printf("%s/%s", log_path, logname); root = xmlnode_root_from_file(log_name); if (!root) { hybrid_debug_error("log", "log %s read error.\n", log_name); goto out; } node = xmlnode_child(root); while (node) { if (!xmlnode_has_prop(node, "type")) goto next; entry = g_new0(HybridLogEntry, 1); tmp = xmlnode_prop(node, "type"); if (g_strcmp0(tmp, "o")) { entry->is_send = 1; } else { entry->is_send = 0; } g_free(tmp); child = xmlnode_find(node, "t"); entry->time = xmlnode_content(child); child = xmlnode_find(node, "n"); entry->name = xmlnode_content(child); child = xmlnode_find(node, "c"); entry->content = xmlnode_content(child); list = g_slist_append(list, entry); next: node = xmlnode_next(node); } out: free(log_path); free(log_name); xmlnode_free(root); return list; }
gchar* get_province_name(const gchar *province) { xmlnode *root; xmlnode *node; gchar *name; gchar *value; g_return_val_if_fail(province != NULL, NULL); if (!(root = xmlnode_root_from_file(FETION_RES_DIR"province.xml"))) { return NULL; } if (!(node = xmlnode_child(root)) || g_strcmp0(node->name, "Province")) { hybrid_debug_error("fetion", "get full province name"); return NULL; } for (; node; node = xmlnode_next(node)) { if (!xmlnode_has_prop(node, "id")) { continue; } value = xmlnode_prop(node, "id"); if (g_strcmp0(value, province) == 0) { name = xmlnode_content(node); /* found, do cleanup. */ g_free(value); xmlnode_free(root); return name; } g_free(value); } xmlnode_free(root); return NULL; }
GSList* sip_parse_sync(fetion_account *account, const gchar *sipmsg) { gchar *pos; gchar *action; gchar *userid; gchar *status; xmlnode *root; xmlnode *node; fetion_buddy *buddy; GSList *list = NULL; if (!(pos = strstr(sipmsg, "\r\n\r\n"))) { goto sync_info_err; } pos += 4; if (!(root = xmlnode_root(pos, strlen(pos)))) { goto sync_info_err; } if (!(node = xmlnode_find(root, "buddies"))) { xmlnode_free(root); return list; } node = xmlnode_child(node); while (node) { if (!xmlnode_has_prop(node, "action")) { goto next; } action = xmlnode_prop(node, "action"); if (g_strcmp0(action, "update") == 0) { if (!xmlnode_has_prop(node, "user-id") || !xmlnode_has_prop(node, "relation-status")) { g_free(action); goto next; } userid = xmlnode_prop(node, "user-id"); status = xmlnode_prop(node, "relation-status"); if (!(buddy = fetion_buddy_find_by_userid(account, userid))) { g_free(action); g_free(userid); g_free(status); goto next; } buddy->status = atoi(status); list = g_slist_append(list, buddy); g_free(status); g_free(userid); } g_free(action); next: node = xmlnode_next(node); } return list; sync_info_err: hybrid_debug_error("fetion", "invalid sync info"); return list; }
void sip_parse_notify(const gchar *sipmsg, gint *notify_type, gint *event_type) { gchar *attr; gchar *pos; gchar *event; xmlnode *root = NULL; xmlnode *node; g_return_if_fail(sipmsg != NULL); if (!(attr = sip_header_get_attr(sipmsg, "N"))) { *notify_type = NOTIFICATION_TYPE_UNKNOWN; *event_type = NOTIFICATION_EVENT_UNKNOWN; return; } if (g_strcmp0(attr, "PresenceV4") == 0) { *notify_type = NOTIFICATION_TYPE_PRESENCE; } else if (g_strcmp0(attr, "Conversation") == 0) { *notify_type = NOTIFICATION_TYPE_CONVERSATION; } else if (g_strcmp0(attr, "contact") == 0) { *notify_type = NOTIFICATION_TYPE_CONTACT; } else if (g_strcmp0(attr, "registration") == 0) { *notify_type = NOTIFICATION_TYPE_REGISTRATION; } else if (g_strcmp0(attr, "SyncUserInfoV4") == 0) { *notify_type = NOTIFICATION_TYPE_SYNCUSERINFO; } else if (g_strcmp0(attr, "PGGroup") == 0) { *notify_type = NOTIFICATION_TYPE_PGGROUP; } else { *notify_type = NOTIFICATION_TYPE_UNKNOWN; } g_free(attr); if (!(pos = strstr(sipmsg, "\r\n\r\n"))) { goto notify_err; } pos += 4; if (!(root = xmlnode_root(pos, strlen(pos)))) { goto notify_err; } if (!(node = xmlnode_find(root, "event"))) { goto notify_err; } if (!(event = xmlnode_prop(node, "type"))) { goto notify_err; } if (g_strcmp0(event, "Support") == 0) { if (!(node = xmlnode_next(node))) { goto notify_err; } if (g_strcmp0(node->name, "event") != 0) { goto notify_err; } if (!(event = xmlnode_prop(node, "type"))) { goto notify_err; } } if (g_strcmp0(event, "PresenceChanged") == 0) { *event_type = NOTIFICATION_EVENT_PRESENCECHANGED; } else if (g_strcmp0(event, "UserEntered") == 0) { *event_type = NOTIFICATION_EVENT_USERENTER; } else if (g_strcmp0(event, "UserLeft") == 0) { *event_type = NOTIFICATION_EVENT_USERLEFT; } else if (g_strcmp0(event, "deregistered") == 0) { *event_type = NOTIFICATION_EVENT_DEREGISTRATION; } else if (g_strcmp0(event, "SyncUserInfo") == 0) { *event_type = NOTIFICATION_EVENT_SYNCUSERINFO; } else if (g_strcmp0(event, "AddBuddyApplication") == 0) { *event_type = NOTIFICATION_EVENT_ADDBUDDYAPPLICATION; } else if (g_strcmp0(event, "PGGetGroupInfo") == 0) { *event_type = NOTIFICATION_EVENT_PGGETGROUPINFO; } else { *event_type = NOTIFICATION_EVENT_UNKNOWN; } xmlnode_free(root); return; notify_err: xmlnode_free(root); *event_type = NOTIFICATION_EVENT_UNKNOWN; return; }
gchar* get_city_name(const gchar *province, const gchar *city) { xmlnode *root; xmlnode *node; gchar *name; gchar *value; if (!(root = xmlnode_root_from_file(FETION_RES_DIR"city.xml"))) { return NULL; } if (!(node = xmlnode_child(root)) || g_strcmp0(node->name, "Province")) { hybrid_debug_error("fetion", "get full city name"); return NULL; } for (; node; node = xmlnode_next(node)) { if (!xmlnode_has_prop(node, "id")) { continue; } value = xmlnode_prop(node, "id"); if (g_strcmp0(value, province) == 0) { /* found, do cleanup. */ g_free(value); goto province_found; } g_free(value); } xmlnode_free(root); return NULL; province_found: if (!(node = xmlnode_child(node)) || g_strcmp0(node->name, "City")) { hybrid_debug_error("fetion", "get full city name"); xmlnode_free(root); return NULL; } for (; node; node = xmlnode_next(node)) { if (!xmlnode_has_prop(node, "id")) { continue; } value = xmlnode_prop(node, "id"); if (g_strcmp0(value, city) == 0) { name= xmlnode_content(node); /* found, do cleanup. */ g_free(value); xmlnode_free(root); return name; } g_free(value); } xmlnode_free(root); return NULL; }