comparison libpurple/protocols/jabber/google.c @ 25606:2260e5b0ca91

*** Plucked rev f9080d0b (khc@pidgin.im): correctly NULL terminate all the arrays since that's what gtknotify assumes, also fixed a memory leak in gmail notification *** Plucked rev a543de79 (khc@pidgin.im): Qulogic pointed out that glib has G_N_ELEMENTS already *** Plucked rev 19b202a7 (khc@pidgin.im): used the wrong count variable here
author Paul Aurich <paul@darkrain42.org>
date Sun, 10 May 2009 23:25:26 +0000
parents e1bddd9c5c88
children 01f1929d0936
comparison
equal deleted inserted replaced
25605:9c0337d4b878 25606:2260e5b0ca91
37 xmlnode *message, *sender_node, *subject_node; 37 xmlnode *message, *sender_node, *subject_node;
38 const char *from, *to, *url, *tid; 38 const char *from, *to, *url, *tid;
39 char *subject; 39 char *subject;
40 const char *in_str; 40 const char *in_str;
41 char *to_name; 41 char *to_name;
42 char *default_tos[1];
43 42
44 int i, count = 1, returned_count; 43 int i, count = 1, returned_count;
45 44
46 const char **tos, **froms, **urls; 45 const char **tos, **froms, **urls;
47 char **subjects; 46 char **subjects;
57 if (in_str && *in_str) 56 if (in_str && *in_str)
58 count = atoi(in_str); 57 count = atoi(in_str);
59 58
60 /* If Gmail doesn't tell us who the mail is to, let's use our JID */ 59 /* If Gmail doesn't tell us who the mail is to, let's use our JID */
61 to = xmlnode_get_attrib(packet, "to"); 60 to = xmlnode_get_attrib(packet, "to");
62 default_tos[0] = jabber_get_bare_jid(to);
63 61
64 message = xmlnode_get_child(child, "mail-thread-info"); 62 message = xmlnode_get_child(child, "mail-thread-info");
65 63
66 if (count == 0 || !message) { 64 if (count == 0 || !message) {
67 if (count > 0) 65 if (count > 0) {
68 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, (const char**) default_tos, NULL, NULL, NULL); 66 char *bare_jid = jabber_get_bare_jid(to);
69 g_free(default_tos[0]); 67 const char *default_tos[2] = { bare_jid };
68
69 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, default_tos, NULL, NULL, NULL);
70 g_free(bare_jid);
71 } else {
72 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, NULL, NULL, NULL, NULL);
73 }
74
70 return; 75 return;
71 } 76 }
72 77
73 /* Loop once to see how many messages were returned so we can allocate arrays 78 /* Loop once to see how many messages were returned so we can allocate arrays
74 * accordingly */ 79 * accordingly */
75 for (returned_count = 0; message; returned_count++, message=xmlnode_get_next_twin(message)); 80 for (returned_count = 0; message; returned_count++, message=xmlnode_get_next_twin(message));
76 81
77 froms = g_new0(const char* , returned_count); 82 froms = g_new0(const char* , returned_count + 1);
78 tos = g_new0(const char* , returned_count); 83 tos = g_new0(const char* , returned_count + 1);
79 subjects = g_new0(char* , returned_count); 84 subjects = g_new0(char* , returned_count + 1);
80 urls = g_new0(const char* , returned_count); 85 urls = g_new0(const char* , returned_count + 1);
81 86
82 to = xmlnode_get_attrib(packet, "to"); 87 to = xmlnode_get_attrib(packet, "to");
83 to_name = jabber_get_bare_jid(to); 88 to_name = jabber_get_bare_jid(to);
84 url = xmlnode_get_attrib(child, "url"); 89 url = xmlnode_get_attrib(child, "url");
85 if (!url || !*url) 90 if (!url || !*url)
121 } 126 }
122 127
123 if (i>0) 128 if (i>0)
124 purple_notify_emails(js->gc, count, count == i, (const char**) subjects, froms, tos, 129 purple_notify_emails(js->gc, count, count == i, (const char**) subjects, froms, tos,
125 urls, NULL, NULL); 130 urls, NULL, NULL);
126 else
127 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, (const char**) default_tos, NULL, NULL, NULL);
128
129 131
130 g_free(to_name); 132 g_free(to_name);
131 g_free(tos); 133 g_free(tos);
132 g_free(default_tos[0]);
133 g_free(froms); 134 g_free(froms);
134 for (; i > 0; i--) 135 for (i = 0; i < returned_count; i++)
135 g_free(subjects[i - 1]); 136 g_free(subjects[i]);
136 g_free(subjects); 137 g_free(subjects);
137 g_free(urls); 138 g_free(urls);
138 139
139 in_str = xmlnode_get_attrib(child, "result-time"); 140 in_str = xmlnode_get_attrib(child, "result-time");
140 if (in_str && *in_str) { 141 if (in_str && *in_str) {