comparison src/protocols/gg/gg.c @ 4051:a5c49e9c6a53

[gaim-migrate @ 4261] (18:27:24) Paco-Paco: The new gaim prpl semantics dictate that gaim<=>prpl communication is always done in UTF-8. This patch brings gadu-gadu up-to-date with respect to this practice. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 08 Dec 2002 23:29:45 +0000
parents 988485669631
children c3968c878c68
comparison
equal deleted inserted replaced
4050:9438d2e96cb1 4051:a5c49e9c6a53
1 /* 1 /*
2 * gaim - Gadu-Gadu Protocol Plugin 2 * gaim - Gadu-Gadu Protocol Plugin
3 * $Id: gg.c 3850 2002-10-16 19:57:03Z hermanator $ 3 * $Id: gg.c 4261 2002-12-08 23:29:45Z lschiere $
4 * 4 *
5 * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL> 5 * Copyright (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
40 #include <stdlib.h> 40 #include <stdlib.h>
41 #include <stdio.h> 41 #include <stdio.h>
42 #include <time.h> 42 #include <time.h>
43 #include <sys/stat.h> 43 #include <sys/stat.h>
44 #include <ctype.h> 44 #include <ctype.h>
45 #ifdef HAVE_LANGINFO_CODESET
46 #include <langinfo.h>
47 #endif
48 #ifdef HAVE_ICONV
49 #include <iconv.h>
50 #include "iconv_string.h"
51 #endif
52 /* Library from EKG (Eksperymentalny Klient Gadu-Gadu) */ 45 /* Library from EKG (Eksperymentalny Klient Gadu-Gadu) */
53 #include "libgg.h" 46 #include "libgg.h"
54 #include "multi.h" 47 #include "multi.h"
55 #include "prpl.h" 48 #include "prpl.h"
56 #include "gaim.h" 49 #include "gaim.h"
113 }; 106 };
114 107
115 108
116 static gchar *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst) 109 static gchar *charset_convert(const gchar *locstr, const char *encsrc, const char *encdst)
117 { 110 {
118 #ifdef HAVE_ICONV 111 return (g_convert (locstr, strlen (locstr), encdst, encsrc, NULL, NULL, NULL));
119 gchar *result = NULL;
120 if (iconv_string(encdst, encsrc, locstr, locstr + strlen(locstr) + 1, &result, NULL) >= 0)
121 return result;
122 #endif
123 return g_strdup(locstr);
124 } 112 }
125 113
126 static gboolean invalid_uin(const char *uin) 114 static gboolean invalid_uin(const char *uin)
127 { 115 {
128 unsigned long int res = strtol(uin, (char **)NULL, 10); 116 unsigned long int res = strtol(uin, (char **)NULL, 10);
164 break; 152 break;
165 default: 153 default:
166 return TRUE; 154 return TRUE;
167 break; 155 break;
168 } 156 }
169 }
170
171 static const gchar *find_local_charset(void)
172 {
173 const gchar *gg_localenc = g_getenv("GG_CHARSET");
174
175 if (gg_localenc == NULL) {
176 #ifdef HAVE_LANGINFO_CODESET
177 gg_localenc = nl_langinfo(CODESET);
178 #else
179 gg_localenc = "US-ASCII";
180 #endif
181 }
182 return gg_localenc;
183 } 157 }
184 158
185 static char *handle_errcode(struct gaim_connection *gc, int errcode) 159 static char *handle_errcode(struct gaim_connection *gc, int errcode)
186 { 160 {
187 static char msg[AGG_BUF_LEN]; 161 static char msg[AGG_BUF_LEN];
360 gchar user[20]; 334 gchar user[20];
361 335
362 g_snprintf(user, sizeof(user), "%lu", e->event.msg.sender); 336 g_snprintf(user, sizeof(user), "%lu", e->event.msg.sender);
363 if (!allowed_uin(gc, user)) 337 if (!allowed_uin(gc, user))
364 break; 338 break;
365 imsg = charset_convert(e->event.msg.message, "CP1250", find_local_charset()); 339 imsg = charset_convert(e->event.msg.message, "CP1250", "UTF-8");
366 strip_linefeed(imsg); 340 strip_linefeed(imsg);
367 /* e->event.msg.time - we don't know what this time is for */ 341 /* e->event.msg.time - we don't know what this time is for */
368 serv_got_im(gc, user, imsg, 0, time(NULL), -1); 342 serv_got_im(gc, user, imsg, 0, time(NULL), -1);
369 g_free(imsg); 343 g_free(imsg);
370 } 344 }
628 GAIM_ERROR); 602 GAIM_ERROR);
629 return -1; 603 return -1;
630 } 604 }
631 605
632 if (strlen(msg) > 0) { 606 if (strlen(msg) > 0) {
633 imsg = charset_convert(msg, find_local_charset(), "CP1250"); 607 imsg = charset_convert(msg, "UTF-8", "CP1250");
634 if (gg_send_message(gd->sess, (flags & IM_FLAG_CHECKBOX) 608 if (gg_send_message(gd->sess, (flags & IM_FLAG_CHECKBOX)
635 ? GG_CLASS_MSG : GG_CLASS_CHAT, 609 ? GG_CLASS_MSG : GG_CLASS_CHAT,
636 strtol(who, (char **)NULL, 10), imsg) < 0) 610 strtol(who, (char **)NULL, 10), imsg) < 0)
637 return -1; 611 return -1;
638 g_free(imsg); 612 g_free(imsg);
707 681
708 /* GG_PUBDIR_HOST service returns 7 lines of data per directory entry */ 682 /* GG_PUBDIR_HOST service returns 7 lines of data per directory entry */
709 if (i % 8 == 0) 683 if (i % 8 == 0)
710 j = 0; 684 j = 0;
711 685
712 p = charset_convert(g_strstrip(webdata_tbl[i]), "CP1250", find_local_charset()); 686 p = charset_convert(g_strstrip(webdata_tbl[i]), "CP1250", "UTF-8");
713 687
714 oldibuf = ibuf; 688 oldibuf = ibuf;
715 689
716 switch (j) { 690 switch (j) {
717 case 0: 691 case 0:
1112 if (email && strlen(email)) { 1086 if (email && strlen(email)) {
1113 gchar *eemail = gg_urlencode(email); 1087 gchar *eemail = gg_urlencode(email);
1114 srch->request = g_strdup_printf("Mode=1&Email=%s", eemail); 1088 srch->request = g_strdup_printf("Mode=1&Email=%s", eemail);
1115 g_free(eemail); 1089 g_free(eemail);
1116 } else { 1090 } else {
1117 gchar *new_first = charset_convert(first, find_local_charset(), "CP1250"); 1091 gchar *new_first = charset_convert(first, "UTF-8", "CP1250");
1118 gchar *new_last = charset_convert(last, find_local_charset(), "CP1250"); 1092 gchar *new_last = charset_convert(last, "UTF-8", "CP1250");
1119 gchar *new_city = charset_convert(city, find_local_charset(), "CP1250"); 1093 gchar *new_city = charset_convert(city, "UTF-8", "CP1250");
1120 1094
1121 gchar *enew_first = gg_urlencode(new_first); 1095 gchar *enew_first = gg_urlencode(new_first);
1122 gchar *enew_last = gg_urlencode(new_last); 1096 gchar *enew_last = gg_urlencode(new_last);
1123 gchar *enew_city = gg_urlencode(new_city); 1097 gchar *enew_city = gg_urlencode(new_city);
1124 1098
1218 srch->form = AGG_PUBDIR_SEARCH_FORM; 1192 srch->form = AGG_PUBDIR_SEARCH_FORM;
1219 srch->host = GG_PUBDIR_HOST; 1193 srch->host = GG_PUBDIR_HOST;
1220 1194
1221 /* If it's invalid uin then maybe it's nickname? */ 1195 /* If it's invalid uin then maybe it's nickname? */
1222 if (invalid_uin(who)) { 1196 if (invalid_uin(who)) {
1223 gchar *new_who = charset_convert(who, find_local_charset(), "CP1250"); 1197 gchar *new_who = charset_convert(who, "UTF-8", "CP1250");
1224 gchar *enew_who = gg_urlencode(new_who); 1198 gchar *enew_who = gg_urlencode(new_who);
1225 1199
1226 g_free(new_who); 1200 g_free(new_who);
1227 1201
1228 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d" 1202 srch->request = g_strdup_printf("Mode=0&FirstName=%s&LastName=%s&Gender=%d"