comparison mcabber/src/jabglue.c @ 1383:d9606bd03144

Small code cleanup
author Mikael Berthe <mikael@lilotux.net>
date Sun, 02 Dec 2007 13:38:44 +0100
parents 40095d413da9
children f762805b3f42
comparison
equal deleted inserted replaced
1382:1447c5296977 1383:d9606bd03144
94 } 94 }
95 95
96 char *compose_jid(const char *username, const char *servername, 96 char *compose_jid(const char *username, const char *servername,
97 const char *resource) 97 const char *resource)
98 { 98 {
99 char *fjid = g_new(char, 3 + 99 char *fjid;
100 strlen(username) + strlen(servername) + strlen(resource)); 100
101 strcpy(fjid, username);
102 if (!strchr(fjid, JID_DOMAIN_SEPARATOR)) { 101 if (!strchr(fjid, JID_DOMAIN_SEPARATOR)) {
103 strcat(fjid, JID_DOMAIN_SEPARATORSTR); 102 fjid = g_strdup_printf("%s%c%s%c%s", username,
104 strcat(fjid, servername); 103 JID_DOMAIN_SEPARATOR, servername,
105 } 104 JID_RESOURCE_SEPARATOR, resource);
106 strcat(fjid, JID_RESOURCE_SEPARATORSTR); 105 } else {
107 strcat(fjid, resource); 106 fjid = g_strdup_printf("%s%c%s", username,
107 JID_RESOURCE_SEPARATOR, resource);
108 }
108 return fjid; 109 return fjid;
109 } 110 }
110 111
111 inline unsigned char jb_getonline(void) 112 inline unsigned char jb_getonline(void)
112 { 113 {
2461 { 2462 {
2462 char *p, *r, *s; 2463 char *p, *r, *s;
2463 xmlnode x; 2464 xmlnode x;
2464 char *body = NULL; 2465 char *body = NULL;
2465 char *enc = NULL; 2466 char *enc = NULL;
2466 char *tmp = NULL; 2467 char *chatmsg = NULL;
2467 time_t timestamp = 0L; 2468 time_t timestamp = 0L;
2468 2469
2469 body = xmlnode_get_tag_data(xmldata, "body"); 2470 body = xmlnode_get_tag_data(xmldata, "body");
2470 2471
2471 p = xmlnode_get_tag_data(xmldata, "subject"); 2472 p = xmlnode_get_tag_data(xmldata, "subject");
2497 g_free(s); 2498 g_free(s);
2498 g_free(mbuf); 2499 g_free(mbuf);
2499 // The topic is displayed in the chat status line, so refresh now. 2500 // The topic is displayed in the chat status line, so refresh now.
2500 scr_UpdateChatStatus(TRUE); 2501 scr_UpdateChatStatus(TRUE);
2501 } else { // Chat message 2502 } else { // Chat message
2502 tmp = g_new(char, (body ? strlen(body) : 0) + strlen(p) + 4); 2503 if (body)
2503 *tmp = '['; 2504 chatmsg = g_strdup_printf("[%s]\n%s", p, body);
2504 strcpy(tmp+1, p); 2505 else
2505 strcat(tmp, "]\n"); 2506 chatmsg = g_strdup_printf("[%s]\n", p);
2506 if (body) strcat(tmp, body); 2507 body = chatmsg;
2507 body = tmp;
2508 } 2508 }
2509 } 2509 }
2510 2510
2511 // Not used yet... 2511 // Not used yet...
2512 x = xml_get_xmlns(xmldata, NS_ENCRYPTED); 2512 x = xml_get_xmlns(xmldata, NS_ENCRYPTED);
2535 if (from) { 2535 if (from) {
2536 x = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user"); 2536 x = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user");
2537 if (x && !strcmp(xmlnode_get_name(x), "x")) 2537 if (x && !strcmp(xmlnode_get_name(x), "x"))
2538 got_muc_message(from, x); 2538 got_muc_message(from, x);
2539 } 2539 }
2540 g_free(tmp); 2540 g_free(chatmsg);
2541 } 2541 }
2542 2542
2543 static void handle_state_events(char *from, xmlnode xmldata) 2543 static void handle_state_events(char *from, xmlnode xmldata)
2544 { 2544 {
2545 #if defined JEP0022 || defined JEP0085 2545 #if defined JEP0022 || defined JEP0085