src/protocols/zephyr/zephyr.c

changeset 10867
b39f9b646d6c
parent 10751
e15f4f5927ce
child 11033
dc68e074f10d
equal deleted inserted replaced
10866:40eab743e22b 10867:b39f9b646d6c
141 #define z_call_s(func, err) if (func != ZERR_NONE) {\ 141 #define z_call_s(func, err) if (func != ZERR_NONE) {\
142 gaim_connection_error(gc, err);\ 142 gaim_connection_error(gc, err);\
143 return;\ 143 return;\
144 } 144 }
145 145
146 #ifdef WIN32
147 extern const char *username;
148 #endif
146 149
147 Code_t zephyr_subscribe_to(zephyr_account* zephyr, char* class, char *instance, char *recipient, char* galaxy) { 150 Code_t zephyr_subscribe_to(zephyr_account* zephyr, char* class, char *instance, char *recipient, char* galaxy) {
148 151
149 if (use_tzc(zephyr)) { 152 if (use_tzc(zephyr)) {
150 /* ((tzcfodder . subscribe) ("class" "instance" "recipient")) */ 153 /* ((tzcfodder . subscribe) ("class" "instance" "recipient")) */
201 * wouldn't do this. but it is so i will. */ 204 * wouldn't do this. but it is so i will. */
202 205
203 /* just for debugging */ 206 /* just for debugging */
204 static void handle_unknown(ZNotice_t notice) 207 static void handle_unknown(ZNotice_t notice)
205 { 208 {
206 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_packet: %s\n", notice.z_packet); 209 gaim_debug_error("zephyr","z_packet: %s\n", notice.z_packet);
207 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_version: %s\n", notice.z_version); 210 gaim_debug_error("zephyr","z_version: %s\n", notice.z_version);
208 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_kind: %d\n", (int)(notice.z_kind)); 211 gaim_debug_error("zephyr","z_kind: %d\n", (int)(notice.z_kind));
209 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class: %s\n", notice.z_class); 212 gaim_debug_error("zephyr","z_class: %s\n", notice.z_class);
210 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class_inst: %s\n", notice.z_class_inst); 213 gaim_debug_error("zephyr","z_class_inst: %s\n", notice.z_class_inst);
211 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_opcode: %s\n", notice.z_opcode); 214 gaim_debug_error("zephyr","z_opcode: %s\n", notice.z_opcode);
212 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_sender: %s\n", notice.z_sender); 215 gaim_debug_error("zephyr","z_sender: %s\n", notice.z_sender);
213 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_recipient: %s\n", notice.z_recipient); 216 gaim_debug_error("zephyr","z_recipient: %s\n", notice.z_recipient);
214 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message: %s\n", notice.z_message); 217 gaim_debug_error("zephyr","z_message: %s\n", notice.z_message);
215 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message_len: %d\n", notice.z_message_len); 218 gaim_debug_error("zephyr","z_message_len: %d\n", notice.z_message_len);
216 } 219 }
217 220
218 221
219 static zephyr_triple *new_triple(zephyr_account *zephyr,const char *c, const char *i, const char *r) 222 static zephyr_triple *new_triple(zephyr_account *zephyr,const char *c, const char *i, const char *r)
220 { 223 {
323 if (g_utf8_validate(string, len, NULL)) { 326 if (g_utf8_validate(string, len, NULL)) {
324 return g_strdup(string); 327 return g_strdup(string);
325 } else { 328 } else {
326 utf8 = g_convert(string, len, "UTF-8", zephyr->encoding, NULL, NULL, &err); 329 utf8 = g_convert(string, len, "UTF-8", zephyr->encoding, NULL, NULL, &err);
327 if (err) { 330 if (err) {
328 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "recv conversion error: %s\n", err->message); 331 gaim_debug_error("zephyr", "recv conversion error: %s\n", err->message);
329 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); 332 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)"));
330 g_error_free(err); 333 g_error_free(err);
331 } 334 }
332 335
333 return utf8; 336 return utf8;
844 Realm from the sender field */ 847 Realm from the sender field */
845 sendertmp = zephyr_strip_local_realm(zephyr,notice.z_sender); 848 sendertmp = zephyr_strip_local_realm(zephyr,notice.z_sender);
846 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); 849 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst);
847 send_inst_utf8 = zephyr_recv_convert(gc,send_inst, strlen(send_inst)); 850 send_inst_utf8 = zephyr_recv_convert(gc,send_inst, strlen(send_inst));
848 if (!send_inst_utf8) { 851 if (!send_inst_utf8) {
849 gaim_debug(GAIM_DEBUG_ERROR, "zephyr","send_inst %s became null\n", send_inst); 852 gaim_debug_error("zephyr","send_inst %s became null\n", send_inst);
850 send_inst_utf8 = "malformed instance"; 853 send_inst_utf8 = "malformed instance";
851 } 854 }
852 855
853 serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL)); 856 serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL));
854 g_free(send_inst); 857 g_free(send_inst);
1194 } 1197 }
1195 1198
1196 return TRUE; 1199 return TRUE;
1197 } 1200 }
1198 1201
1202 #ifdef WIN32
1203
1204 static gint check_loc(gpointer_data)
1205 {
1206 GaimBlistNode *gnode, *cnode, *bnode;
1207 ZLocations_t locations;
1208 int numlocs;
1209 int one = 1;
1210
1211 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) {
1212 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
1213 continue;
1214 for (cnode = gnode->child; cnode; cnode = cnode->next) {
1215 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
1216 continue;
1217 for (bnode = cnode->child; bnode; bnode = bnode->next) {
1218 GaimBuddy *b = (GaimBuddy *) bnode;
1219
1220 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
1221 continue;
1222 if (b->account->gc == zgc) {
1223 char *chk;
1224 chk = local_zephyr_normalize(b->name);
1225 ZLocateUser(chk,&numlocs, ZAUTH);
1226 if (numlocs) {
1227 int i;
1228 for(i=0;i<numlocs;i++) {
1229 ZGetLocations(&locations,&one);
1230 serv_got_update(zgc,b->name,1,0,0,0,0);
1231 }
1232 }
1233 }
1234 }
1235 }
1236 }
1237 return TRUE;
1238 }
1239
1240 #else
1241
1199 static gint check_loc(gpointer data) 1242 static gint check_loc(gpointer data)
1200 { 1243 {
1201 GaimBlistNode *gnode, *cnode, *bnode; 1244 GaimBlistNode *gnode, *cnode, *bnode;
1202 ZAsyncLocateData_t ald; 1245 ZAsyncLocateData_t ald;
1203 GaimConnection *gc = (GaimConnection *)data; 1246 GaimConnection *gc = (GaimConnection *)data;
1259 } 1302 }
1260 1303
1261 return TRUE; 1304 return TRUE;
1262 } 1305 }
1263 1306
1307 #endif /* WIN32 */
1308
1264 static char *get_exposure_level() 1309 static char *get_exposure_level()
1265 { 1310 {
1266 /* XXX add real error reporting */ 1311 /* XXX add real error reporting */
1267 char *exposure = ZGetVariable("exposure"); 1312 char *exposure = ZGetVariable("exposure");
1268 1313
1295 { 1340 {
1296 /* XXX This code may not be Win32 clean */ 1341 /* XXX This code may not be Win32 clean */
1297 struct hostent *hent; 1342 struct hostent *hent;
1298 1343
1299 if (gethostname(zephyr->ourhost, sizeof(zephyr->ourhost)) == -1) { 1344 if (gethostname(zephyr->ourhost, sizeof(zephyr->ourhost)) == -1) {
1300 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "unable to retrieve hostname, %%host%% and %%canon%% will be wrong in subscriptions and have been set to unknown\n"); 1345 gaim_debug_error("zephyr", "unable to retrieve hostname, %%host%% and %%canon%% will be wrong in subscriptions and have been set to unknown\n");
1301 g_strlcpy(zephyr->ourhost, "unknown", sizeof(zephyr->ourhost)); 1346 g_strlcpy(zephyr->ourhost, "unknown", sizeof(zephyr->ourhost));
1302 g_strlcpy(zephyr->ourhostcanon, "unknown", sizeof(zephyr->ourhostcanon)); 1347 g_strlcpy(zephyr->ourhostcanon, "unknown", sizeof(zephyr->ourhostcanon));
1303 return; 1348 return;
1304 } 1349 }
1305 1350
1306 if (!(hent = gethostbyname(zephyr->ourhost))) { 1351 if (!(hent = gethostbyname(zephyr->ourhost))) {
1307 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "unable to resolve hostname, %%canon%% will be wrong in subscriptions.and has been set to the value of %%host%%, %s\n",zephyr->ourhost); 1352 gaim_debug_error("zephyr", "unable to resolve hostname, %%canon%% will be wrong in subscriptions.and has been set to the value of %%host%%, %s\n",zephyr->ourhost);
1308 g_strlcpy(zephyr->ourhostcanon, zephyr->ourhost, sizeof(zephyr->ourhostcanon)); 1353 g_strlcpy(zephyr->ourhostcanon, zephyr->ourhost, sizeof(zephyr->ourhostcanon));
1309 return; 1354 return;
1310 } 1355 }
1311 1356
1312 g_strlcpy(zephyr->ourhostcanon, hent->h_name, sizeof(zephyr->ourhostcanon)); 1357 g_strlcpy(zephyr->ourhostcanon, hent->h_name, sizeof(zephyr->ourhostcanon));
1393 /* There should be some sort of error report listing classes that couldn't be subbed to. 1438 /* There should be some sort of error report listing classes that couldn't be subbed to.
1394 Not important right now though */ 1439 Not important right now though */
1395 1440
1396 if (zephyr_subscribe_to(zephyr,z_class, z_instance, recip,z_galaxy) != ZERR_NONE) { 1441 if (zephyr_subscribe_to(zephyr,z_class, z_instance, recip,z_galaxy) != ZERR_NONE) {
1397 1442
1398 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "Couldn't subscribe to %s, %s, %s\n", z_class,z_instance,recip); 1443 gaim_debug_error("zephyr", "Couldn't subscribe to %s, %s, %s\n", z_class,z_instance,recip);
1399 } 1444 }
1400 1445
1401 zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,z_class,z_instance,recip)); 1446 zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,z_class,z_instance,recip));
1402 /* g_hash_table_destroy(sub_hash_table); */ 1447 /* g_hash_table_destroy(sub_hash_table); */
1403 g_free(z_instance); 1448 g_free(z_instance);
1472 gc = gaim_account_get_connection(account); 1517 gc = gaim_account_get_connection(account);
1473 read_anyone = gaim_account_get_bool(gc->account,"read_anyone",TRUE); 1518 read_anyone = gaim_account_get_bool(gc->account,"read_anyone",TRUE);
1474 read_zsubs = gaim_account_get_bool(gc->account,"read_zsubs",TRUE); 1519 read_zsubs = gaim_account_get_bool(gc->account,"read_zsubs",TRUE);
1475 exposure = (gchar *)gaim_account_get_string(gc->account, "exposure_level", EXPOSE_REALMVIS); 1520 exposure = (gchar *)gaim_account_get_string(gc->account, "exposure_level", EXPOSE_REALMVIS);
1476 1521
1522 #ifdef WIN32
1523 username = gaim_account_get_username(account);
1524 #endif
1477 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC; 1525 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC;
1478 gc->proto_data = zephyr=g_new0(zephyr_account,1); 1526 gc->proto_data = zephyr=g_new0(zephyr_account,1);
1479 1527
1480 zephyr->account = account; 1528 zephyr->account = account;
1481 1529
2103 } 2151 }
2104 2152
2105 static const char *zephyr_normalize(const GaimAccount * account, const char *orig) 2153 static const char *zephyr_normalize(const GaimAccount * account, const char *orig)
2106 { 2154 {
2107 /* returns the string you gave it. Maybe this function shouldn't be here */ 2155 /* returns the string you gave it. Maybe this function shouldn't be here */
2108 char * buf = g_malloc0(80); 2156 static char buf[80];
2109 /* gaim_debug_error("zephyr","entering zephyr_normalize\n"); */ 2157 /* gaim_debug_error("zephyr","entering zephyr_normalize\n"); */
2110 2158
2111 if (!g_ascii_strcasecmp(orig, "")) { 2159 if (!g_ascii_strcasecmp(orig, "")) {
2112 buf[0] = '\0'; 2160 buf[0] = '\0';
2113 return buf; 2161 return buf;
2689 GString* subout = g_string_new("Subscription list<br>"); 2737 GString* subout = g_string_new("Subscription list<br>");
2690 2738
2691 title = g_strdup_printf("Server subscriptions for %s", zephyr->username); 2739 title = g_strdup_printf("Server subscriptions for %s", zephyr->username);
2692 2740
2693 if (zephyr->port == 0) { 2741 if (zephyr->port == 0) {
2694 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving port"); 2742 gaim_debug_error("zephyr", "error while retrieving port");
2695 return; 2743 return;
2696 } 2744 }
2697 if ((retval = ZRetrieveSubscriptions(zephyr->port,&nsubs)) != ZERR_NONE) { 2745 if ((retval = ZRetrieveSubscriptions(zephyr->port,&nsubs)) != ZERR_NONE) {
2698 /* XXX better error handling */ 2746 /* XXX better error handling */
2699 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving subscriptions from server"); 2747 gaim_debug_error("zephyr", "error while retrieving subscriptions from server");
2700 return; 2748 return;
2701 } 2749 }
2702 for(i=0;i<nsubs;i++) { 2750 for(i=0;i<nsubs;i++) {
2703 one = 1; 2751 one = 1;
2704 if ((retval = ZGetSubscriptions(&subs,&one)) != ZERR_NONE) { 2752 if ((retval = ZGetSubscriptions(&subs,&one)) != ZERR_NONE) {
2705 /* XXX better error handling */ 2753 /* XXX better error handling */
2706 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving individual subscription"); 2754 gaim_debug_error("zephyr", "error while retrieving individual subscription");
2707 return; 2755 return;
2708 } 2756 }
2709 g_string_append_printf(subout, "Class %s Instance %s Recipient %s<br>", 2757 g_string_append_printf(subout, "Class %s Instance %s Recipient %s<br>",
2710 subs.zsub_class, subs.zsub_classinst, 2758 subs.zsub_class, subs.zsub_classinst,
2711 subs.zsub_recipient); 2759 subs.zsub_recipient);

mercurial