comparison src/protocols/jabber/message.c @ 7145:0e4894b3e2a6

[gaim-migrate @ 7712] all sorts of fun jabber stuff including: 1. stop calling gaim_strdup_withhtml() with NULL values 2. real support for headline-type messages 3. fix a stupid presence bug when authorizing people 4. fix login default stuff so people can log in committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 04 Oct 2003 21:19:29 +0000
parents eba5f7be0bc8
children 071dee25c48e
comparison
equal deleted inserted replaced
7144:4d5b0c1f2e7a 7145:0e4894b3e2a6
44 g_free(jm->body); 44 g_free(jm->body);
45 if(jm->xhtml) 45 if(jm->xhtml)
46 g_free(jm->xhtml); 46 g_free(jm->xhtml);
47 if(jm->password) 47 if(jm->password)
48 g_free(jm->password); 48 g_free(jm->password);
49 if(jm->etc)
50 g_list_free(jm->etc);
49 51
50 g_free(jm); 52 g_free(jm);
51 } 53 }
52 54
53 void handle_chat(JabberMessage *jm) 55 static void handle_chat(JabberMessage *jm)
54 { 56 {
55 JabberID *jid = jabber_id_new(jm->from); 57 JabberID *jid = jabber_id_new(jm->from);
56 char *from; 58 char *from;
57 59
58 JabberBuddy *jb; 60 JabberBuddy *jb;
82 84
83 g_free(from); 85 g_free(from);
84 jabber_id_free(jid); 86 jabber_id_free(jid);
85 } 87 }
86 88
87 void handle_groupchat(JabberMessage *jm) 89 static void handle_headline(JabberMessage *jm)
90 {
91 char *title;
92 GString *body = g_string_new("");
93 GList *etc;
94
95 title = g_strdup_printf(_("Message from %s"), jm->from);
96
97 if(jm->xhtml)
98 g_string_append(body, jm->xhtml);
99 else if(jm->body)
100 g_string_append(body, jm->body);
101
102 for(etc = jm->etc; etc; etc = etc->next) {
103 xmlnode *x = etc->data;
104 const char *xmlns = xmlnode_get_attrib(x, "xmlns");
105 if(xmlns && !strcmp(xmlns, "jabber:x:oob")) {
106 xmlnode *url, *desc;
107 char *urltxt, *desctxt;
108
109 url = xmlnode_get_child(x, "url");
110 desc = xmlnode_get_child(x, "desc");
111
112 if(!url || !desc)
113 continue;
114
115 urltxt = xmlnode_get_data(url);
116 desctxt = xmlnode_get_data(desc);
117
118 /* I'm all about ugly hacks */
119 if(body->len && !strcmp(body->str, jm->body))
120 g_string_printf(body, "<a href='%s'>%s</a>",
121 urltxt, desctxt);
122 else
123 g_string_append_printf(body, "<br/><a href='%s'>%s</a>",
124 urltxt, desctxt);
125
126 g_free(urltxt);
127 g_free(desctxt);
128 }
129 }
130
131 gaim_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title,
132 NULL, body->str, NULL, NULL);
133
134 g_free(title);
135 g_string_free(body, TRUE);
136 }
137
138 static void handle_groupchat(JabberMessage *jm)
88 { 139 {
89 JabberID *jid = jabber_id_new(jm->from); 140 JabberID *jid = jabber_id_new(jm->from);
90 JabberChat *chat = jabber_chat_find(jm->js, jid->node, jid->domain); 141 JabberChat *chat = jabber_chat_find(jm->js, jid->node, jid->domain);
91 142
92 if(!chat) 143 if(!chat)
98 serv_got_chat_in(jm->js->gc, chat->id, jabber_get_resource(jm->from), 149 serv_got_chat_in(jm->js->gc, chat->id, jabber_get_resource(jm->from),
99 0, jm->xhtml ? jm->xhtml : jm->body, jm->sent); 150 0, jm->xhtml ? jm->xhtml : jm->body, jm->sent);
100 jabber_id_free(jid); 151 jabber_id_free(jid);
101 } 152 }
102 153
103 void handle_groupchat_invite(JabberMessage *jm) 154 static void handle_groupchat_invite(JabberMessage *jm)
104 { 155 {
105 GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal, 156 GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal,
106 g_free, g_free); 157 g_free, g_free);
107 JabberID *jid = jabber_id_new(jm->to); 158 JabberID *jid = jabber_id_new(jm->to);
108 159
113 164
114 jabber_id_free(jid); 165 jabber_id_free(jid);
115 serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components); 166 serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components);
116 } 167 }
117 168
118 void handle_error(JabberMessage *jm) 169 static void handle_error(JabberMessage *jm)
119 { 170 {
120 char *buf; 171 char *buf;
121 172
122 if(!jm->body) 173 if(!jm->body)
123 return; 174 return;
229 if((password = xmlnode_get_child(invite, "password"))) 280 if((password = xmlnode_get_child(invite, "password")))
230 jm->password = xmlnode_get_data(password); 281 jm->password = xmlnode_get_data(password);
231 282
232 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE; 283 jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE;
233 } 284 }
285 } else {
286 jm->etc = g_list_append(jm->etc, child);
234 } 287 }
235 } 288 }
236 } 289 }
237 290
238 switch(jm->type) { 291 switch(jm->type) {
239 case JABBER_MESSAGE_NORMAL: 292 case JABBER_MESSAGE_NORMAL:
240 case JABBER_MESSAGE_CHAT: 293 case JABBER_MESSAGE_CHAT:
294 handle_chat(jm);
295 break;
241 case JABBER_MESSAGE_HEADLINE: 296 case JABBER_MESSAGE_HEADLINE:
242 handle_chat(jm); 297 handle_headline(jm);
243 break; 298 break;
244 case JABBER_MESSAGE_GROUPCHAT: 299 case JABBER_MESSAGE_GROUPCHAT:
245 handle_groupchat(jm); 300 handle_groupchat(jm);
246 break; 301 break;
247 case JABBER_MESSAGE_GROUPCHAT_INVITE: 302 case JABBER_MESSAGE_GROUPCHAT_INVITE: