static void add_to_msg_list(const char *sender) { llnode *node; if ((node = malloc(sizeof(llnode))) == NULL) { purple_debug_fatal("pidgin-pp", "Malloc failed\n"); return; } if ((node->sender = malloc(MAX_NAME_LENGTH + 1)) == NULL) { free(node); purple_debug_fatal("pidgin-pp", "Malloc failed\n"); return; } strncpy(node->sender, sender, MAX_NAME_LENGTH); node->next = head; head = node; node->timer = g_timeout_add(MSG_LIST_TIMEOUT, (GSourceFunc) timer_expired, node); debug_msg_list(); }
//gets the text of whatever the user sets the status to. (not necessarily what status is on the server) //client_text and server_text are freed if it returns false static gboolean getStatusText(char** client_text, char** server_text, PurpleAccount *account, const char** sid) { PurpleStatus* status; PurpleSavedStatus* savedStatus; PurpleSavedStatusSub* substat; const char* statusMessage; status = purple_account_get_active_status(account); if (status == NULL) { purple_debug_fatal("MusicInfo", "Account with NULL status\n"); return FALSE; } *sid = purple_status_get_id(status); statusMessage = purple_status_get_attr_string(status, "message"); if(statusMessage != NULL) { *server_text = g_strdup(statusMessage); } else { *server_text = g_strdup("\0"); } savedStatus = purple_savedstatus_get_current(); if (savedStatus == NULL) { purple_debug_fatal("MusicInfo", "Account with NULL saved status\n"); g_free(*server_text); return FALSE; } statusMessage = NULL; if(purple_savedstatus_has_substatuses(savedStatus)) { substat = purple_savedstatus_get_substatus(savedStatus, account); if(substat != NULL) statusMessage = purple_savedstatus_substatus_get_message(substat); } if(statusMessage == NULL) { statusMessage = purple_savedstatus_get_message(savedStatus); } if(statusMessage == NULL) { g_free(*server_text); return FALSE; } *client_text = g_strdup(statusMessage); return TRUE; }
/* As we've covered before, libpurple calls this function, if present, when it * loads the plugin. Here we're using it to show off the capabilities of the * debug API and just blindly returning TRUE to tell libpurple it's safe to * continue loading. */ static gboolean plugin_load(PurplePlugin *plugin) { /* Define these for convenience--we're just using them to show the * similarities of the debug functions to the standard printf(). */ gint i = 256; gfloat f = 512.1024; const gchar *s = "example string"; /* Introductory message */ purple_debug_info(PLUGIN_ID, "Called plugin_load. Beginning debug demonstration\n"); /* Show off the debug API a bit */ purple_debug_misc(PLUGIN_ID, "MISC level debug message. i = %d, f = %f, s = %s\n", i, f, s); purple_debug_info(PLUGIN_ID, "INFO level debug message. i = %d, f = %f, s = %s\n", i, f, s); purple_debug_warning(PLUGIN_ID, "WARNING level debug message. i = %d, f = %f, s = %s\n", i, f, s); purple_debug_error(PLUGIN_ID, "ERROR level debug message. i = %d, f = %f, s = %s\n", i, f, s); purple_debug_fatal(PLUGIN_ID, "FATAL level debug message. i = %d, f = %f, s = %s\n", i, f, s); /* Now just return TRUE to tell libpurple to finish loading. */ return TRUE; }
void sipe_backend_debug(sipe_debug_level level, const gchar *format, ...) { va_list ap; va_start(ap, format); if (purple_debug_is_enabled()) { /* purple_debug doesn't have a vprintf-like API call :-( */ gchar *msg = g_strdup_vprintf(format, ap); switch (level) { case SIPE_DEBUG_LEVEL_INFO: purple_debug_info("sipe", "%s\n", msg); break; case SIPE_DEBUG_LEVEL_WARNING: purple_debug_warning("sipe", "%s\n", msg); break; case SIPE_DEBUG_LEVEL_ERROR: purple_debug_error("sipe", "%s\n", msg); break; case SIPE_DEBUG_LEVEL_FATAL: purple_debug_fatal("sipe", "%s\n", msg); break; } g_free(msg); } va_end(ap); }
void ggp_edisc_xfer_send_ticket_changed(PurpleConnection *gc, PurpleXfer *xfer, gboolean is_allowed) { ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer); if (!edisc_xfer) { purple_debug_fatal("gg", "ggp_edisc_event_ticket_changed: " "transfer %p already free'd\n", xfer); return; } if (!is_allowed) { purple_debug_info("gg", "ggp_edisc_event_ticket_changed: " "transfer %p rejected\n", xfer); purple_xfer_cancel_remote(xfer); ggp_edisc_xfer_free(xfer); return; } if (edisc_xfer->allowed) { purple_debug_misc("gg", "ggp_edisc_event_ticket_changed: " "transfer %p already allowed\n", xfer); return; } edisc_xfer->allowed = TRUE; purple_xfer_start(xfer, -1, NULL, 0); }
static void ggp_roster_send_update(PurpleConnection *gc) { GGPInfo *accdata = purple_connection_get_protocol_data(gc); ggp_roster_session_data *rdata = ggp_roster_get_rdata(gc); ggp_roster_content *content = rdata->content; GList *updates_it; gchar *str; int len; /* an update is running now */ if (rdata->sent_updates) return; /* no pending updates found */ if (!rdata->pending_updates) return; /* not initialized */ if (!content) return; purple_debug_info("gg", "ggp_roster_send_update: " "pending updates found\n"); rdata->sent_updates = rdata->pending_updates; rdata->pending_updates = NULL; updates_it = g_list_first(rdata->sent_updates); while (updates_it) { ggp_roster_change *change = updates_it->data; gboolean succ = FALSE; updates_it = g_list_next(updates_it); if (change->type == GGP_ROSTER_CHANGE_CONTACT_UPDATE) succ = ggp_roster_send_update_contact_update(gc, change); else if (change->type == GGP_ROSTER_CHANGE_CONTACT_REMOVE) succ = ggp_roster_send_update_contact_remove(gc, change); else if (change->type == GGP_ROSTER_CHANGE_GROUP_RENAME) succ = ggp_roster_send_update_group_rename(gc, change); else purple_debug_fatal("gg", "ggp_roster_send_update: " "not handled\n"); g_return_if_fail(succ); } #if GGP_ROSTER_DEBUG ggp_roster_dump(content); #endif str = purple_xmlnode_to_str(content->xml, &len); gg_userlist100_request(accdata->session, GG_USERLIST100_PUT, content->version, GG_USERLIST100_FORMAT_TYPE_GG100, str); g_free(str); }
void ggp_chat_got_event(PurpleConnection *gc, const struct gg_event *ev) { ggp_chat_session_data *sdata = ggp_chat_get_sdata(gc); ggp_chat_local_info *chat; uint32_t i; if (ev->type == GG_EVENT_CHAT_INFO) { const struct gg_event_chat_info *eci = &ev->event.chat_info; chat = ggp_chat_new(gc, eci->id); for (i = 0; i < eci->participants_count; i++) ggp_chat_joined(chat, eci->participants[i]); } else if (ev->type == GG_EVENT_CHAT_INFO_GOT_ALL) { GSList *it = sdata->pending_joins; sdata->got_all_chats_info = TRUE; while (it) { uint64_t *id_p = it->data; ggp_chat_join_id(gc, *id_p); it = g_slist_next(it); } g_slist_free_full(sdata->pending_joins, g_free); sdata->pending_joins = NULL; } else if (ev->type == GG_EVENT_CHAT_INFO_UPDATE) { const struct gg_event_chat_info_update *eciu = &ev->event.chat_info_update; chat = ggp_chat_get(gc, eciu->id); if (!chat) { purple_debug_error("gg", "ggp_chat_got_event: " "chat %" G_GUINT64_FORMAT " not found\n", eciu->id); return; } if (eciu->type == GG_CHAT_INFO_UPDATE_ENTERED) ggp_chat_joined(chat, eciu->participant); else if (eciu->type == GG_CHAT_INFO_UPDATE_EXITED) ggp_chat_left(chat, eciu->participant); else purple_debug_warning("gg", "ggp_chat_got_event: " "unknown update type - %d", eciu->type); } else if (ev->type == GG_EVENT_CHAT_CREATED) { const struct gg_event_chat_created *ecc = &ev->event.chat_created; uin_t me = ggp_str_to_uin(purple_account_get_username( purple_connection_get_account(gc))); chat = ggp_chat_new(gc, ecc->id); ggp_chat_joined(chat, me); ggp_chat_open_conv(chat); } else if (ev->type == GG_EVENT_CHAT_INVITE_ACK) { /* ignore */ } else { purple_debug_fatal("gg", "ggp_chat_got_event: unexpected event " "- %d\n", ev->type); } }
static gchar * yahoo_ft_url_gen(PurpleXfer *xfer, const gchar *host) { struct yahoo_xfer_data *xfer_data; PurpleAccount *account; g_return_val_if_fail(host != NULL, NULL); xfer_data = purple_xfer_get_protocol_data(xfer); account = purple_connection_get_account(xfer_data->gc); if (!xfer_data->is_relay) { purple_debug_fatal("yahoo", "Non-relay FT aren't tested yet\n"); return NULL; } return g_strdup_printf("http://%s/relay?token=%s&sender=%s&recver=%s", host, purple_url_encode(xfer_data->xfer_idstring_for_relay), purple_normalize(account, purple_account_get_username(account)), purple_xfer_get_remote_user(xfer)); }
void sipe_backend_debug_literal(sipe_debug_level level, const gchar *msg) { if (purple_debug_is_enabled()) { /* purple_debug doesn't have a vprintf-like API call :-( */ switch (level) { case SIPE_DEBUG_LEVEL_INFO: purple_debug_info("sipe", "%s\n", msg); break; case SIPE_DEBUG_LEVEL_WARNING: purple_debug_warning("sipe", "%s\n", msg); break; case SIPE_DEBUG_LEVEL_ERROR: purple_debug_error("sipe", "%s\n", msg); break; case SIPE_DEBUG_LEVEL_FATAL: purple_debug_fatal("sipe", "%s\n", msg); break; } } }
gchar * ggp_message_format_to_gg(PurpleConversation *conv, const gchar *text) { gchar *text_new, *tmp; GList *rt = NULL; /* reformatted text */ GMatchInfo *match; guint pos = 0; GList *pending_objects = NULL; GList *font_stack = NULL; static int html_sizes_pt[7] = { 7, 8, 9, 10, 12, 14, 16 }; ggp_font *font_new, *font_current, *font_base; gboolean font_changed = FALSE; gboolean in_any_tag = FALSE; /* TODO: verbose * purple_debug_info("gg", "ggp formatting text: [%s]\n", text); */ /* default font */ font_base = ggp_font_new(); font_current = ggp_font_new(); font_new = ggp_font_new(); /* GG11 doesn't use nbsp, it just print spaces */ text_new = purple_strreplace(text, " ", " "); /* add end-of-message tag */ if (strstr(text_new, "<eom>") != NULL) { tmp = text_new; text_new = purple_strreplace(text_new, "<eom>", ""); g_free(tmp); purple_debug_warning("gg", "ggp_message_format_to_gg: " "unexpected <eom> tag\n"); } tmp = text_new; text_new = g_strdup_printf("%s<eom></eom>", text_new); g_free(tmp); g_regex_match(global_data.re_html_tag, text_new, 0, &match); while (g_match_info_matches(match)) { int m_start, m_end, m_pos; gboolean tag_close; gchar *tag_str, *attribs_str; ggp_html_tag tag; gboolean text_before; /* reading tag and its contents */ g_match_info_fetch_pos(match, 0, &m_start, &m_end); g_assert(m_start >= 0 && m_end >= 0); text_before = ((guint)m_start > pos); g_match_info_fetch_pos(match, 1, &m_pos, NULL); tag_close = (m_pos >= 0); tag_str = g_match_info_fetch(match, 2); tag = ggp_html_parse_tag(tag_str); attribs_str = g_match_info_fetch(match, 3); g_match_info_next(match, NULL); if (tag == GGP_HTML_TAG_UNKNOWN) { purple_debug_warning("gg", "ggp_message_format_to_gg: " "uknown tag %s\n", tag_str); } /* closing *all* formatting-related tags (GG11 weirness) * and adding pending objects */ if ((text_before && (font_changed || pending_objects)) || (tag == GGP_HTML_TAG_EOM && tag_close)) { font_changed = FALSE; if (in_any_tag) { in_any_tag = FALSE; if (font_current->s && !GGP_GG11_FORCE_COMPAT) rt = g_list_prepend(rt, g_strdup("</s>")); if (font_current->u) rt = g_list_prepend(rt, g_strdup("</u>")); if (font_current->i) rt = g_list_prepend(rt, g_strdup("</i>")); if (font_current->b) rt = g_list_prepend(rt, g_strdup("</b>")); rt = g_list_prepend(rt, g_strdup("</span>")); } if (pending_objects) { rt = g_list_concat(pending_objects, rt); pending_objects = NULL; } } /* opening formatting-related tags again */ if (text_before && !in_any_tag) { gchar *style; GList *styles = NULL; gboolean has_size = (font_new->size > 0 && font_new->size <= 7 && font_new->size != 3); if (has_size) styles = g_list_append(styles, g_strdup_printf( "font-size:%dpt;", html_sizes_pt[font_new->size - 1])); if (font_new->face) styles = g_list_append(styles, g_strdup_printf( "font-family:%s;", font_new->face)); if (font_new->bgcolor >= 0 && !GGP_GG11_FORCE_COMPAT) styles = g_list_append(styles, g_strdup_printf( "background-color:#%06x;", font_new->bgcolor)); if (font_new->color >= 0) styles = g_list_append(styles, g_strdup_printf( "color:#%06x;", font_new->color)); if (styles) { gchar *combined = ggp_strjoin_list(" ", styles); g_list_free_full(styles, g_free); style = g_strdup_printf(" style=\"%s\"", combined); g_free(combined); } else style = g_strdup(""); rt = g_list_prepend(rt, g_strdup_printf("<span%s>", style)); g_free(style); if (font_new->b) rt = g_list_prepend(rt, g_strdup("<b>")); if (font_new->i) rt = g_list_prepend(rt, g_strdup("<i>")); if (font_new->u) rt = g_list_prepend(rt, g_strdup("<u>")); if (font_new->s && !GGP_GG11_FORCE_COMPAT) rt = g_list_prepend(rt, g_strdup("<s>")); ggp_font_free(font_current); font_current = font_new; font_new = ggp_font_clone(font_current); in_any_tag = TRUE; } if (text_before) { rt = g_list_prepend(rt, g_strndup(text_new + pos, m_start - pos)); } /* set formatting of a following text */ if (tag == GGP_HTML_TAG_B) { font_changed |= (font_new->b != !tag_close); font_new->b = !tag_close; } else if (tag == GGP_HTML_TAG_I) { font_changed |= (font_new->i != !tag_close); font_new->i = !tag_close; } else if (tag == GGP_HTML_TAG_U) { font_changed |= (font_new->u != !tag_close); font_new->u = !tag_close; } else if (tag == GGP_HTML_TAG_S) { font_changed |= (font_new->s != !tag_close); font_new->s = !tag_close; } else if (tag == GGP_HTML_TAG_IMG && !tag_close) { GHashTable *attribs = ggp_html_tag_attribs(attribs_str); gchar *val = NULL; uint64_t id; int stored_id = -1; ggp_image_prepare_result res = -1; if ((val = g_hash_table_lookup(attribs, "src")) != NULL && g_str_has_prefix(val, PURPLE_STORED_IMAGE_PROTOCOL)) { val += strlen(PURPLE_STORED_IMAGE_PROTOCOL); if (sscanf(val, "%u", &stored_id) != 1) stored_id = -1; } if (stored_id >= 0) res = ggp_image_prepare(conv, stored_id, &id); if (res == GGP_IMAGE_PREPARE_OK) { pending_objects = g_list_prepend( pending_objects, g_strdup_printf( "<img name=\"" GGP_IMAGE_ID_FORMAT "\">", id)); } else if (res == GGP_IMAGE_PREPARE_TOO_BIG) { purple_conversation_write(conv, "", _("Image is too large, please try " "smaller one."), PURPLE_MESSAGE_ERROR, time(NULL)); } else { purple_conversation_write(conv, "", _("Image cannot be sent."), PURPLE_MESSAGE_ERROR, time(NULL)); } g_hash_table_destroy(attribs); } else if (tag == GGP_HTML_TAG_FONT && !tag_close) { GHashTable *attribs = ggp_html_tag_attribs(attribs_str); gchar *val = NULL; font_stack = g_list_prepend(font_stack, ggp_font_clone(font_new)); if ((val = g_hash_table_lookup(attribs, "size")) != NULL && val[0] >= '1' && val[0] <= '7' && val[1] == '\0') { int size = val[0] - '0'; font_changed |= (font_new->size != size); font_new->size = size; } if ((val = g_hash_table_lookup(attribs, "face")) != NULL) { font_changed |= (g_strcmp0(font_new->face, val) != 0); g_free(font_new->face); font_new->face = g_strdup(val); } if ((val = g_hash_table_lookup(attribs, "color")) != NULL && val[0] == '#' && strlen(val) == 7) { int color = ggp_html_decode_color(val); font_changed |= (font_new->color != color); font_new->color = color; } g_hash_table_destroy(attribs); } else if ((tag == GGP_HTML_TAG_SPAN || tag == GGP_HTML_TAG_DIV) && !tag_close) { GHashTable *attribs, *styles = NULL; gchar *style = NULL; gchar *val = NULL; attribs = ggp_html_tag_attribs(attribs_str); font_stack = g_list_prepend(font_stack, ggp_font_clone(font_new)); if (tag == GGP_HTML_TAG_DIV) pending_objects = g_list_prepend( pending_objects, g_strdup("<br>")); style = g_hash_table_lookup(attribs, "style"); if (style) styles = ggp_html_css_attribs(style); if ((val = g_hash_table_lookup(styles, "background-color")) != NULL) { int color = ggp_html_decode_color(val); font_changed |= (font_new->bgcolor != color); font_new->bgcolor = color; } if ((val = g_hash_table_lookup(styles, "color")) != NULL) { int color = ggp_html_decode_color(val); font_changed |= (font_new->color != color); font_new->color = color; } if (styles) g_hash_table_destroy(styles); g_hash_table_destroy(attribs); } else if ((tag == GGP_HTML_TAG_FONT || tag == GGP_HTML_TAG_SPAN || tag == GGP_HTML_TAG_DIV) && tag_close) { font_changed = TRUE; ggp_font_free(font_new); if (font_stack) { font_new = (ggp_font*)font_stack->data; font_stack = g_list_delete_link( font_stack, font_stack); } else font_new = ggp_font_clone(font_base); } else if (tag == GGP_HTML_TAG_BR) { pending_objects = g_list_prepend(pending_objects, g_strdup("<br>")); } else if (tag == GGP_HTML_TAG_HR) { pending_objects = g_list_prepend(pending_objects, g_strdup("<br><span>---</span><br>")); } else if (tag == GGP_HTML_TAG_A || tag == GGP_HTML_TAG_EOM) { /* do nothing */ } else if (tag == GGP_HTML_TAG_UNKNOWN) { purple_debug_warning("gg", "ggp_message_format_to_gg: " "uknown tag %s\n", tag_str); } else { purple_debug_error("gg", "ggp_message_format_to_gg: " "not handled tag %s\n", tag_str); } pos = m_end; g_free(tag_str); g_free(attribs_str); } g_match_info_free(match); if (pos < strlen(text_new) || in_any_tag) { purple_debug_fatal("gg", "ggp_message_format_to_gg: " "end of message not reached\n"); } /* releasing fonts recources */ ggp_font_free(font_new); ggp_font_free(font_current); ggp_font_free(font_base); g_list_free_full(font_stack, ggp_font_free); /* combining reformatted text info one string */ rt = g_list_reverse(rt); g_free(text_new); text_new = ggp_strjoin_list("", rt); g_list_free_full(rt, g_free); /* TODO: verbose * purple_debug_info("gg", "reformatted text: [%s]\n", text_new); */ return text_new; }