END_TEST START_TEST(test_util_str_to_time) { fail_unless(377182200 == purple_str_to_time("19811214T12:50:00", TRUE, NULL, NULL, NULL)); fail_unless(1175919261 == purple_str_to_time("20070407T04:14:21", TRUE, NULL, NULL, NULL)); }
static void skypeweb_got_authrequests(SkypeWebAccount *sa, JsonNode *node, gpointer user_data) { JsonArray *requests; guint index, length; time_t latest_timestamp = 0; requests = json_node_get_array(node); length = json_array_get_length(requests); for(index = 0; index < length; index++) { JsonObject *request = json_array_get_object_element(requests, index); const gchar *event_time_iso = json_object_get_string_member(request, "event_time_iso"); const gchar *sender = json_object_get_string_member(request, "sender"); const gchar *greeting = json_object_get_string_member(request, "greeting"); time_t event_timestamp = purple_str_to_time(event_time_iso, TRUE, NULL, NULL, NULL); latest_timestamp = MAX(latest_timestamp, event_timestamp); if (sa->last_authrequest && event_timestamp <= sa->last_authrequest) continue; purple_account_request_authorization( sa->account, sender, NULL, NULL, greeting, FALSE, skypeweb_auth_accept_cb, skypeweb_auth_reject_cb, purple_buddy_new(sa->account, sender, NULL)); } sa->last_authrequest = latest_timestamp; }
static gboolean nexus_parse_token(MsnNexus *nexus, int id, xmlnode *node) { char *token_str, *expiry_str; const char *id_str; char **elems, **cur, **tokens; xmlnode *token = xmlnode_get_child(node, "RequestedSecurityToken/BinarySecurityToken"); xmlnode *secret = xmlnode_get_child(node, "RequestedProofToken/BinarySecret"); xmlnode *expires = xmlnode_get_child(node, "LifeTime/Expires"); if (!token) return FALSE; /* Use the ID that the server sent us */ if (id == -1) { id_str = xmlnode_get_attrib(token, "Id"); if (id_str == NULL) return FALSE; id = atol(id_str + 7) - 1; /* 'Compact#' or 'PPToken#' */ if (id >= nexus->token_len) return FALSE; /* Where did this come from? */ } token_str = xmlnode_get_data(token); if (token_str == NULL) return FALSE; g_hash_table_remove_all(nexus->tokens[id].token); elems = g_strsplit(token_str, "&", 0); for (cur = elems; *cur != NULL; cur++) { tokens = g_strsplit(*cur, "=", 2); g_hash_table_insert(nexus->tokens[id].token, tokens[0], tokens[1]); /* Don't free each of the tokens, only the array. */ g_free(tokens); } g_strfreev(elems); g_free(token_str); if (secret) nexus->tokens[id].secret = xmlnode_get_data(secret); else nexus->tokens[id].secret = NULL; /* Yay for MS using ISO-8601 */ expiry_str = xmlnode_get_data(expires); nexus->tokens[id].expiry = purple_str_to_time(expiry_str, FALSE, NULL, NULL, NULL); g_free(expiry_str); purple_debug_info("msn", "Updated ticket for domain '%s', expires at %" G_GINT64_FORMAT ".\n", ticket_domains[id][SSO_VALID_TICKET_DOMAIN], (gint64)nexus->tokens[id].expiry); return TRUE; }
static void fb_got_notifications_cb(FacebookAccount *fba, gchar *url_text, gsize len, gpointer userdata) { gchar *salvaged; time_t last_fetch_time; time_t time_of_message; time_t newest_message = 0; xmlnode *channel;//VOXOX - CJC - 2009.07.06 xmlnode *rss_root;//VOXOX - CJC - 2009.07.06 xmlnode *item;//VOXOX - CJC - 2009.07.06 xmlnode *link;//VOXOX - CJC - 2009.07.06 xmlnode *title;//VOXOX - CJC - 2009.07.06 gchar *tmp; gchar month_string[4], weekday[4]; guint year, month, day, hour, minute, second; long timezone; gchar *subject, *url; month_string[3] = weekday[3] = '\0'; year = month = day = hour = minute = second = 0; if (!url_text || !len) return; last_fetch_time = purple_account_get_int(fba->account, "facebook_notifications_last_fetch", 0); /* purple_debug_info("facebook", "last fetch time: %zu\n", last_fetch_time); */ salvaged = purple_utf8_salvage(url_text); rss_root = xmlnode_from_str(salvaged, -1); g_free(salvaged); if (rss_root == NULL) { purple_debug_error("facebook", "Could not load RSS file\n"); return; } channel = xmlnode_get_child(rss_root, "channel"); if (channel == NULL) { purple_debug_warning("facebook", "Invalid RSS feed\n"); xmlnode_free(rss_root); return; } item = xmlnode_get_child(channel, "item"); if (item == NULL) { purple_debug_info("facebook", "No new notifications\n"); } for (; item != NULL; item = xmlnode_get_next_twin(item)) { xmlnode *pubDate = xmlnode_get_child(item, "pubDate"); if (!pubDate) continue; tmp = xmlnode_get_data_unescaped(pubDate); /* rss times are in Thu, 19 Jun 2008 15:51:25 -1100 format */ sscanf(tmp, "%3s, %2u %3s %4u %2u:%2u:%2u %5ld", (char*)&weekday, &day, (char*)&month_string, &year, &hour, &minute, &second, &timezone); if (g_str_equal(month_string, "Jan")) month = 0; else if (g_str_equal(month_string, "Feb")) month = 1; else if (g_str_equal(month_string, "Mar")) month = 2; else if (g_str_equal(month_string, "Apr")) month = 3; else if (g_str_equal(month_string, "May")) month = 4; else if (g_str_equal(month_string, "Jun")) month = 5; else if (g_str_equal(month_string, "Jul")) month = 6; else if (g_str_equal(month_string, "Aug")) month = 7; else if (g_str_equal(month_string, "Sep")) month = 8; else if (g_str_equal(month_string, "Oct")) month = 9; else if (g_str_equal(month_string, "Nov")) month = 10; else if (g_str_equal(month_string, "Dec")) month = 11; g_free(tmp); /* try using pidgin's functions */ tmp = g_strdup_printf("%04u%02u%02uT%02u%02u%02u%05ld", year, month, day, hour, minute, second, timezone); time_of_message = purple_str_to_time(tmp, FALSE, NULL, NULL, NULL); g_free(tmp); if (time_of_message <= 0) { /* there's no cross-platform, portable way of converting string to time which doesn't need a new version of glib, so just cheat */ time_of_message = second + 60*minute + 3600*hour + 86400*day + 2592000*month + 31536000*(year-1970); } if (time_of_message > newest_message) { /* we'll keep the newest message to save */ newest_message = time_of_message; } if (time_of_message <= last_fetch_time) { /* fortunatly, rss messages are ordered from newest to oldest */ /* so if this message is older than the last one, ignore rest */ break; } link = xmlnode_get_child(item, "link"); if (link) { url = xmlnode_get_data_unescaped(link); } else { url = g_strdup(""); } title = xmlnode_get_child(item, "title"); if (title) { subject = xmlnode_get_data_unescaped(title); } else { subject = g_strdup(""); } purple_notify_email(fba->pc, subject, NULL, fba->account->username, url, NULL, NULL); g_free(subject); g_free(url); } xmlnode_free(rss_root); if (newest_message > last_fetch_time) { /* update the last fetched time if we had newer messages */ purple_account_set_int(fba->account, "facebook_notifications_last_fetch", newest_message); } }
JabberChat *jabber_join_chat(JabberStream *js, const char *room, const char *server, const char *handle, const char *password, GHashTable *data) { JabberChat *chat; PurpleConnection *gc; PurpleAccount *account; PurpleStatus *status; xmlnode *presence, *x; JabberBuddyState state; char *msg; int priority; char *jid; char *history_maxchars; char *history_maxstanzas; char *history_seconds; char *history_since; struct tm history_since_datetime; const char *history_since_string = NULL; chat = jabber_chat_new(js, room, server, handle, password, data); if (chat == NULL) return NULL; gc = js->gc; account = purple_connection_get_account(gc); status = purple_account_get_active_status(account); purple_status_to_jabber(status, &state, &msg, &priority); presence = jabber_presence_create_js(js, state, msg, priority); g_free(msg); jid = g_strdup_printf("%s@%s/%s", room, server, handle); xmlnode_set_attrib(presence, "to", jid); g_free(jid); history_maxchars = g_hash_table_lookup(data, "history_maxchars"); history_maxstanzas = g_hash_table_lookup(data, "history_maxstanzas"); history_seconds = g_hash_table_lookup(data, "history_seconds"); history_since = g_hash_table_lookup(data, "history_since"); if (history_since) { if (purple_str_to_time(history_since, TRUE, &history_since_datetime, NULL, NULL) != 0) { history_since_string = purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", &history_since_datetime); } else { history_since_string = NULL; purple_debug_error("jabber", "Invalid date format for history_since" " while requesting history: %s", history_since); } } x = xmlnode_new_child(presence, "x"); xmlnode_set_namespace(x, "http://jabber.org/protocol/muc"); if (password && *password) { xmlnode *p = xmlnode_new_child(x, "password"); xmlnode_insert_data(p, password, -1); } if ((history_maxchars && *history_maxchars) || (history_maxstanzas && *history_maxstanzas) || (history_seconds && *history_seconds) || (history_since_string && *history_since_string)) { xmlnode *history = xmlnode_new_child(x, "history"); if (history_maxchars && *history_maxchars) { xmlnode_set_attrib(history, "maxchars", history_maxchars); } if (history_maxstanzas && *history_maxstanzas) { xmlnode_set_attrib(history, "maxstanzas", history_maxstanzas); } if (history_seconds && *history_seconds) { xmlnode_set_attrib(history, "seconds", history_seconds); } if (history_since_string && *history_since_string) { xmlnode_set_attrib(history, "since", history_since_string); } } jabber_send(js, presence); xmlnode_free(presence); return chat; }