# HG changeset patch # User Christian Hammond # Date 1064992553 0 # Node ID 6faeeecab0dc5e21a22c69112f4aeedb92ce45b6 # Parent 9220c7490cd1c2df666b05f3dde8f2950bee6571 [gaim-migrate @ 7673] Put the rest of util.[ch] into namespaces and sectioned off the functions. committer: Tailor Script diff -r 9220c7490cd1 -r 6faeeecab0dc src/blist.c --- a/src/blist.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/blist.c Wed Oct 01 07:15:53 2003 +0000 @@ -1476,7 +1476,7 @@ break; if (*c == 'g') { char *utf8 = NULL; - utf8 = gaim_try_conv_to_utf8(c + 2); + utf8 = gaim_utf8_try_convert(c + 2); if (utf8 == NULL) { g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); } else { @@ -1497,7 +1497,7 @@ g_strlcpy(nm, c + 2, sizeof(nm)); if (a) { - utf8 = gaim_try_conv_to_utf8(a); + utf8 = gaim_utf8_try_convert(a); if (utf8 == NULL) { gaim_debug(GAIM_DEBUG_ERROR, "toc blist", "Failed to convert alias for " diff -r 9220c7490cd1 -r 6faeeecab0dc src/browser.c --- a/src/browser.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/browser.c Wed Oct 01 07:15:53 2003 +0000 @@ -584,7 +584,7 @@ } } - if (!program_is_valid(command)) { + if (!gaim_program_is_valid(command)) { gchar *tmp = g_strdup_printf(_("The browser \"%s\" is invalid."), command); gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp); diff -r 9220c7490cd1 -r 6faeeecab0dc src/dialogs.c --- a/src/dialogs.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/dialogs.c Wed Oct 01 07:15:53 2003 +0000 @@ -878,7 +878,7 @@ if ((user_info = gaim_account_get_user_info(account)) != NULL) { buf = g_malloc(strlen(user_info) + 1); - strncpy_nohtml(buf, user_info, strlen(user_info) + 1); + gaim_strncpy_nohtml(buf, user_info, strlen(user_info) + 1); buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(b->text)); gtk_text_buffer_set_text(buffer, buf, -1); g_free(buf); diff -r 9220c7490cd1 -r 6faeeecab0dc src/gtkconn.c --- a/src/gtkconn.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/gtkconn.c Wed Oct 01 07:15:53 2003 +0000 @@ -273,7 +273,7 @@ primary = g_strdup_printf(_("%s has been disconnected"), gaim_account_get_username(gaim_connection_get_account(gc))); - secondary = g_strdup_printf("%s\n%s", full_date(), + secondary = g_strdup_printf("%s\n%s", gaim_date_full(), text ? text : _("Reason Unknown.")); gaim_notify_error(NULL, _("Connection Error"), primary, secondary); g_free(primary); diff -r 9220c7490cd1 -r 6faeeecab0dc src/gtkconv.c --- a/src/gtkconv.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/gtkconv.c Wed Oct 01 07:15:53 2003 +0000 @@ -3923,10 +3923,10 @@ fprintf(fd, _("

" "---- New Conversation @ %s ----


