# HG changeset patch # User Evan Schoenberg # Date 1144792091 0 # Node ID fa7313d125ac2ebf170350836994f288c23db4e3 # Parent 880c956dd0313407b1a49632ecb8d15be24dad5a [gaim-migrate @ 16013] utils.c / utils.h is a common name. Namespacing the gg prpl's utils files to gg-utils.c and gg-utils.h. committer: Tailor Script diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/Makefile.am --- a/src/protocols/gg/Makefile.am Tue Apr 11 21:07:58 2006 +0000 +++ b/src/protocols/gg/Makefile.am Tue Apr 11 21:48:11 2006 +0000 @@ -3,8 +3,8 @@ pkgdir = $(libdir)/gaim GGSOURCES = \ - utils.h \ - utils.c \ + gg-utils.h \ + gg-utils.c \ confer.h \ confer.c \ search.h \ diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/Makefile.mingw --- a/src/protocols/gg/Makefile.mingw Tue Apr 11 21:07:58 2006 +0000 +++ b/src/protocols/gg/Makefile.mingw Tue Apr 11 21:48:11 2006 +0000 @@ -81,7 +81,7 @@ confer.c \ gg.c \ search.c \ - utils.c + gg-utils.c OBJECTS = $(C_SRC:%.c=%.o) diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/buddylist.c --- a/src/protocols/gg/buddylist.c Tue Apr 11 21:07:58 2006 +0000 +++ b/src/protocols/gg/buddylist.c Tue Apr 11 21:48:11 2006 +0000 @@ -24,7 +24,7 @@ #include #include "gg.h" -#include "utils.h" +#include "gg-utils.h" #include "buddylist.h" diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/confer.c --- a/src/protocols/gg/confer.c Tue Apr 11 21:07:58 2006 +0000 +++ b/src/protocols/gg/confer.c Tue Apr 11 21:48:11 2006 +0000 @@ -23,7 +23,7 @@ #include #include "gg.h" -#include "utils.h" +#include "gg-utils.h" #include "confer.h" /* GaimConversation *ggp_confer_find_by_name(GaimConnection *gc, const gchar *name) {{{ */ diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/gg-utils.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/protocols/gg/gg-utils.c Tue Apr 11 21:48:11 2006 +0000 @@ -0,0 +1,104 @@ +/** + * @file gg-utils.c + * + * gaim + * + * Copyright (C) 2005 Bartosz Oler + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "gg-utils.h" + + +/* uin_t ggp_str_to_uin(const char *str) {{{ */ +uin_t ggp_str_to_uin(const char *str) +{ + char *tmp; + long num; + + if (!str) + return 0; + + errno = 0; + num = strtol(str, &tmp, 10); + + if (*str == '\0' || *tmp != '\0') + return 0; + + if ((errno == ERANGE || (num == LONG_MAX || num == LONG_MIN)) +#if (LONG_MAX > UINT_MAX) + || num > (long)UINT_MAX +#endif + || num < 0) + return 0; + + return (uin_t) num; +} +/* }}} */ + +/* char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) {{{ */ +char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) +{ + gchar *msg; + GError *err = NULL; + + if (locstr == NULL) + return NULL; + + msg = g_convert_with_fallback(locstr, strlen(locstr), encdst, encsrc, + "?", NULL, NULL, &err); + if (err != NULL) { + gaim_debug_error("gg", "Error converting from %s to %s: %s\n", + encsrc, encdst, err->message); + g_error_free(err); + } + + /* Just in case? */ + if (msg == NULL) + msg = g_strdup(locstr); + + return msg; +} +/* }}} */ + +/* ggp_get_uin(GaimAccount *account) {{{ */ +uin_t ggp_get_uin(GaimAccount *account) +{ + return ggp_str_to_uin(gaim_account_get_username(account)); +} +/* }}} */ + +/* char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) {{{ */ +char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) +{ + GaimBuddy *buddy; + gchar *str_uin; + + str_uin = g_strdup_printf("%lu", (unsigned long int)uin); + + buddy = gaim_find_buddy(gaim_connection_get_account(gc), str_uin); + if (buddy != NULL) { + g_free(str_uin); + return g_strdup(gaim_buddy_get_alias(buddy)); + } else { + return str_uin; + } +} +/* }}} */ + + +/* vim: set ts=8 sts=0 sw=8 noet: */ diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/gg-utils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/protocols/gg/gg-utils.h Tue Apr 11 21:48:11 2006 +0000 @@ -0,0 +1,86 @@ +/** + * @file gg-utils.h + * + * gaim + * + * Copyright (C) 2005 Bartosz Oler + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _GAIM_GG_UTILS_H +#define _GAIM_GG_UTILS_H + +#include "internal.h" + +#include "plugin.h" +#include "version.h" +#include "notify.h" +#include "status.h" +#include "blist.h" +#include "accountopt.h" +#include "debug.h" +#include "util.h" +#include "request.h" + +#include "gg.h" + + +/* + * Convert a base 10 string to a UIN. + * + * @param str The string to convert + * @return UIN or 0 if an error occurred. + */ +uin_t +ggp_str_to_uin(const char *str); + +/** + * Convert enconding of a given string. + * + * @param locstr Input string. + * @param encsrc Current encoding of the string. + * @param encdst Target encoding of the string. + * + * @return Converted string (it must be g_free()ed when not used. Or NULL if + * locstr is NULL. + */ +char * +charset_convert(const gchar *locstr, const char *encsrc, const char *encdst); + +/** + * Get UIN of a given account. + * + * @param account Current account. + * + * @return UIN of an account. + */ +uin_t +ggp_get_uin(GaimAccount *account); + +/** + * Returns the best name of a buddy from the buddylist. + * + * @param gc GaimConnection instance. + * @param uin UIN of the buddy. + * + * @return Name of the buddy, or UIN converted to string. + */ +char * +ggp_buddy_get_name(GaimConnection *gc, const uin_t uin); + +#endif /* _GAIM_GG_UTILS_H */ + +/* vim: set ts=8 sts=0 sw=8 noet: */ diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/gg.c --- a/src/protocols/gg/gg.c Tue Apr 11 21:07:58 2006 +0000 +++ b/src/protocols/gg/gg.c Tue Apr 11 21:48:11 2006 +0000 @@ -43,7 +43,7 @@ #include "confer.h" #include "search.h" #include "buddylist.h" -#include "utils.h" +#include "gg-utils.h" static GaimPlugin *my_protocol = NULL; diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/search.c --- a/src/protocols/gg/search.c Tue Apr 11 21:07:58 2006 +0000 +++ b/src/protocols/gg/search.c Tue Apr 11 21:48:11 2006 +0000 @@ -23,7 +23,7 @@ #include -#include "utils.h" +#include "gg-utils.h" #include "search.h" /* GGPSearchForm *ggp_search_form_new() {{{ */ diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/utils.c --- a/src/protocols/gg/utils.c Tue Apr 11 21:07:58 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -/** - * @file utils.c - * - * gaim - * - * Copyright (C) 2005 Bartosz Oler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include "utils.h" - - -/* uin_t ggp_str_to_uin(const char *str) {{{ */ -uin_t ggp_str_to_uin(const char *str) -{ - char *tmp; - long num; - - if (!str) - return 0; - - errno = 0; - num = strtol(str, &tmp, 10); - - if (*str == '\0' || *tmp != '\0') - return 0; - - if ((errno == ERANGE || (num == LONG_MAX || num == LONG_MIN)) -#if (LONG_MAX > UINT_MAX) - || num > (long)UINT_MAX -#endif - || num < 0) - return 0; - - return (uin_t) num; -} -/* }}} */ - -/* char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) {{{ */ -char *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) -{ - gchar *msg; - GError *err = NULL; - - if (locstr == NULL) - return NULL; - - msg = g_convert_with_fallback(locstr, strlen(locstr), encdst, encsrc, - "?", NULL, NULL, &err); - if (err != NULL) { - gaim_debug_error("gg", "Error converting from %s to %s: %s\n", - encsrc, encdst, err->message); - g_error_free(err); - } - - /* Just in case? */ - if (msg == NULL) - msg = g_strdup(locstr); - - return msg; -} -/* }}} */ - -/* ggp_get_uin(GaimAccount *account) {{{ */ -uin_t ggp_get_uin(GaimAccount *account) -{ - return ggp_str_to_uin(gaim_account_get_username(account)); -} -/* }}} */ - -/* char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) {{{ */ -char *ggp_buddy_get_name(GaimConnection *gc, const uin_t uin) -{ - GaimBuddy *buddy; - gchar *str_uin; - - str_uin = g_strdup_printf("%lu", (unsigned long int)uin); - - buddy = gaim_find_buddy(gaim_connection_get_account(gc), str_uin); - if (buddy != NULL) { - g_free(str_uin); - return g_strdup(gaim_buddy_get_alias(buddy)); - } else { - return str_uin; - } -} -/* }}} */ - - -/* vim: set ts=8 sts=0 sw=8 noet: */ diff -r 880c956dd031 -r fa7313d125ac src/protocols/gg/utils.h --- a/src/protocols/gg/utils.h Tue Apr 11 21:07:58 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/** - * @file utils.h - * - * gaim - * - * Copyright (C) 2005 Bartosz Oler - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _GAIM_GG_UTILS_H -#define _GAIM_GG_UTILS_H - -#include "internal.h" - -#include "plugin.h" -#include "version.h" -#include "notify.h" -#include "status.h" -#include "blist.h" -#include "accountopt.h" -#include "debug.h" -#include "util.h" -#include "request.h" - -#include "gg.h" - - -/* - * Convert a base 10 string to a UIN. - * - * @param str The string to convert - * @return UIN or 0 if an error occurred. - */ -uin_t -ggp_str_to_uin(const char *str); - -/** - * Convert enconding of a given string. - * - * @param locstr Input string. - * @param encsrc Current encoding of the string. - * @param encdst Target encoding of the string. - * - * @return Converted string (it must be g_free()ed when not used. Or NULL if - * locstr is NULL. - */ -char * -charset_convert(const gchar *locstr, const char *encsrc, const char *encdst); - -/** - * Get UIN of a given account. - * - * @param account Current account. - * - * @return UIN of an account. - */ -uin_t -ggp_get_uin(GaimAccount *account); - -/** - * Returns the best name of a buddy from the buddylist. - * - * @param gc GaimConnection instance. - * @param uin UIN of the buddy. - * - * @return Name of the buddy, or UIN converted to string. - */ -char * -ggp_buddy_get_name(GaimConnection *gc, const uin_t uin); - -#endif /* _GAIM_GG_UTILS_H */ - -/* vim: set ts=8 sts=0 sw=8 noet: */