comparison libpurple/protocols/oscar/family_icbm.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 c1b8e619f1b8
children 9623db527d1e d24c975c68a5 879baaf87aa2
comparison
equal deleted inserted replaced
30405:c1b8e619f1b8 30406:f18b6eb0ed02
51 #include "win32dep.h" 51 #include "win32dep.h"
52 #endif 52 #endif
53 53
54 #include "util.h" 54 #include "util.h"
55 55
56 static const char * const errcodereason[] = {
57 N_("Invalid error"),
58 N_("Not logged in"),
59 N_("Cannot receive IM due to parental controls"),
60 N_("Cannot send SMS without accepting terms"),
61 N_("Cannot send SMS"), /* SMS_WITHOUT_DISCLAIMER is weird */
62 N_("Cannot send SMS to this country"),
63 N_("Unknown error"), /* Undocumented */
64 N_("Unknown error"), /* Undocumented */
65 N_("Cannot send SMS to unknown country"),
66 N_("Bot accounts cannot initiate IMs"),
67 N_("Bot account cannot IM this user"),
68 N_("Bot account reached IM limit"),
69 N_("Bot account reached daily IM limit"),
70 N_("Bot account reached monthly IM limit"),
71 N_("Unable to receive offline messages"),
72 N_("Offline message store full")
73 };
74 static const int errcodereasonlen = G_N_ELEMENTS(errcodereason);
56 75
57 /** 76 /**
58 * Add a standard ICBM header to the given bstream with the given 77 * Add a standard ICBM header to the given bstream with the given
59 * information. 78 * information.
60 * 79 *
155 * Subtype 0x0001 - Error 174 * Subtype 0x0001 - Error
156 */ 175 */
157 static int 176 static int
158 error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) 177 error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
159 { 178 {
160 int ret = 0;
161 aim_rxcallback_t userfunc;
162 aim_snac_t *snac2; 179 aim_snac_t *snac2;
163 guint16 reason, errcode = 0; 180 guint16 reason, errcode = 0;
164 char *bn; 181 const char *bn;
165 GSList *tlvlist; 182 GSList *tlvlist;
166 183 PurpleConnection *gc = od->gc;
167 if (!(snac2 = aim_remsnac(od, snac->id))) { 184 #ifdef TODOFT
185 PurpleXfer *xfer;
186 #endif
187 const char *reason_str;
188 char *buf;
189
190 snac2 = aim_remsnac(od, snac->id);
191 if (!snac2) {
168 purple_debug_misc("oscar", "icbm error: received response from unknown request!\n"); 192 purple_debug_misc("oscar", "icbm error: received response from unknown request!\n");
169 return 1; 193 return 1;
170 } 194 }
171 195
172 if (snac2->family != SNAC_FAMILY_ICBM) { 196 if (snac2->family != SNAC_FAMILY_ICBM) {
174 g_free(snac2->data); 198 g_free(snac2->data);
175 g_free(snac2); 199 g_free(snac2);
176 return 1; 200 return 1;
177 } 201 }
178 202
179 if (!(bn = snac2->data)) { 203 /* Data is assumed to be the destination bn */
204 bn = snac2->data;
205 if (!bn || bn[0] == '\0') {
180 purple_debug_misc("oscar", "icbm error: received response from request without a buddy name!\n"); 206 purple_debug_misc("oscar", "icbm error: received response from request without a buddy name!\n");
207 g_free(snac2->data);
181 g_free(snac2); 208 g_free(snac2);
182 return 1; 209 return 1;
183 } 210 }
184 211
185 reason = byte_stream_get16(bs); 212 reason = byte_stream_get16(bs);
187 tlvlist = aim_tlvlist_read(bs); 214 tlvlist = aim_tlvlist_read(bs);
188 if (aim_tlv_gettlv(tlvlist, 0x0008, 1)) 215 if (aim_tlv_gettlv(tlvlist, 0x0008, 1))
189 errcode = aim_tlv_get16(tlvlist, 0x0008, 1); 216 errcode = aim_tlv_get16(tlvlist, 0x0008, 1);
190 aim_tlvlist_free(tlvlist); 217 aim_tlvlist_free(tlvlist);
191 218
219 purple_debug_error("oscar",
220 "Message error with bn %s and reason %hu and errcode %hu\n",
221 (bn != NULL ? bn : ""), reason, errcode);
222
223 #ifdef TODOFT
224 /* If this was a file transfer request, bn is a cookie */
225 if ((xfer = oscar_find_xfer_by_cookie(od->file_transfers, bn))) {
226 purple_xfer_cancel_remote(xfer);
227 return 1;
228 }
229 #endif
230
192 /* Notify the user that the message wasn't delivered */ 231 /* Notify the user that the message wasn't delivered */
193 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) 232 reason_str = oscar_get_msgerr_reason(reason);
194 ret = userfunc(od, conn, frame, reason, errcode, bn); 233 if (errcode != 0 && errcode < errcodereasonlen)
195 234 buf = g_strdup_printf(_("Unable to send message: %s (%s)"), reason_str,
196 if (snac2) { 235 _(errcodereason[errcode]));
197 g_free(snac2->data); 236 else
198 g_free(snac2); 237 buf = g_strdup_printf(_("Unable to send message: %s"), reason_str);
199 } 238
200 239 if (!purple_conv_present_error(bn, purple_connection_get_account(gc), buf)) {
201 return ret; 240 g_free(buf);
241 if (errcode != 0 && errcode < errcodereasonlen)
242 buf = g_strdup_printf(_("Unable to send message to %s: %s (%s)"),
243 bn ? bn : "(unknown)", reason_str,
244 _(errcodereason[errcode]));
245 else
246 buf = g_strdup_printf(_("Unable to send message to %s: %s"),
247 bn ? bn : "(unknown)", reason_str);
248 purple_notify_error(od->gc, NULL, buf, reason_str);
249 }
250 g_free(buf);
251
252
253
254
255 g_free(snac2->data);
256 g_free(snac2);
257
258 return 1;
202 } 259 }
203 260
204 /** 261 /**
205 * Subtype 0x0002 - Set ICBM parameters. 262 * Subtype 0x0002 - Set ICBM parameters.
206 * 263 *