\n"), - full_date()); + gaim_date_full()); else fprintf(fd, _("---- New Conversation @ %s ----\n"), - full_date()); + gaim_date_full()); fclose(fd); } diff -r 9220c7490cd1 -r 6faeeecab0dc src/gtkdebug.c --- a/src/gtkdebug.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/gtkdebug.c Wed Oct 01 07:15:53 2003 +0000 @@ -305,7 +305,7 @@ g_free(esc_s); - utf8_s = gaim_try_conv_to_utf8(s); + utf8_s = gaim_utf8_try_convert(s); g_free(s); s = utf8_s; diff -r 9220c7490cd1 -r 6faeeecab0dc src/gtkprefs.c --- a/src/gtkprefs.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/gtkprefs.c Wed Oct 01 07:15:53 2003 +0000 @@ -1234,7 +1234,7 @@ browsers = g_list_prepend(browsers, _("Manual")); for (i = 0; i < num_possible_browsers; i++) { - if (program_is_valid(possible_browsers[i].command)) { + if (gaim_program_is_valid(possible_browsers[i].command)) { browsers = g_list_prepend(browsers, possible_browsers[i].command); browsers = g_list_prepend(browsers, _(possible_browsers[i].name)); diff -r 9220c7490cd1 -r 6faeeecab0dc src/log.c --- a/src/log.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/log.c Wed Oct 01 07:15:53 2003 +0000 @@ -268,36 +268,36 @@ switch (what) { case log_signon: g_snprintf(text, sizeof(text), _("+++ %s (%s) signed on @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_signoff: g_snprintf(text, sizeof(text), _("+++ %s (%s) signed off @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_away: g_snprintf(text, sizeof(text), _("+++ %s (%s) changed away state @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_back: g_snprintf(text, sizeof(text), _("+++ %s (%s) came back @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_idle: g_snprintf(text, sizeof(text), _("+++ %s (%s) became idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_unidle: g_snprintf(text, sizeof(text), _("+++ %s (%s) returned from idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_quit: - g_snprintf(text, sizeof(text), _("+++ Program exit @ %s"), full_date()); + g_snprintf(text, sizeof(text), _("+++ Program exit @ %s"), gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; } @@ -305,33 +305,33 @@ switch (what) { case log_signon: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) signed on @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_signoff: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) signed off @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_away: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) went away @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_back: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) came back @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_idle: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) became idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_unidle: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s (%s) returned from idle @ %s"), gaim_account_get_username(account), - gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, full_date()); + gc->prpl->info->name, gaim_get_buddy_alias(who), who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; default: @@ -343,33 +343,33 @@ switch (what) { case log_signon: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s signed on @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_signoff: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s signed off @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_away: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s went away @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_back: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s came back @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_idle: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s became idle @ %s"), - gaim_account_get_username(account), gc->prpl->info->name, who->name, full_date()); + gaim_account_get_username(account), gc->prpl->info->name, who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; case log_unidle: g_snprintf(text, sizeof(text), _("%s (%s) reported that %s returned from idle @ %s"), gaim_account_get_username(account), - gc->prpl->info->name, who->name, full_date()); + gc->prpl->info->name, who->name, gaim_date_full()); g_snprintf(html, sizeof(html), "%s", text); break; default: diff -r 9220c7490cd1 -r 6faeeecab0dc src/protocols/gg/gg.c --- a/src/protocols/gg/gg.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/protocols/gg/gg.c Wed Oct 01 07:15:53 2003 +0000 @@ -1,6 +1,6 @@ /* * gaim - Gadu-Gadu Protocol Plugin - * $Id: gg.c 7627 2003-09-30 07:47:38Z chipx86 $ + * $Id: gg.c 7673 2003-10-01 07:15:53Z chipx86 $ * * Copyright (C) 2001 Arkadiusz Mi¶kiewicz * @@ -310,7 +310,7 @@ if (!allowed_uin(gc, user)) break; imsg = charset_convert(e->event.msg.message, "CP1250", "UTF-8"); - strip_linefeed(imsg); + gaim_str_strip_linefeed(imsg); /* e->event.msg.time - we don't know what this time is for */ serv_got_im(gc, user, imsg, 0, time(NULL)); g_free(imsg); diff -r 9220c7490cd1 -r 6faeeecab0dc src/protocols/irc/msgs.c --- a/src/protocols/irc/msgs.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/protocols/irc/msgs.c Wed Oct 01 07:15:53 2003 +0000 @@ -203,7 +203,7 @@ g_free(irc->whois.channels); } if (irc->whois.idle) { - gchar *timex = sec_to_text(irc->whois.idle); + gchar *timex = gaim_str_seconds_to_string(irc->whois.idle); g_string_append_printf(info, _("Idle for: %s
"), timex); g_free(timex); g_string_append_printf(info, "%s: %s", _("Online since"), ctime(&irc->whois.signon)); diff -r 9220c7490cd1 -r 6faeeecab0dc src/protocols/jabber/buddy.c --- a/src/protocols/jabber/buddy.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/protocols/jabber/buddy.c Wed Oct 01 07:15:53 2003 +0000 @@ -535,7 +535,7 @@ if(resource_name) { jbr = jabber_buddy_find_resource(jb, resource_name); if(jbr) { - char *purdy = strdup_withhtml(jbr->status); + char *purdy = gaim_strdup_withhtml(jbr->status); g_string_append_printf(info_text, "%s: %s%s%s
\n", _("Status"), jabber_get_state_string(jbr->state), purdy ? ": " : "", @@ -549,7 +549,7 @@ for(resources = jb->resources; resources; resources = resources->next) { char *purdy; jbr = resources->data; - purdy = strdup_withhtml(jbr->status); + purdy = gaim_strdup_withhtml(jbr->status); g_string_append_printf(info_text, "%s: %s
\n", _("Resource"), jbr->name); g_string_append_printf(info_text, "%s: %s%s%s

\n", diff -r 9220c7490cd1 -r 6faeeecab0dc src/protocols/msn/msn.c --- a/src/protocols/msn/msn.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/protocols/msn/msn.c Wed Oct 01 07:15:53 2003 +0000 @@ -1003,7 +1003,7 @@ if (swboard == NULL) return -EINVAL; - send = add_cr(message); + send = gaim_str_add_cr(message); msg = msn_message_new(); msn_message_set_attr(msg, "X-MMS-IM-Format", "FN=Arial; EF=; CO=0; PF=0"); diff -r 9220c7490cd1 -r 6faeeecab0dc src/protocols/oscar/oscar.c --- a/src/protocols/oscar/oscar.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/protocols/oscar/oscar.c Wed Oct 01 07:15:53 2003 +0000 @@ -2259,7 +2259,7 @@ } } - /* strip_linefeed(tmp); */ + /* gaim_str_strip_linefeed(tmp); */ serv_got_im(gc, userinfo->sn, tmp, flags, time(NULL)); g_free(tmp); @@ -2559,7 +2559,7 @@ for (numtoks=0; msg1[numtoks]; numtoks++); msg2 = (gchar **)g_malloc((numtoks+1)*sizeof(gchar *)); for (i=0; msg1[i]; i++) { - strip_linefeed(msg1[i]); + gaim_str_strip_linefeed(msg1[i]); msg2[i] = g_convert(msg1[i], strlen(msg1[i]), "UTF-8", "ISO-8859-1", NULL, NULL, &err); if (err) { gaim_debug(GAIM_DEBUG_ERROR, "oscar", @@ -3153,7 +3153,7 @@ asctime(localtime((time_t *)&userinfo->membersince))); if (userinfo->present & AIM_USERINFO_PRESENT_IDLE) { - gchar *itime = sec_to_text(userinfo->idletime*60); + gchar *itime = gaim_str_seconds_to_string(userinfo->idletime*60); g_string_append_printf(text, _("Idle: %s"), itime); g_free(itime); } else @@ -3175,7 +3175,7 @@ } } - final = away_subs(text->str, gaim_connection_get_display_name(gc)); + final = gaim_str_sub_away_formatters(text->str, gaim_connection_get_display_name(gc)); g_string_free(text, TRUE); gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, final, NULL, NULL); g_free(final); @@ -3853,7 +3853,7 @@ args.flags = msg->flags; args.msglen = msg->msglen; args.msg = msg->msg; - t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0); + t = gaim_time_build(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0); incomingim_chan4(sess, fr->conn, NULL, &args, t); return 1; @@ -3884,27 +3884,27 @@ g_snprintf(who, sizeof(who), "%u", info->uin); buf = g_strdup_printf("%s: %s", _("UIN"), who); - if (info->nick && info->nick[0] && (utf8 = gaim_try_conv_to_utf8(info->nick))) { + if (info->nick && info->nick[0] && (utf8 = gaim_utf8_try_convert(info->nick))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Nick"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->first && info->first[0] && (utf8 = gaim_try_conv_to_utf8(info->first))) { + if (info->first && info->first[0] && (utf8 = gaim_utf8_try_convert(info->first))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("First Name"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->last && info->last[0] && (utf8 = gaim_try_conv_to_utf8(info->last))) { + if (info->last && info->last[0] && (utf8 = gaim_utf8_try_convert(info->last))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Last Name"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->email && info->email[0] && (utf8 = gaim_try_conv_to_utf8(info->email))) { + if (info->email && info->email[0] && (utf8 = gaim_utf8_try_convert(info->email))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Email Address"), ": ", utf8, "", NULL); g_free(tmp); g_free(utf8); } if (info->numaddresses && info->email2) { int i; for (i = 0; i < info->numaddresses; i++) { - if (info->email2[i] && info->email2[i][0] && (utf8 = gaim_try_conv_to_utf8(info->email2[i]))) { + if (info->email2[i] && info->email2[i][0] && (utf8 = gaim_utf8_try_convert(info->email2[i]))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Email Address"), ": ", utf8, "", NULL); g_free(tmp); g_free(utf8); } } } - if (info->mobile && info->mobile[0] && (utf8 = gaim_try_conv_to_utf8(info->mobile))) { + if (info->mobile && info->mobile[0] && (utf8 = gaim_utf8_try_convert(info->mobile))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Mobile Phone"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } if (info->gender) { @@ -3924,57 +3924,57 @@ snprintf(age, sizeof(age), "%hhd", info->age); tmp = buf; buf = g_strconcat(tmp, "\n
", _("Age"), ": ", age, NULL); g_free(tmp); } - if (info->personalwebpage && info->personalwebpage[0] && (utf8 = gaim_try_conv_to_utf8(info->personalwebpage))) { + if (info->personalwebpage && info->personalwebpage[0] && (utf8 = gaim_utf8_try_convert(info->personalwebpage))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Personal Web Page"), ": ", utf8, "", NULL); g_free(tmp); g_free(utf8); } - if (info->info && info->info[0] && (utf8 = gaim_try_conv_to_utf8(info->info))) { + if (info->info && info->info[0] && (utf8 = gaim_utf8_try_convert(info->info))) { tmp = buf; buf = g_strconcat(tmp, "
", _("Additional Information"), ":
", utf8, NULL); g_free(tmp); g_free(utf8); } tmp = buf; buf = g_strconcat(tmp, "
\n", NULL); g_free(tmp); if ((info->homeaddr && (info->homeaddr[0])) || (info->homecity && info->homecity[0]) || (info->homestate && info->homestate[0]) || (info->homezip && info->homezip[0])) { tmp = buf; buf = g_strconcat(tmp, "", _("Home Address"), ":", NULL); g_free(tmp); - if (info->homeaddr && info->homeaddr[0] && (utf8 = gaim_try_conv_to_utf8(info->homeaddr))) { + if (info->homeaddr && info->homeaddr[0] && (utf8 = gaim_utf8_try_convert(info->homeaddr))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Address"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->homecity && info->homecity[0] && (utf8 = gaim_try_conv_to_utf8(info->homecity))) { + if (info->homecity && info->homecity[0] && (utf8 = gaim_utf8_try_convert(info->homecity))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("City"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->homestate && info->homestate[0] && (utf8 = gaim_try_conv_to_utf8(info->homestate))) { + if (info->homestate && info->homestate[0] && (utf8 = gaim_utf8_try_convert(info->homestate))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("State"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->homezip && info->homezip[0] && (utf8 = gaim_try_conv_to_utf8(info->homezip))) { + if (info->homezip && info->homezip[0] && (utf8 = gaim_utf8_try_convert(info->homezip))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Zip Code"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } tmp = buf; buf = g_strconcat(tmp, "\n
\n", NULL); g_free(tmp); } if ((info->workaddr && info->workaddr[0]) || (info->workcity && info->workcity[0]) || (info->workstate && info->workstate[0]) || (info->workzip && info->workzip[0])) { tmp = buf; buf = g_strconcat(tmp, "", _("Work Address"), ":", NULL); g_free(tmp); - if (info->workaddr && info->workaddr[0] && (utf8 = gaim_try_conv_to_utf8(info->workaddr))) { + if (info->workaddr && info->workaddr[0] && (utf8 = gaim_utf8_try_convert(info->workaddr))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Address"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->workcity && info->workcity[0] && (utf8 = gaim_try_conv_to_utf8(info->workcity))) { + if (info->workcity && info->workcity[0] && (utf8 = gaim_utf8_try_convert(info->workcity))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("City"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->workstate && info->workstate[0] && (utf8 = gaim_try_conv_to_utf8(info->workstate))) { + if (info->workstate && info->workstate[0] && (utf8 = gaim_utf8_try_convert(info->workstate))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("State"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->workzip && info->workzip[0] && (utf8 = gaim_try_conv_to_utf8(info->workzip))) { + if (info->workzip && info->workzip[0] && (utf8 = gaim_utf8_try_convert(info->workzip))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Zip Code"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } tmp = buf; buf = g_strconcat(tmp, "\n
\n", NULL); g_free(tmp); } if ((info->workcompany && info->workcompany[0]) || (info->workdivision && info->workdivision[0]) || (info->workposition && info->workposition[0]) || (info->workwebpage && info->workwebpage[0])) { tmp = buf; buf = g_strconcat(tmp, "", _("Work Information"), ":", NULL); g_free(tmp); - if (info->workcompany && info->workcompany[0] && (utf8 = gaim_try_conv_to_utf8(info->workcompany))) { + if (info->workcompany && info->workcompany[0] && (utf8 = gaim_utf8_try_convert(info->workcompany))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Company"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->workdivision && info->workdivision[0] && (utf8 = gaim_try_conv_to_utf8(info->workdivision))) { + if (info->workdivision && info->workdivision[0] && (utf8 = gaim_utf8_try_convert(info->workdivision))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Division"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->workposition && info->workposition[0] && (utf8 = gaim_try_conv_to_utf8(info->workposition))) { + if (info->workposition && info->workposition[0] && (utf8 = gaim_utf8_try_convert(info->workposition))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Position"), ": ", utf8, NULL); g_free(tmp); g_free(utf8); } - if (info->workwebpage && info->workwebpage[0] && (utf8 = gaim_try_conv_to_utf8(info->workwebpage))) { + if (info->workwebpage && info->workwebpage[0] && (utf8 = gaim_utf8_try_convert(info->workwebpage))) { tmp = buf; buf = g_strconcat(tmp, "\n
", _("Web Page"), ": ", utf8, "", NULL); g_free(tmp); g_free(utf8); } tmp = buf; buf = g_strconcat(tmp, "\n
\n", NULL); g_free(tmp); @@ -4001,7 +4001,7 @@ info = va_arg(ap, struct aim_icq_info *); va_end(ap); - if (info->uin && info->nick && info->nick[0] && (utf8 = gaim_try_conv_to_utf8(info->nick))) { + if (info->uin && info->nick && info->nick[0] && (utf8 = gaim_utf8_try_convert(info->nick))) { g_snprintf(who, sizeof(who), "%u", info->uin); serv_got_alias(gc, who, utf8); if ((b = gaim_find_buddy(gc->account, who))) { @@ -4285,9 +4285,9 @@ /* For ICQ send newlines as CR/LF, for AIM send newlines as
*/ if (isdigit(name[0])) - tmpmsg = add_cr(message); + tmpmsg = gaim_str_add_cr(message); else - tmpmsg = strdup_withhtml(message); + tmpmsg = gaim_strdup_withhtml(message); len = strlen(tmpmsg); args.flags |= oscar_encoding_check(tmpmsg); @@ -4405,7 +4405,7 @@ return; } - text_html = strdup_withhtml(text); + text_html = gaim_strdup_withhtml(text); flags = oscar_encoding_check(text_html); if (flags & AIM_IMFLAGS_UNICODE) { msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); @@ -4463,7 +4463,7 @@ return; } - text_html = strdup_withhtml(text); + text_html = gaim_strdup_withhtml(text); flags = oscar_encoding_check(text_html); if (flags & AIM_IMFLAGS_UNICODE) { msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); @@ -4787,9 +4787,9 @@ case 0x0000: { /* Buddy */ if (curitem->name) { char *gname = aim_ssi_itemlist_findparentname(sess->ssi.local, curitem->name); - char *gname_utf8 = gaim_try_conv_to_utf8(gname); + char *gname_utf8 = gaim_utf8_try_convert(gname); char *alias = aim_ssi_getalias(sess->ssi.local, gname, curitem->name); - char *alias_utf8 = gaim_try_conv_to_utf8(alias); + char *alias_utf8 = gaim_utf8_try_convert(alias); GaimBuddy *buddy = gaim_find_buddy(gc->account, curitem->name); /* Should gname be freed here? -- elb */ /* Not with the current code, but that might be cleaner -- med */ @@ -5377,7 +5377,7 @@ } if (userinfo != NULL) { - char *tstr = sec_to_text(time(NULL) - userinfo->onlinesince + + char *tstr = gaim_str_seconds_to_string(time(NULL) - userinfo->onlinesince + (gc->login_time_official ? gc->login_time_official - gc->login_time : 0)); tmp = ret; ret = g_strconcat(tmp, _("Logged In: "), tstr, "\n", NULL); @@ -5419,7 +5419,7 @@ tmp1 = gaim_strreplace(away_utf8, "
", "\n"); tmp2 = gaim_markup_strip_html(tmp1); g_free(tmp1); - tmp1 = away_subs(tmp2, gaim_connection_get_display_name(gc)); + tmp1 = gaim_str_sub_away_formatters(tmp2, gaim_connection_get_display_name(gc)); g_free(tmp2); tmp = ret; ret = g_strconcat(tmp, _("Away Message: "), tmp1, "\n", NULL); diff -r 9220c7490cd1 -r 6faeeecab0dc src/protocols/yahoo/yahoo.c --- a/src/protocols/yahoo/yahoo.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/protocols/yahoo/yahoo.c Wed Oct 01 07:15:53 2003 +0000 @@ -675,7 +675,7 @@ msg = pair->value; - strip_linefeed(msg); + gaim_str_strip_linefeed(msg); m = yahoo_codes_to_html(msg); serv_got_im(gc, from, m, 0, tm); g_free(m); @@ -999,7 +999,7 @@ const unsigned char *magic_ptr; unsigned int magic[64]; - unsigned int magic_work; + unsigned int magic_work = 0; unsigned int value = 0; int x; diff -r 9220c7490cd1 -r 6faeeecab0dc src/server.c --- a/src/server.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/server.c Wed Oct 01 07:15:53 2003 +0000 @@ -143,7 +143,7 @@ account = gaim_connection_get_account(gc); if (gaim_account_get_user_info(account) != NULL) { - /* buf = strdup_withhtml(gc->user->user_info); */ + /* buf = gaim_strdup_withhtml(gc->user->user_info); */ serv_set_info(gc, gaim_account_get_user_info(account)); /* g_free(buf); */ } @@ -1018,7 +1018,7 @@ /* apply default fonts and colors */ tmpmsg = stylize(gc->away, MSG_LEN); - serv_send_im(gc, name, away_subs(tmpmsg, alias), GAIM_IM_AUTO_RESP); + serv_send_im(gc, name, gaim_str_sub_away_formatters(tmpmsg, alias), GAIM_IM_AUTO_RESP); if (!cnv && awayqueue && gaim_prefs_get_bool("/gaim/gtk/away/queue_messages")) { @@ -1026,13 +1026,13 @@ qm = g_new0(struct queued_message, 1); g_snprintf(qm->name, sizeof(qm->name), "%s", name); - qm->message = g_strdup(away_subs(tmpmsg, alias)); + qm->message = g_strdup(gaim_str_sub_away_formatters(tmpmsg, alias)); qm->account = gc->account; qm->tm = mtime; qm->flags = GAIM_MESSAGE_SEND | GAIM_MESSAGE_AUTO_RESP; message_queue = g_slist_append(message_queue, qm); } else if (cnv != NULL) - gaim_im_write(GAIM_IM(cnv), NULL, away_subs(tmpmsg, alias), + gaim_im_write(GAIM_IM(cnv), NULL, gaim_str_sub_away_formatters(tmpmsg, alias), GAIM_MESSAGE_SEND | GAIM_MESSAGE_AUTO_RESP, mtime); g_free(tmpmsg); @@ -1378,9 +1378,9 @@ if (!gaim_prefs_get_bool("/gaim/gtk/logging/strip_html")) fprintf(fd, _("

---- New Conversation @ %s ----


\n"), - full_date()); + gaim_date_full()); else - fprintf(fd, _("---- New Conversation @ %s ----\n"), full_date()); + fprintf(fd, _("---- New Conversation @ %s ----\n"), gaim_date_full()); fclose(fd); } diff -r 9220c7490cd1 -r 6faeeecab0dc src/util.c --- a/src/util.c Wed Oct 01 06:17:28 2003 +0000 +++ b/src/util.c Wed Oct 01 07:15:53 2003 +0000 @@ -60,122 +60,121 @@ static char home_dir[MAXPATHLEN]; -char *full_date() -{ - char *date; - time_t tme; - time(&tme); - date = ctime(&tme); - date[strlen(date) - 1] = '\0'; - return date; -} - -G_GNUC_CONST static gint badchar(char c) +/************************************************************************** + * Base16 Functions + **************************************************************************/ +unsigned char * +gaim_base16_encode(const unsigned char *data, int length) { - switch (c) { - case ' ': - case ',': - case '(': - case ')': - case '\0': - case '\n': - case '<': - case '>': - case '"': - case '\'': - return 1; - default: - return 0; - } + int i; + unsigned char *ascii = NULL; + + g_return_val_if_fail(data != NULL, NULL); + g_return_val_if_fail(length > 0, NULL); + + ascii = g_malloc(length * 2 + 1); + + for (i = 0; i < length; i++) + snprintf(&ascii[i * 2], 3, "%02hhx", data[i]); + + return ascii; } - -gchar *sec_to_text(guint sec) +int +gaim_base16_decode(const char *ascii, unsigned char **raw) { - guint daze, hrs, min; - char *ret = NULL; + int len, i, accumulator = 0; + unsigned char *data; + + g_return_val_if_fail(ascii != NULL, 0); - daze = sec / (60 * 60 * 24); - hrs = (sec % (60 * 60 * 24)) / (60 * 60); - min = (sec % (60 * 60)) / 60; - sec = min % 60; + len = strlen(ascii); + + g_return_val_if_fail(strlen(ascii) > 0, 0); + g_return_val_if_fail(len % 2 > 0, 0); + + data = g_malloc(len / 2); - if (daze) { - if (hrs || min) { - if (hrs) { - if (min) { - ret = g_strdup_printf( - "%d %s, %d %s, %d %s.", - daze, ngettext("day","days",daze), - hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min)); - } else { - ret = g_strdup_printf( - "%d %s, %d %s.", - daze, ngettext("day","days",daze), hrs, ngettext("hour","hours",hrs)); - } - } else { - ret = g_strdup_printf( - "%d %s, %d %s.", - daze, ngettext("day","days",daze), min, ngettext("minute","minutes",min)); + for (i = 0; i < len; i++) + { + if ((i % 2) == 0) + accumulator = 0; + else + accumulator <<= 4; + + if (isdigit(ascii[i])) + accumulator |= ascii[i] - 48; + else + { + switch(ascii[i]) + { + case 'a': case 'A': accumulator |= 10; break; + case 'b': case 'B': accumulator |= 11; break; + case 'c': case 'C': accumulator |= 12; break; + case 'd': case 'D': accumulator |= 13; break; + case 'e': case 'E': accumulator |= 14; break; + case 'f': case 'F': accumulator |= 15; break; } - } else - ret = g_strdup_printf("%d %s.", daze, ngettext("day","days",daze)); - } else { - if (hrs) { - if (min) { - ret = g_strdup_printf( - "%d %s, %d %s.", - hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min)); - } else { - ret = g_strdup_printf("%d %s.", hrs, ngettext("hour","hours",hrs)); - } - } else { - ret = g_strdup_printf("%d %s.", min, ngettext("minute","minutes",min)); } + + if (i % 2) + data[(i - 1) / 2] = accumulator; } - return ret; + *raw = data; + + return (len / 2); } - +/************************************************************************** + * Base64 Functions + **************************************************************************/ static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/"; -char *gaim_base64_encode(const unsigned char *in, size_t inlen) +unsigned char * +gaim_base64_encode(const unsigned char *in, size_t inlen) { char *out, *rv; + g_return_val_if_fail(in != NULL, NULL); + g_return_val_if_fail(inlen > 0, NULL); + rv = out = g_malloc((4 * (inlen + 1)) / 3 + 1); - for (; inlen >= 3; inlen -= 3) - { - *out++ = alphabet[in[0] >> 2]; - *out++ = alphabet[((in[0] << 4) & 0x30) | (in[1] >> 4)]; - *out++ = alphabet[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; - *out++ = alphabet[in[2] & 0x3f]; - in += 3; - } - if (inlen > 0) - { - unsigned char fragment; + for (; inlen >= 3; inlen -= 3) + { + *out++ = alphabet[in[0] >> 2]; + *out++ = alphabet[((in[0] << 4) & 0x30) | (in[1] >> 4)]; + *out++ = alphabet[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; + *out++ = alphabet[in[2] & 0x3f]; + in += 3; + } + + if (inlen > 0) + { + unsigned char fragment; - *out++ = alphabet[in[0] >> 2]; - fragment = (in[0] << 4) & 0x30; - if (inlen > 1) - fragment |= in[1] >> 4; - *out++ = alphabet[fragment]; - *out++ = (inlen < 2) ? '=' : alphabet[(in[1] << 2) & 0x3c]; - *out++ = '='; - } - *out = '\0'; + *out++ = alphabet[in[0] >> 2]; + fragment = (in[0] << 4) & 0x30; + + if (inlen > 1) + fragment |= in[1] >> 4; + + *out++ = alphabet[fragment]; + *out++ = (inlen < 2) ? '=' : alphabet[(in[1] << 2) & 0x3c]; + *out++ = '='; + } + + *out = '\0'; return rv; } - -void gaim_base64_decode(const char *text, char **data, int *size) +void +gaim_base64_decode(const char *text, char **data, int *size) { char *out = NULL; char tmp = 0; @@ -183,8 +182,8 @@ gint32 tmp2 = 0; int len = 0, n = 0; - if (!text || !data) - return; + g_return_if_fail(text != NULL); + g_return_if_fail(data != NULL); c = text; @@ -236,343 +235,42 @@ out[len] = 0; *data = out; + if (size) *size = len; } -/* - * Converts raw data to a pretty, null-terminated base16 string. - */ -unsigned char *gaim_base16_encode(const unsigned char *data, int length) -{ - int i; - unsigned char *ascii = NULL; - if (!data || !length) - return NULL; - - ascii = g_malloc(length*2 + 1); - - for (i=0; idata); - tmp = g_slist_remove(tmp, tmp->data); - } - ret = NULL; - } - - while (TRUE) { - if (lastgood >= len) - return ret; - - if (len - lastgood < limit) { - ret = g_slist_append(ret, g_strdup(&message[lastgood])); - return ret; - } + char *date; + time_t tme; - curgood = curpos = 0; - intag = FALSE; - while (curpos <= limit) { - if (isspace(message[curpos + lastgood]) && !intag) - curgood = curpos; - if (message[curpos + lastgood] == '<') - intag = TRUE; - if (message[curpos + lastgood] == '>') - intag = FALSE; - curpos++; - } + time(&tme); + date = ctime(&tme); + date[strlen(date) - 1] = '\0'; - if (curgood) { - ret = g_slist_append(ret, g_strndup(&message[lastgood], curgood)); - if (isspace(message[curgood + lastgood])) - lastgood += curgood + 1; - else - lastgood += curgood; - } else { - /* whoops, guess we have to fudge it here */ - ret = g_slist_append(ret, g_strndup(&message[lastgood], limit)); - lastgood += limit; - } - } -} - -const gchar *gaim_home_dir() -{ -#ifndef _WIN32 - if(g_get_home_dir()) - return g_get_home_dir(); - else - return NULL; -#else - return wgaim_data_dir(); -#endif + return date; } -/* returns a string of the form ~/.gaim, where ~ is replaced by the user's home - * dir. Note that there is no trailing slash after .gaim. */ -gchar *gaim_user_dir() -{ - const gchar *hd = gaim_home_dir(); - if(hd) { - strcpy( (char*)&home_dir, hd ); - strcat( (char*)&home_dir, G_DIR_SEPARATOR_S ".gaim" ); - return (gchar*)&home_dir; - } - else { - return NULL; - } -} - -/* - * rcg10312000 This could be more robust, but it works for my current - * goal: to remove those annoying
tags. :) - * dtf12162000 made the loop more readable. i am a neat freak. ;) */ -void strncpy_nohtml(gchar *dest, const gchar *src, size_t destsize) -{ - gchar *ptr; - g_snprintf(dest, destsize, "%s", src); - - while ((ptr = strstr(dest, "
")) != NULL) { - /* replace
with a newline. */ - *ptr = '\n'; - memmove(ptr + 1, ptr + 4, strlen(ptr + 4) + 1); - } -} - -void strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize) -{ - gchar *end = dest + destsize; - - while (dest < end) { - if (*src == '\n' && dest < end - 5) { - strcpy(dest, "
"); - src++; - dest += 4; - } else if(*src == '\r') { - src++; - } else { - *dest++ = *src; - if (*src == '\0') - return; - else - src++; - } - } -} - - -/* - * Like strncpy_withhtml (above), but malloc()'s the necessary space - * - * The caller is responsible for freeing the space pointed to by the - * return value. - */ - -gchar *strdup_withhtml(const gchar *src) -{ - gchar *sp, *dest; - gulong destsize; - - if(!src) - return NULL; - - /* - * All we need do is multiply the number of newlines by 3 (the - * additional length of "
" over "\n"), account for the - * terminator, malloc the space and call strncpy_withhtml. - */ - for(destsize = 0, sp = (gchar *)src; (sp = strchr(sp, '\n')) != NULL; ++sp, ++destsize) - ; - destsize *= 3; - destsize += strlen(src) + 1; - dest = g_malloc(destsize); - strncpy_withhtml(dest, src, destsize); - - return(dest); -} - -void strip_linefeed(gchar *text) -{ - int i, j; - gchar *text2 = g_malloc(strlen(text) + 1); - - for (i = 0, j = 0; text[i]; i++) - if (text[i] != '\r') - text2[j++] = text[i]; - text2[j] = '\0'; - - strcpy(text, text2); - g_free(text2); -} - -char *add_cr(const char *text) -{ - char *ret = NULL; - int count = 0, i, j; - - if (text[0] == '\n') - count++; - for (i = 1; i < strlen(text); i++) - if (text[i] == '\n' && text[i - 1] != '\r') - count++; - - if (count == 0) - return g_strdup(text); - - ret = g_malloc0(strlen(text) + count + 1); - - i = 0; j = 0; - if (text[i] == '\n') - ret[j++] = '\r'; - ret[j++] = text[i++]; - for (; i < strlen(text); i++) { - if (text[i] == '\n' && text[i - 1] != '\r') - ret[j++] = '\r'; - ret[j++] = text[i]; - } - - gaim_debug(GAIM_DEBUG_INFO, "add_cr", "got: %s, leaving with %s\n", - text, ret); - - return ret; -} - -time_t get_time(int year, int month, int day, int hour, int min, int sec) +time_t +gaim_time_build(int year, int month, int day, int hour, int min, int sec) { struct tm tm; @@ -582,227 +280,14 @@ tm.tm_hour = hour; tm.tm_min = min; tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60; + return mktime(&tm); } -/* - * Like mkstemp() but returns a file pointer, uses a pre-set template, - * uses the semantics of tempnam() for the directory to use and allocates - * the space for the filepath. - * - * Caller is responsible for closing the file and removing it when done, - * as well as freeing the space pointed-to by "path" with g_free(). - * - * Returns NULL on failure and cleans up after itself if so. - */ -static const char *gaim_mkstemp_templ = {"gaimXXXXXX"}; -FILE *gaim_mkstemp(gchar **fpath) -{ - const gchar *tmpdir; -#ifndef _WIN32 - int fd; -#endif - FILE *fp = NULL; - - if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) { - if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) { -#ifdef _WIN32 - char* result = _mktemp( *fpath ); - if( result == NULL ) - gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", - "Problem creating the template\n"); - else - { - if( (fp = fopen( result, "w+" )) == NULL ) { - gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", - "Couldn't fopen() %s\n", result); - } - } -#else - if((fd = mkstemp(*fpath)) == -1) { - gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", - "Couldn't make \"%s\", error: %d\n", - *fpath, errno); - } else { - if((fp = fdopen(fd, "r+")) == NULL) { - close(fd); - gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", - "Couldn't fdopen(), error: %d\n", errno); - } - } -#endif - if(!fp) { - g_free(*fpath); - *fpath = NULL; - } - } - } else { - gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", - "g_get_tmp_dir() failed!"); - } - - return fp; -} - -gboolean program_is_valid(const char *program) -{ - GError *error = NULL; - char **argv; - gchar *progname; - gboolean is_valid = FALSE; - - if (program == NULL || *program == '\0') { - return FALSE; - } - - if (!g_shell_parse_argv(program, NULL, &argv, &error)) { - gaim_debug(GAIM_DEBUG_ERROR, "program_is_valid", - "Could not parse program '%s': %s\n", - program, error->message); - g_error_free(error); - return FALSE; - } - - if (argv == NULL) { - return FALSE; - } - - progname = g_find_program_in_path(argv[0]); - is_valid = (progname != NULL); - - g_strfreev(argv); - g_free(progname); - - return is_valid; -} - -char *gaim_try_conv_to_utf8(const char *str) -{ - gsize converted; - char *utf8; - - if (str == NULL) { - return NULL; - } - - if (g_utf8_validate(str, -1, NULL)) { - return g_strdup(str); - } - - utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL); - if (utf8) - return(utf8); - - g_free(utf8); - - utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL); - if (utf8 && converted == strlen (str)) { - return(utf8); - } else if (utf8) { - g_free(utf8); - } - - return(NULL); -} - -char *gaim_getip_from_fd(int fd) -{ - struct sockaddr addr; - socklen_t namelen = sizeof(addr); - - if (getsockname(fd, &addr, &namelen)) - return NULL; - - return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr)); -} - -gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b) { - gchar *a_norm=NULL; - gchar *b_norm=NULL; - gint ret=-1; - - if(!a && b) - return -1; - else if(!b && a) - return 1; - else if(!a && !b) - return 0; - - if(!g_utf8_validate(a, -1, NULL) || !g_utf8_validate(b, -1, NULL)) { - gaim_debug(GAIM_DEBUG_ERROR, "gaim_utf8_strcasecmp", "One or both parameters are invalid UTF8\n"); - return ret; - } - - a_norm = g_utf8_casefold(a, -1); - b_norm = g_utf8_casefold(b, -1); - ret = g_utf8_collate(a_norm, b_norm); - g_free(a_norm); - g_free(b_norm); - return ret; -} - -gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, const gchar *replacement) { - gchar **split; - gchar *ret; - - split = g_strsplit(string, delimiter, 0); - ret = g_strjoinv(replacement, split); - g_strfreev(split); - - return ret; -} - -const char *gaim_strcasestr(const char *haystack, const char *needle) { - size_t hlen, nlen; - const char *tmp, *ret; - - g_return_val_if_fail(haystack != NULL, NULL); - g_return_val_if_fail(needle != NULL, NULL); - - hlen = strlen(haystack); - nlen = strlen(needle); - tmp = haystack, - ret = NULL; - - g_return_val_if_fail(hlen > 0, NULL); - g_return_val_if_fail(nlen > 0, NULL); - - while (*tmp && !ret) { - if (!g_ascii_strncasecmp(needle, tmp, nlen)) - ret = tmp; - else - tmp++; - } - - return ret; -} - -char * -gaim_str_size_to_units(size_t size) -{ - static const char *size_str[4] = { "bytes", "KB", "MB", "GB" }; - float size_mag; - int size_index = 0; - - if (size == -1) { - return g_strdup(_("Calculating...")); - } - else if (size == 0) { - return g_strdup(_("Unknown.")); - } - else { - size_mag = (float)size; - - while ((size_index < 4) && (size_mag > 1024)) { - size_mag /= 1024; - size_index++; - } - - return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]); - } -} - +/************************************************************************** + * Markup Functions + **************************************************************************/ gboolean gaim_markup_find_tag(const char *needle, const char *haystack, const char **start, const char **end, GData **attributes) @@ -1386,6 +871,26 @@ return str2; } +static gint +badchar(char c) +{ + switch (c) { + case ' ': + case ',': + case '(': + case ')': + case '\0': + case '\n': + case '<': + case '>': + case '"': + case '\'': + return 1; + default: + return 0; + } +} + char * gaim_markup_linkify(const char *text) { @@ -1595,6 +1100,497 @@ return tmp; } + +/************************************************************************** + * Path/Filename Functions + **************************************************************************/ +const char * +gaim_home_dir(void) +{ +#ifndef _WIN32 + if(g_get_home_dir()) + return g_get_home_dir(); + else + return NULL; +#else + return wgaim_data_dir(); +#endif +} + +/* returns a string of the form ~/.gaim, where ~ is replaced by the user's home + * dir. Note that there is no trailing slash after .gaim. */ +char * +gaim_user_dir(void) +{ + const gchar *hd = gaim_home_dir(); + + if(hd) + { + strcpy( (char*)&home_dir, hd ); + strcat( (char*)&home_dir, G_DIR_SEPARATOR_S ".gaim" ); + + return (gchar*)&home_dir; + } + + return NULL; +} + +/* + * Like mkstemp() but returns a file pointer, uses a pre-set template, + * uses the semantics of tempnam() for the directory to use and allocates + * the space for the filepath. + * + * Caller is responsible for closing the file and removing it when done, + * as well as freeing the space pointed-to by "path" with g_free(). + * + * Returns NULL on failure and cleans up after itself if so. + */ +static const char *gaim_mkstemp_templ = {"gaimXXXXXX"}; + +FILE * +gaim_mkstemp(char **fpath) +{ + const gchar *tmpdir; +#ifndef _WIN32 + int fd; +#endif + FILE *fp = NULL; + + g_return_val_if_fail(fpath != NULL, NULL); + + if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) { + if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) { +#ifdef _WIN32 + char* result = _mktemp( *fpath ); + if( result == NULL ) + gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", + "Problem creating the template\n"); + else + { + if( (fp = fopen( result, "w+" )) == NULL ) { + gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", + "Couldn't fopen() %s\n", result); + } + } +#else + if((fd = mkstemp(*fpath)) == -1) { + gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", + "Couldn't make \"%s\", error: %d\n", + *fpath, errno); + } else { + if((fp = fdopen(fd, "r+")) == NULL) { + close(fd); + gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", + "Couldn't fdopen(), error: %d\n", errno); + } + } +#endif + if(!fp) { + g_free(*fpath); + *fpath = NULL; + } + } + } else { + gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp", + "g_get_tmp_dir() failed!"); + } + + return fp; +} + +gboolean +gaim_program_is_valid(const char *program) +{ + GError *error = NULL; + char **argv; + gchar *progname; + gboolean is_valid = FALSE; + + g_return_val_if_fail(program != NULL, FALSE); + g_return_val_if_fail(*program != '\0', FALSE); + + if (!g_shell_parse_argv(program, NULL, &argv, &error)) { + gaim_debug(GAIM_DEBUG_ERROR, "program_is_valid", + "Could not parse program '%s': %s\n", + program, error->message); + g_error_free(error); + return FALSE; + } + + if (argv == NULL) { + return FALSE; + } + + progname = g_find_program_in_path(argv[0]); + is_valid = (progname != NULL); + + g_strfreev(argv); + g_free(progname); + + return is_valid; +} + +char * +gaim_fd_get_ip(int fd) +{ + struct sockaddr addr; + socklen_t namelen = sizeof(addr); + + g_return_val_if_fail(fd != 0, NULL); + + if (getsockname(fd, &addr, &namelen)) + return NULL; + + return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr)); +} + + +/************************************************************************** + * String Functions + **************************************************************************/ +char * +gaim_normalize(const char *s) +{ + static char buf[BUF_LEN]; + char *tmp; + int i, j; + + g_return_val_if_fail(s != NULL, NULL); + + strncpy(buf, s, BUF_LEN); + for (i=0, j=0; buf[j]; i++, j++) { + while (buf[j] == ' ') + j++; + buf[i] = buf[j]; + } + buf[i] = '\0'; + + tmp = g_utf8_strdown(buf, -1); + g_snprintf(buf, sizeof(buf), "%s", tmp); + g_free(tmp); + tmp = g_utf8_normalize(buf, -1, G_NORMALIZE_DEFAULT); + g_snprintf(buf, sizeof(buf), "%s", tmp); + g_free(tmp); + + return buf; +} + +/* Look for %n, %d, or %t in msg, and replace with the sender's name, date, + or time */ +char * +gaim_str_sub_away_formatters(const char *msg, const char *name) +{ + char *c; + static char cpy[BUF_LONG]; + int cnt = 0; + time_t t; + struct tm *tme; + char tmp[20]; + + g_return_val_if_fail(msg != NULL, NULL); + g_return_val_if_fail(name != NULL, NULL); + + t = time(NULL); + tme = localtime(&t); + + cpy[0] = '\0'; + c = (char *)msg; + while (*c) { + switch (*c) { + case '%': + if (*(c + 1)) { + switch (*(c + 1)) { + case 'n': + /* append name */ + strcpy(cpy + cnt, name); + cnt += strlen(name); + c++; + break; + case 'd': + /* append date */ + strftime(tmp, 20, "%m/%d/%Y", tme); + strcpy(cpy + cnt, tmp); + cnt += strlen(tmp); + c++; + break; + case 't': + /* append time */ + strftime(tmp, 20, "%r", tme); + strcpy(cpy + cnt, tmp); + cnt += strlen(tmp); + c++; + break; + default: + cpy[cnt++] = *c; + } + } + break; + default: + cpy[cnt++] = *c; + } + c++; + } + cpy[cnt] = '\0'; + return (cpy); +} + +/* + * rcg10312000 This could be more robust, but it works for my current + * goal: to remove those annoying
tags. :) + * dtf12162000 made the loop more readable. i am a neat freak. ;) */ +void +gaim_strncpy_nohtml(char *dest, const char *src, size_t destsize) +{ + char *ptr; + + g_return_if_fail(dest != NULL); + g_return_if_fail(src != NULL); + g_return_if_fail(destsize > 0); + + g_snprintf(dest, destsize, "%s", src); + + while ((ptr = strstr(dest, "
")) != NULL) { + /* replace
with a newline. */ + *ptr = '\n'; + memmove(ptr + 1, ptr + 4, strlen(ptr + 4) + 1); + } +} + +void +gaim_strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize) +{ + gchar *end; + + g_return_if_fail(dest != NULL); + g_return_if_fail(src != NULL); + g_return_if_fail(destsize > 0); + + end = dest + destsize; + + while (dest < end) { + if (*src == '\n' && dest < end - 5) { + strcpy(dest, "
"); + src++; + dest += 4; + } else if(*src == '\r') { + src++; + } else { + *dest++ = *src; + if (*src == '\0') + return; + else + src++; + } + } +} + +/* + * Like strncpy_withhtml (above), but malloc()'s the necessary space + * + * The caller is responsible for freeing the space pointed to by the + * return value. + */ +char * +gaim_strdup_withhtml(const char *src) +{ + char *sp, *dest; + gulong destsize; + + g_return_val_if_fail(src != NULL, NULL); + + /* + * All we need do is multiply the number of newlines by 3 (the + * additional length of "
" over "\n"), account for the + * terminator, malloc the space and call strncpy_withhtml. + */ + for(destsize = 0, sp = (gchar *)src; + (sp = strchr(sp, '\n')) != NULL; + ++sp, ++destsize) + ; + + destsize *= 3; + destsize += strlen(src) + 1; + dest = g_malloc(destsize); + gaim_strncpy_withhtml(dest, src, destsize); + + return dest; +} + +char * +gaim_str_add_cr(const char *text) +{ + char *ret = NULL; + int count = 0, i, j; + + g_return_val_if_fail(text != NULL, NULL); + + if (text[0] == '\n') + count++; + for (i = 1; i < strlen(text); i++) + if (text[i] == '\n' && text[i - 1] != '\r') + count++; + + if (count == 0) + return g_strdup(text); + + ret = g_malloc0(strlen(text) + count + 1); + + i = 0; j = 0; + if (text[i] == '\n') + ret[j++] = '\r'; + ret[j++] = text[i++]; + for (; i < strlen(text); i++) { + if (text[i] == '\n' && text[i - 1] != '\r') + ret[j++] = '\r'; + ret[j++] = text[i]; + } + + gaim_debug_misc("gaim_str_add_cr", "got: %s, leaving with %s\n", + text, ret); + + return ret; +} + +void +gaim_str_strip_linefeed(char *text) +{ + int i, j; + char *text2; + + g_return_if_fail(text != NULL); + + text2 = g_malloc(strlen(text) + 1); + + for (i = 0, j = 0; text[i]; i++) + if (text[i] != '\r') + text2[j++] = text[i]; + text2[j] = '\0'; + + strcpy(text, text2); + g_free(text2); +} + +char * +gaim_strreplace(const char *string, const char *delimiter, + const char *replacement) +{ + gchar **split; + gchar *ret; + + g_return_val_if_fail(string != NULL, NULL); + g_return_val_if_fail(delimiter != NULL, NULL); + g_return_val_if_fail(replacement != NULL, NULL); + + split = g_strsplit(string, delimiter, 0); + ret = g_strjoinv(replacement, split); + g_strfreev(split); + + return ret; +} + +const char * +gaim_strcasestr(const char *haystack, const char *needle) +{ + size_t hlen, nlen; + const char *tmp, *ret; + + g_return_val_if_fail(haystack != NULL, NULL); + g_return_val_if_fail(needle != NULL, NULL); + + hlen = strlen(haystack); + nlen = strlen(needle); + tmp = haystack, + ret = NULL; + + g_return_val_if_fail(hlen > 0, NULL); + g_return_val_if_fail(nlen > 0, NULL); + + while (*tmp && !ret) { + if (!g_ascii_strncasecmp(needle, tmp, nlen)) + ret = tmp; + else + tmp++; + } + + return ret; +} + +char * +gaim_str_size_to_units(size_t size) +{ + static const char *size_str[4] = { "bytes", "KB", "MB", "GB" }; + float size_mag; + int size_index = 0; + + if (size == -1) { + return g_strdup(_("Calculating...")); + } + else if (size == 0) { + return g_strdup(_("Unknown.")); + } + else { + size_mag = (float)size; + + while ((size_index < 4) && (size_mag > 1024)) { + size_mag /= 1024; + size_index++; + } + + return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]); + } +} + +char * +gaim_str_seconds_to_string(guint sec) +{ + guint daze, hrs, min; + char *ret = NULL; + + daze = sec / (60 * 60 * 24); + hrs = (sec % (60 * 60 * 24)) / (60 * 60); + min = (sec % (60 * 60)) / 60; + sec = min % 60; + + if (daze) { + if (hrs || min) { + if (hrs) { + if (min) { + ret = g_strdup_printf( + "%d %s, %d %s, %d %s.", + daze, ngettext("day","days",daze), + hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min)); + } else { + ret = g_strdup_printf( + "%d %s, %d %s.", + daze, ngettext("day","days",daze), hrs, ngettext("hour","hours",hrs)); + } + } else { + ret = g_strdup_printf( + "%d %s, %d %s.", + daze, ngettext("day","days",daze), min, ngettext("minute","minutes",min)); + } + } else + ret = g_strdup_printf("%d %s.", daze, ngettext("day","days",daze)); + } else { + if (hrs) { + if (min) { + ret = g_strdup_printf( + "%d %s, %d %s.", + hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min)); + } else { + ret = g_strdup_printf("%d %s.", hrs, ngettext("hour","hours",hrs)); + } + } else { + ret = g_strdup_printf("%d %s.", min, ngettext("minute","minutes",min)); + } + } + + return ret; +} + +/************************************************************************** + * URI/URL Functions + **************************************************************************/ gboolean gaim_url_parse(const char *url, char **ret_host, int *ret_port, char **ret_path) @@ -1920,3 +1916,65 @@ cb(user_data, g_strdup(_("g003: Error opening connection.\n")), 0); } } + + +/************************************************************************** + * UTF8 String Functions + **************************************************************************/ +char * +gaim_utf8_try_convert(const char *str) +{ + gsize converted; + char *utf8; + + g_return_val_if_fail(str != NULL, NULL); + + if (g_utf8_validate(str, -1, NULL)) { + return g_strdup(str); + } + + utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL); + if (utf8) + return(utf8); + + g_free(utf8); + + utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL); + if (utf8 && converted == strlen (str)) { + return(utf8); + } else if (utf8) { + g_free(utf8); + } + + return(NULL); +} + +int +gaim_utf8_strcasecmp(const char *a, const char *b) +{ + char *a_norm = NULL; + char *b_norm = NULL; + int ret = -1; + + if(!a && b) + return -1; + else if(!b && a) + return 1; + else if(!a && !b) + return 0; + + if(!g_utf8_validate(a, -1, NULL) || !g_utf8_validate(b, -1, NULL)) + { + gaim_debug_error("gaim_utf8_strcasecmp", + "One or both parameters are invalid UTF8\n"); + return ret; + } + + a_norm = g_utf8_casefold(a, -1); + b_norm = g_utf8_casefold(b, -1); + ret = g_utf8_collate(a_norm, b_norm); + g_free(a_norm); + g_free(b_norm); + + return ret; +} diff -r 9220c7490cd1 -r 6faeeecab0dc src/util.h --- a/src/util.h Wed Oct 01 06:17:28 2003 +0000 +++ b/src/util.h Wed Oct 01 07:15:53 2003 +0000 @@ -34,42 +34,10 @@ extern "C" { #endif -/** - * Normalizes a string, so that it is suitable for comparison. - * - * The returned string will point to a static buffer, so if the - * string is intended to be kept long-term, you must - * g_strdup() it. Also, calling normalize() twice in the same line - * will lead to problems. - * - * @param str The string to normalize. - * - * @return A pointer to the normalized version stored in a static buffer. - */ -char *gaim_normalize(const char *str); - -/** - * Converts a string to its base-64 equivalent. - * - * @param buf The data to convert. - * @param len The length of the data. - * - * @return The base-64 version of @a str. - * - * @see frombase64() - */ -char *gaim_base64_encode(const unsigned char *buf, size_t len); - -/** - * Converts a string back from its base-64 equivalent. - * - * @param str The string to convert back. - * @param ret_str The returned, non-base-64 string. - * @param ret_len The returned string length. - * - * @see tobase64() - */ -void gaim_base64_decode(const char *str, char **ret_str, int *ret_len); +/**************************************************************************/ +/** @name Base16 Functions */ +/**************************************************************************/ +/*@{*/ /** * Converts a string to its base-16 equivalent. @@ -95,6 +63,45 @@ */ int gaim_base16_decode(const char *str, unsigned char **ret_str); +/*@}*/ + + +/**************************************************************************/ +/** @name Base64 Functions */ +/**************************************************************************/ +/*@{*/ + +/** + * Converts a string to its base-64 equivalent. + * + * @param buf The data to convert. + * @param len The length of the data. + * + * @return The base-64 version of @a str. + * + * @see frombase64() + */ +unsigned char *gaim_base64_encode(const unsigned char *buf, size_t len); + +/** + * Converts a string back from its base-64 equivalent. + * + * @param str The string to convert back. + * @param ret_str The returned, non-base-64 string. + * @param ret_len The returned string length. + * + * @see tobase64() + */ +void gaim_base64_decode(const char *str, char **ret_str, int *ret_len); + +/*@}*/ + + +/**************************************************************************/ +/** @name Date/Time Functions */ +/**************************************************************************/ +/*@{*/ + /** * Returns the current local time in hour:minute:second form. * @@ -105,17 +112,7 @@ * * @see full_date() */ -char *date(void); - -/** - * Converts seconds into a human-readable form. - * - * @param sec The seconds. - * - * @return A human-readable form, containing days, hours, minutes, and - * seconds. - */ -char *sec_to_text(guint sec); +char *gaim_date(void); /** * Returns the date and time in human-readable form. @@ -127,92 +124,7 @@ * * @see date() */ -char *full_date(void); - -/** - * Looks for %n, %d, or %t in a string, and replaces them with the - * specified name, date, and time, respectively. - * - * The returned string is stored in a static buffer, so the result - * should be g_strdup()'d if it's intended to be used for long. - * - * @param str The string that may contain the special variables. - * @param name The sender name. - * - * @return A new string where the special variables are expanded. - */ -char *away_subs(const char *str, const char *name); - -/**` - * Returns the user's home directory. - * - * @return The user's home directory. - * - * @see gaim_user_dir() - */ -const gchar *gaim_home_dir(void); - -/** - * Returns the gaim settings directory in the user's home directory. - * - * @return The gaim settings directory. - * - * @see gaim_home_dir() - */ -char *gaim_user_dir(void); - -/** - * Copies a string and replaces all HTML linebreaks with newline characters. - * - * @param dest The destination string. - * @param src The source string. - * @param dest_len The destination string length. - * - * @see strncpy_withhtml() - * @see strdup_withhtml() - */ -void strncpy_nohtml(gchar *dest, const gchar *src, size_t dest_len); - -/** - * Copies a string and replaces all newline characters with HTML linebreaks. - * - * @param dest The destination string. - * @param src The source string. - * @param dest_len The destination string length. - * - * @see strncpy_nohtml() - * @see strdup_withhtml() - */ -void strncpy_withhtml(gchar *dest, const gchar *src, size_t dest_len); - -/** - * Duplicates a string and replaces all newline characters from the - * source string with HTML linebreaks. - * - * @param src The source string. - * - * @return The new string. - * - * @see strncpy_nohtml() - * @see strncpy_withhtml() - */ -gchar *strdup_withhtml(const gchar *src); - -/** - * Ensures that all linefeeds have a matching carriage return. - * - * @param str The source string. - * - * @return The string with carriage returns. - */ -char *add_cr(const char *str); - -/** - * Strips all linefeeds from a string. - * - * @param str The string to strip linefeeds from. - */ -void strip_linefeed(char *str); +char *gaim_date_full(void); /** * Builds a time_t from the supplied information. @@ -226,99 +138,16 @@ * * @return A time_t. */ -time_t get_time(int year, int month, int day, - int hour, int min, int sec); - -/** - * Creates a temporary file and returns a file pointer to it. - * - * This is like mkstemp(), but returns a file pointer and uses a - * pre-set template. It uses the semantics of tempnam() for the - * directory to use and allocates the space for the file path. - * - * The caller is responsible for closing the file and removing it when - * done, as well as freeing the space pointed to by @a path with - * g_free(). - * - * @param path The returned path to the temp file. - * - * @return A file pointer to the temporary file, or @c NULL on failure. - */ -FILE *gaim_mkstemp(gchar **path); +time_t gaim_time_build(int year, int month, int day, int hour, + int min, int sec); -/** - * Checks if the given program name is valid and executable. - * - * @parm program The file name of the application. - * - * @return True if the program is runable. - */ -gboolean program_is_valid(const char *program); - -/** - * Attempts to convert a string to UTF-8 from an unknown encoding. - * - * This function checks the locale and tries sane defaults. - * - * @param str The source string. - * - * @return The UTF-8 string, or @c NULL if it could not be converted. - */ -char *gaim_try_conv_to_utf8(const char *str); +/*@}*/ -/** - * Returns the IP address from a socket file descriptor. - * - * @param fd The socket file descriptor. - * - * @return The IP address, or @c NULL on error. - */ -char *gaim_getip_from_fd(int fd); -/** - * Compares two UTF-8 strings. - * - * @param a The first string. - * @param b The second string. - * - * @return -1 if @a is less than @a b. - * 0 if @a is equal to @a b. - * 1 if @a is greater than @a b. - */ -gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b); - -/** - * Given a string, this replaces one substring with another - * and returns a newly allocated string. - * - * @param string The string from which to replace stuff. - * @param delimiter The substring you want replaced. - * @param replacement The substring you want inserted in place - * of the delimiting substring. - */ -gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, - const gchar *replacement); - -/** - * This is like strstr, except that it ignores ASCII case in - * searching for the substring. - * - * @param haystack The string to search in. - * @param needle The substring to find. - * - * @return the location of the substring if found, or NULL if not - */ -const char *gaim_strcasestr(const char *haystack, const char *needle); - -/** - * Returns a string representing a filesize in the appropriate - * units (MB, KB, GB, etc.) - * - * @param size The size - * - * @return The string in units form. This must be freed. - */ -char *gaim_str_size_to_units(size_t size); +/**************************************************************************/ +/** @name Markup Functions */ +/**************************************************************************/ +/*@{*/ /** * Finds a HTML tag matching the given name. @@ -396,6 +225,207 @@ */ char *gaim_markup_linkify(const char *str); +/*@}*/ + + +/**************************************************************************/ +/** @name Path/Filename Functions */ +/**************************************************************************/ +/*@{*/ + +/** + * Returns the user's home directory. + * + * @return The user's home directory. + * + * @see gaim_user_dir() + */ +const gchar *gaim_home_dir(void); + +/** + * Returns the gaim settings directory in the user's home directory. + * + * @return The gaim settings directory. + * + * @see gaim_home_dir() + */ +char *gaim_user_dir(void); + +/** + * Creates a temporary file and returns a file pointer to it. + * + * This is like mkstemp(), but returns a file pointer and uses a + * pre-set template. It uses the semantics of tempnam() for the + * directory to use and allocates the space for the file path. + * + * The caller is responsible for closing the file and removing it when + * done, as well as freeing the space pointed to by @a path with + * g_free(). + * + * @param path The returned path to the temp file. + * + * @return A file pointer to the temporary file, or @c NULL on failure. + */ +FILE *gaim_mkstemp(char **path); + +/** + * Checks if the given program name is valid and executable. + * + * @parm program The file name of the application. + * + * @return True if the program is runable. + */ +gboolean gaim_program_is_valid(const char *program); + +/** + * Returns the IP address from a socket file descriptor. + * + * @param fd The socket file descriptor. + * + * @return The IP address, or @c NULL on error. + */ +char *gaim_fd_get_ip(int fd); + +/*@}*/ + + +/**************************************************************************/ +/** @name String Functions */ +/**************************************************************************/ +/*@{*/ + +/** + * Normalizes a string, so that it is suitable for comparison. + * + * The returned string will point to a static buffer, so if the + * string is intended to be kept long-term, you must + * g_strdup() it. Also, calling normalize() twice in the same line + * will lead to problems. + * + * @param str The string to normalize. + * + * @return A pointer to the normalized version stored in a static buffer. + */ +char *gaim_normalize(const char *str); + +/** + * Looks for %n, %d, or %t in a string, and replaces them with the + * specified name, date, and time, respectively. + * + * The returned string is stored in a static buffer, so the result + * should be g_strdup()'d if it's intended to be used for long. + * + * @param str The string that may contain the special variables. + * @param name The sender name. + * + * @return A new string where the special variables are expanded. + */ +char *gaim_str_sub_away_formatters(const char *str, const char *name); + +/** + * Copies a string and replaces all HTML linebreaks with newline characters. + * + * @param dest The destination string. + * @param src The source string. + * @param dest_len The destination string length. + * + * @see gaim_strncpy_withhtml() + * @see gaim_strdup_withhtml() + */ +void gaim_strncpy_nohtml(char *dest, const char *src, size_t dest_len); + +/** + * Copies a string and replaces all newline characters with HTML linebreaks. + * + * @param dest The destination string. + * @param src The source string. + * @param dest_len The destination string length. + * + * @see gaim_strncpy_nohtml() + * @see gaim_strdup_withhtml() + */ +void gaim_strncpy_withhtml(gchar *dest, const gchar *src, size_t dest_len); + +/** + * Duplicates a string and replaces all newline characters from the + * source string with HTML linebreaks. + * + * @param src The source string. + * + * @return The new string. + * + * @see gaim_strncpy_nohtml() + * @see gaim_strncpy_withhtml() + */ +char *gaim_strdup_withhtml(const char *src); + +/** + * Ensures that all linefeeds have a matching carriage return. + * + * @param str The source string. + * + * @return The string with carriage returns. + */ +char *gaim_str_add_cr(const char *str); + +/** + * Strips all linefeeds from a string. + * + * @param str The string to strip linefeeds from. + */ +void gaim_str_strip_linefeed(char *str); + +/** + * Given a string, this replaces one substring with another + * and returns a newly allocated string. + * + * @param string The string from which to replace stuff. + * @param delimiter The substring you want replaced. + * @param replacement The substring you want inserted in place + * of the delimiting substring. + */ +char *gaim_strreplace(const char *string, const char *delimiter, + const char *replacement); + +/** + * This is like strstr, except that it ignores ASCII case in + * searching for the substring. + * + * @param haystack The string to search in. + * @param needle The substring to find. + * + * @return the location of the substring if found, or NULL if not + */ +const char *gaim_strcasestr(const char *haystack, const char *needle); + +/** + * Returns a string representing a filesize in the appropriate + * units (MB, KB, GB, etc.) + * + * @param size The size + * + * @return The string in units form. This must be freed. + */ +char *gaim_str_size_to_units(size_t size); + +/** + * Converts seconds into a human-readable form. + * + * @param sec The seconds. + * + * @return A human-readable form, containing days, hours, minutes, and + * seconds. + */ +char *gaim_str_seconds_to_string(guint sec); + +/*@}*/ + + +/**************************************************************************/ +/** @name URI/URL Functions */ +/**************************************************************************/ +/*@{*/ + /** * Parses a URL, returning its host, port, and file path. * @@ -425,6 +455,39 @@ void (*cb)(void *, const char *, size_t), void *data); +/*@}*/ + + +/************************************************************************** + * UTF8 String Functions + **************************************************************************/ +/*@{*/ + +/** + * Attempts to convert a string to UTF-8 from an unknown encoding. + * + * This function checks the locale and tries sane defaults. + * + * @param str The source string. + * + * @return The UTF-8 string, or @c NULL if it could not be converted. + */ +char *gaim_utf8_try_convert(const char *str); + +/** + * Compares two UTF-8 strings. + * + * @param a The first string. + * @param b The second string. + * + * @return -1 if @a is less than @a b. + * 0 if @a is equal to @a b. + * 1 if @a is greater than @a b. + */ +int gaim_utf8_strcasecmp(const char *a, const char *b); + +/*@}*/ + #ifdef __cplusplus } #endif