* Purple's oscar protocol plugin * This file is the legal property of its developers. * Please see the AUTHORS file distributed alongside this file. * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA static const char * const msgerrreason[] = { N_("Server rate limit exceeded"), N_("Client rate limit exceeded"), N_("Service unavailable"), N_("Service not defined"), N_("Not supported by host"), N_("Not supported by client"), N_("Busted SNAC payload"), N_("Insufficient rights"), N_("In local permit/deny"), N_("Warning level too high (sender)"), N_("Warning level too high (receiver)"), N_("User temporarily unavailable"), static const int msgerrreasonlen = G_N_ELEMENTS(msgerrreason); const char *oscar_get_msgerr_reason(size_t reason) return (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Unknown reason"); int oscar_get_ui_info_int(const char *str, int default_value) ui_info = purple_core_get_ui_info(); if (g_hash_table_lookup_extended(ui_info, str, NULL, &value)) return GPOINTER_TO_INT(value); const char *oscar_get_ui_info_string(const char *str, const char *default_value) const char *value = NULL; ui_info = purple_core_get_ui_info(); value = g_hash_table_lookup(ui_info, str); gchar *oscar_get_clientstring(void) const char *name, *version; name = oscar_get_ui_info_string("name", "Purple"); version = oscar_get_ui_info_string("version", VERSION); return g_strdup_printf("%s/%s", name, version);; * Calculate the checksum of a given icon. aimutil_iconsum(const guint8 *buf, int buflen) for (i=0, sum=0; i+1<buflen; i+=2) sum += (buf[i+1] << 8) + buf[i]; sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff); * Check if the given name is a valid AIM username. * Example: Henry_Ford@mac.com * Example: 1KrazyKat@example.com * @return TRUE if the name is valid, FALSE if not. oscar_util_valid_name_aim(const char *name) if (purple_email_is_valid(name)) /* Normal AIM usernames can't start with a number, period or underscore */ if (isalnum(name[0]) == 0) for (i = 0; name[i] != '\0'; i++) { if (!isalnum(name[i]) && name[i] != ' ' && name[i] != '.' && name[i] != '_') * Check if the given name is a valid ICQ username. * @return TRUE if the name is valid, FALSE if not. oscar_util_valid_name_icq(const char *name) for (i = 0; name[i] != '\0'; i++) { * Check if the given name is a valid SMS username. * @return TRUE if the name is valid, FALSE if not. oscar_util_valid_name_sms(const char *name) for (i = 1; name[i] != '\0'; i++) { * Check if the given name is a valid oscar username. * @return TRUE if the name is valid, FALSE if not. oscar_util_valid_name(const char *name) if ((name == NULL) || (*name == '\0')) return oscar_util_valid_name_icq(name) || oscar_util_valid_name_sms(name) || oscar_util_valid_name_aim(name); * This takes two names and compares them using the rules * on usernames for AIM/AOL. Mainly, this means case and space * insensitivity (all case differences and spacing differences are * ignored, with the exception that usernames can not start with * @return 0 if equal, non-0 if different /* TODO: Do something different for email addresses. */ oscar_util_name_compare(const char *name1, const char *name2) if ((name1 == NULL) || (name2 == NULL)) if (toupper(*name1) != toupper(*name2)) } while ((*name1 != '\0') && name1++ && name2++); * Looks for %n, %d, or %t in a string, and replaces them with the * specified name, date, and time, respectively. * @param str The string that may contain the special variables. * @param name The sender name. * @return A newly allocated string where the special variables are * expanded. This should be g_free'd by the caller. oscar_util_format_string(const char *str, const char *name) g_return_val_if_fail(str != NULL, NULL); g_return_val_if_fail(name != NULL, NULL); /* Create an empty GString that is hopefully big enough for most messages */ cpy = g_string_sized_new(1024); g_string_append(cpy, name); g_string_append(cpy, purple_date_format_short(tme)); g_string_append(cpy, purple_time_format(tme)); g_string_append_c(cpy, *c); g_string_append_c(cpy, *c); g_string_append_c(cpy, *c); return g_string_free(cpy, FALSE); oscar_format_buddies(GSList *buddies, const gchar *no_buddies_message) return g_strdup_printf("<i>%s</i>", no_buddies_message); result = g_string_new(""); for (cur = buddies; cur != NULL; cur = cur->next) { PurpleBuddy *buddy = cur->data; const gchar *bname = purple_buddy_get_name(buddy); const gchar *alias = purple_buddy_get_alias_only(buddy); g_string_append(result, bname); g_string_append_printf(result, " (%s)", alias); g_string_append(result, "<br>"); return g_string_free(result, FALSE);