comparison libpurple/protocols/oscar/oscar.c @ 30406:f18b6eb0ed02

Cleanup, basically. Move the icbm snac error handling from oscar.c to family_icbm.c so we don't have to bother we va_args. This is simpler, and gives us the benefit of type checking by the compiler, which will help avoid the crash bug we encountered.
author Mark Doliner <mark@kingant.net>
date Thu, 20 May 2010 02:44:00 +0000
parents 859bb4ab3efe
children 9623db527d1e 17d5518c5cad
comparison
equal deleted inserted replaced
30405:c1b8e619f1b8 30406:f18b6eb0ed02
126 PurpleConnection *gc; 126 PurpleConnection *gc;
127 gchar *name; 127 gchar *name;
128 gchar *nick; 128 gchar *nick;
129 }; 129 };
130 130
131 static const char * const msgerrreason[] = {
132 N_("Invalid error"),
133 N_("Invalid SNAC"),
134 N_("Rate to host"),
135 N_("Rate to client"),
136 N_("Not logged in"),
137 N_("Service unavailable"),
138 N_("Service not defined"),
139 N_("Obsolete SNAC"),
140 N_("Not supported by host"),
141 N_("Not supported by client"),
142 N_("Refused by client"),
143 N_("Reply too big"),
144 N_("Responses lost"),
145 N_("Request denied"),
146 N_("Busted SNAC payload"),
147 N_("Insufficient rights"),
148 N_("In local permit/deny"),
149 N_("Warning level too high (sender)"),
150 N_("Warning level too high (receiver)"),
151 N_("User temporarily unavailable"),
152 N_("No match"),
153 N_("List overflow"),
154 N_("Request ambiguous"),
155 N_("Queue full"),
156 N_("Not while on AOL")
157 };
158 static const int msgerrreasonlen = G_N_ELEMENTS(msgerrreason);
159
160 static const char * const errcodereason[] = {
161 N_("Invalid error"),
162 N_("Not logged in"),
163 N_("Cannot receive IM due to parental controls"),
164 N_("Cannot send SMS without accepting terms"),
165 N_("Cannot send SMS"), /* SMS_WITHOUT_DISCLAIMER is weird */
166 N_("Cannot send SMS to this country"),
167 N_("Unknown error"), /* Undocumented */
168 N_("Unknown error"), /* Undocumented */
169 N_("Cannot send SMS to unknown country"),
170 N_("Bot accounts cannot initiate IMs"),
171 N_("Bot account cannot IM this user"),
172 N_("Bot account reached IM limit"),
173 N_("Bot account reached daily IM limit"),
174 N_("Bot account reached monthly IM limit"),
175 N_("Unable to receive offline messages"),
176 N_("Offline message store full")
177 };
178 static const int errcodereasonlen = G_N_ELEMENTS(errcodereason);
179
180 /* All the libfaim->purple callback functions */ 131 /* All the libfaim->purple callback functions */
181 132
182 /* Only used when connecting with the old-style BUCP login */ 133 /* Only used when connecting with the old-style BUCP login */
183 static int purple_parse_auth_resp (OscarData *, FlapConnection *, FlapFrame *, ...); 134 static int purple_parse_auth_resp (OscarData *, FlapConnection *, FlapFrame *, ...);
184 static int purple_parse_login (OscarData *, FlapConnection *, FlapFrame *, ...); 135 static int purple_parse_login (OscarData *, FlapConnection *, FlapFrame *, ...);
205 static int purple_parse_evilnotify (OscarData *, FlapConnection *, FlapFrame *, ...); 156 static int purple_parse_evilnotify (OscarData *, FlapConnection *, FlapFrame *, ...);
206 static int purple_parse_searcherror(OscarData *, FlapConnection *, FlapFrame *, ...); 157 static int purple_parse_searcherror(OscarData *, FlapConnection *, FlapFrame *, ...);
207 static int purple_parse_searchreply(OscarData *, FlapConnection *, FlapFrame *, ...); 158 static int purple_parse_searchreply(OscarData *, FlapConnection *, FlapFrame *, ...);
208 static int purple_bosrights (OscarData *, FlapConnection *, FlapFrame *, ...); 159 static int purple_bosrights (OscarData *, FlapConnection *, FlapFrame *, ...);
209 static int purple_connerr (OscarData *, FlapConnection *, FlapFrame *, ...); 160 static int purple_connerr (OscarData *, FlapConnection *, FlapFrame *, ...);
210 static int purple_parse_msgerr (OscarData *, FlapConnection *, FlapFrame *, ...);
211 static int purple_parse_mtn (OscarData *, FlapConnection *, FlapFrame *, ...); 161 static int purple_parse_mtn (OscarData *, FlapConnection *, FlapFrame *, ...);
212 static int purple_parse_locaterights(OscarData *, FlapConnection *, FlapFrame *, ...); 162 static int purple_parse_locaterights(OscarData *, FlapConnection *, FlapFrame *, ...);
213 static int purple_parse_buddyrights(OscarData *, FlapConnection *, FlapFrame *, ...); 163 static int purple_parse_buddyrights(OscarData *, FlapConnection *, FlapFrame *, ...);
214 static int purple_parse_locerr (OscarData *, FlapConnection *, FlapFrame *, ...); 164 static int purple_parse_locerr (OscarData *, FlapConnection *, FlapFrame *, ...);
215 static int purple_parse_genericerr (OscarData *, FlapConnection *, FlapFrame *, ...); 165 static int purple_parse_genericerr (OscarData *, FlapConnection *, FlapFrame *, ...);
1543 oscar_data_addhandler(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_RECVAUTHREP, purple_ssi_authreply, 0); 1493 oscar_data_addhandler(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_RECVAUTHREP, purple_ssi_authreply, 0);
1544 oscar_data_addhandler(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_ADDED, purple_ssi_gotadded, 0); 1494 oscar_data_addhandler(od, SNAC_FAMILY_FEEDBAG, SNAC_SUBTYPE_FEEDBAG_ADDED, purple_ssi_gotadded, 0);
1545 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_INCOMING, purple_parse_incoming_im, 0); 1495 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_INCOMING, purple_parse_incoming_im, 0);
1546 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_MISSEDCALL, purple_parse_misses, 0); 1496 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_MISSEDCALL, purple_parse_misses, 0);
1547 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_CLIENTAUTORESP, purple_parse_clientauto, 0); 1497 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_CLIENTAUTORESP, purple_parse_clientauto, 0);
1548 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_ERROR, purple_parse_msgerr, 0);
1549 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_MTN, purple_parse_mtn, 0); 1498 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_MTN, purple_parse_mtn, 0);
1550 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_ACK, purple_parse_msgack, 0); 1499 oscar_data_addhandler(od, SNAC_FAMILY_ICBM, SNAC_SUBTYPE_ICBM_ACK, purple_parse_msgack, 0);
1551 #ifdef OLDSTYLE_ICQ_OFFLINEMSGS 1500 #ifdef OLDSTYLE_ICQ_OFFLINEMSGS
1552 oscar_data_addhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_OFFLINEMSG, purple_offlinemsg, 0); 1501 oscar_data_addhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_OFFLINEMSG, purple_offlinemsg, 0);
1553 oscar_data_addhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_OFFLINEMSGCOMPLETE, purple_offlinemsgdone, 0); 1502 oscar_data_addhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_OFFLINEMSGCOMPLETE, purple_offlinemsgdone, 0);
3369 3318
3370 va_start(ap, fr); 3319 va_start(ap, fr);
3371 reason = (guint16) va_arg(ap, unsigned int); 3320 reason = (guint16) va_arg(ap, unsigned int);
3372 va_end(ap); 3321 va_end(ap);
3373 3322
3374 purple_debug_error("oscar", 3323 purple_debug_error("oscar", "snac threw error (reason 0x%04hx: %s)\n",
3375 "snac threw error (reason 0x%04hx: %s)\n", reason, 3324 reason, oscar_get_msgerr_reason(reason));
3376 (reason < msgerrreasonlen) ? msgerrreason[reason] : "unknown");
3377 return 1;
3378 }
3379
3380 static int purple_parse_msgerr(OscarData *od, FlapConnection *conn, FlapFrame *fr, ...) {
3381 PurpleConnection *gc = od->gc;
3382 #ifdef TODOFT
3383 OscarData *od = purple_connection_get_protocol_data(gc);
3384 PurpleXfer *xfer;
3385 #endif
3386 va_list ap;
3387 guint16 reason, errcode;
3388 char *data, *reason_str, *buf;
3389
3390 va_start(ap, fr);
3391 reason = (guint16)va_arg(ap, unsigned int);
3392 errcode = (guint16)va_arg(ap, unsigned int);
3393 data = va_arg(ap, char *);
3394 va_end(ap);
3395
3396 purple_debug_error("oscar",
3397 "Message error with data %s and reason %hu and errcode %hu\n",
3398 (data != NULL ? data : ""), reason, errcode);
3399
3400 if ((data == NULL) || (*data == '\0'))
3401 /* We can't do anything if data is empty */
3402 return 1;
3403
3404 #ifdef TODOFT
3405 /* If this was a file transfer request, data is a cookie */
3406 if ((xfer = oscar_find_xfer_by_cookie(od->file_transfers, data))) {
3407 purple_xfer_cancel_remote(xfer);
3408 return 1;
3409 }
3410 #endif
3411
3412 /* Data is assumed to be the destination bn */
3413
3414 reason_str = g_strdup((reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Unknown reason"));
3415 if (errcode != 0 && errcode < errcodereasonlen)
3416 buf = g_strdup_printf(_("Unable to send message: %s (%s)"), reason_str,
3417 _(errcodereason[errcode]));
3418 else
3419 buf = g_strdup_printf(_("Unable to send message: %s"), reason_str);
3420
3421 if (!purple_conv_present_error(data, purple_connection_get_account(gc), buf)) {
3422 g_free(buf);
3423 if (errcode != 0 && errcode < errcodereasonlen)
3424 buf = g_strdup_printf(_("Unable to send message to %s: %s (%s)"),
3425 data ? data : "(unknown)", reason_str,
3426 _(errcodereason[errcode]));
3427 else
3428 buf = g_strdup_printf(_("Unable to send message to %s: %s"),
3429 data ? data : "(unknown)", reason_str);
3430 purple_notify_error(od->gc, NULL, buf, reason_str);
3431 }
3432 g_free(buf);
3433 g_free(reason_str);
3434
3435 return 1; 3325 return 1;
3436 } 3326 }
3437 3327
3438 static int purple_parse_mtn(OscarData *od, FlapConnection *conn, FlapFrame *fr, ...) { 3328 static int purple_parse_mtn(OscarData *od, FlapConnection *conn, FlapFrame *fr, ...) {
3439 PurpleConnection *gc = od->gc; 3329 PurpleConnection *gc = od->gc;
3492 3382
3493 if (destn == NULL) 3383 if (destn == NULL)
3494 return 1; 3384 return 1;
3495 3385
3496 user_info = purple_notify_user_info_new(); 3386 user_info = purple_notify_user_info_new();
3497 buf = g_strdup_printf(_("User information not available: %s"), (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Unknown reason.")); 3387 buf = g_strdup_printf(_("User information not available: %s"), oscar_get_msgerr_reason(reason));
3498 purple_notify_user_info_add_pair(user_info, NULL, buf); 3388 purple_notify_user_info_add_pair(user_info, NULL, buf);
3499 purple_notify_userinfo(od->gc, destn, user_info, NULL, NULL); 3389 purple_notify_userinfo(od->gc, destn, user_info, NULL, NULL);
3500 purple_notify_user_info_destroy(user_info); 3390 purple_notify_user_info_destroy(user_info);
3501 purple_conv_present_error(destn, purple_connection_get_account(od->gc), buf); 3391 purple_conv_present_error(destn, purple_connection_get_account(od->gc), buf);
3502 g_free(buf); 3392 g_free(buf);