# HG changeset patch # User Mikael Berthe # Date 1196599124 -3600 # Node ID d9606bd0314449e381d527e55e0cc2c96999f885 # Parent 1447c52969771db9a905a9ba9e4367dd6e1334a0 Small code cleanup diff -r 1447c5296977 -r d9606bd03144 mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Sun Dec 02 13:04:57 2007 +0100 +++ b/mcabber/src/jabglue.c Sun Dec 02 13:38:44 2007 +0100 @@ -96,15 +96,16 @@ char *compose_jid(const char *username, const char *servername, const char *resource) { - char *fjid = g_new(char, 3 + - strlen(username) + strlen(servername) + strlen(resource)); - strcpy(fjid, username); + char *fjid; + if (!strchr(fjid, JID_DOMAIN_SEPARATOR)) { - strcat(fjid, JID_DOMAIN_SEPARATORSTR); - strcat(fjid, servername); + fjid = g_strdup_printf("%s%c%s%c%s", username, + JID_DOMAIN_SEPARATOR, servername, + JID_RESOURCE_SEPARATOR, resource); + } else { + fjid = g_strdup_printf("%s%c%s", username, + JID_RESOURCE_SEPARATOR, resource); } - strcat(fjid, JID_RESOURCE_SEPARATORSTR); - strcat(fjid, resource); return fjid; } @@ -2463,7 +2464,7 @@ xmlnode x; char *body = NULL; char *enc = NULL; - char *tmp = NULL; + char *chatmsg = NULL; time_t timestamp = 0L; body = xmlnode_get_tag_data(xmldata, "body"); @@ -2499,12 +2500,11 @@ // The topic is displayed in the chat status line, so refresh now. scr_UpdateChatStatus(TRUE); } else { // Chat message - tmp = g_new(char, (body ? strlen(body) : 0) + strlen(p) + 4); - *tmp = '['; - strcpy(tmp+1, p); - strcat(tmp, "]\n"); - if (body) strcat(tmp, body); - body = tmp; + if (body) + chatmsg = g_strdup_printf("[%s]\n%s", p, body); + else + chatmsg = g_strdup_printf("[%s]\n", p); + body = chatmsg; } } @@ -2537,7 +2537,7 @@ if (x && !strcmp(xmlnode_get_name(x), "x")) got_muc_message(from, x); } - g_free(tmp); + g_free(chatmsg); } static void handle_state_events(char *from, xmlnode xmldata) diff -r 1447c5296977 -r d9606bd03144 mcabber/src/settings.c --- a/mcabber/src/settings.c Sun Dec 02 13:04:57 2007 +0100 +++ b/mcabber/src/settings.c Sun Dec 02 13:38:44 2007 +0100 @@ -97,6 +97,7 @@ if (!filename) { // Use default config file locations char *home; + GString *sfilename; if (!mainfile) { scr_LogPrint(LPRINT_LOGNORM, "No file name provided"); @@ -110,28 +111,28 @@ err = -1; goto cfg_read_file_return; } - filename = g_new(char, strlen(home)+24); - sprintf(filename, "%s/.mcabber/mcabberrc", home); - if ((fp = fopen(filename, "r")) == NULL) { + sfilename = g_string_new(""); + g_string_printf(sfilename, "%s/.mcabber/mcabberrc", home); + if ((fp = fopen(sfilename->str, "r")) == NULL) { // 2nd try... - sprintf(filename, "%s/.mcabberrc", home); - if ((fp = fopen(filename, "r")) == NULL) { + g_string_printf(sfilename, "%s/.mcabberrc", home); + if ((fp = fopen(sfilename->str, "r")) == NULL) { fprintf(stderr, "Cannot open config file!\n"); - g_free(filename); + g_string_free(sfilename, TRUE); err = -1; goto cfg_read_file_return; } } // Check configuration file permissions // As it could contain sensitive data, we make it user-readable only. - checkset_perm(filename, TRUE); - scr_LogPrint(LPRINT_LOGNORM, "Reading %s", filename); + checkset_perm(sfilename->str, TRUE); + scr_LogPrint(LPRINT_LOGNORM, "Reading %s", sfilename->str); // Check mcabber dir. Here we just warn, we don't change the modes. - sprintf(filename, "%s/.mcabber/", home); - checkset_perm(filename, FALSE); - g_free(filename); - filename = NULL; + g_string_printf(sfilename, "%s/.mcabber/", home); + checkset_perm(sfilename->str, FALSE); + g_string_free(sfilename, TRUE); } else { + // filename was specified if ((fp = fopen(filename, "r")) == NULL) { const char *msg = "Cannot open configuration file"; if (mainfile)