comparison src/protocols/oscar/oscar.c @ 4076:91c4bd698d39

[gaim-migrate @ 4291] I went ape on ICQ's i18n stuff for offline messages/channel 4 messages. I'm pretty sure accented characters and what not should work like a charm, now. Thanks to Mr. McQueen and Mr. Blanton. Also, I changed some stuff with handling these types of messages, so we actually delimit the message at the delimiters. So, uh, hopefully no one will complain about funky "?" symbols in their authorization requests. Stuff to look out for would be authorization requests and replies not working. I still haven't been able to get icqnum@pager.icq.com to work reliably enough to test it. And also, I'd like to take this moment to say that lobsters are really neat. Yeah. Lobsters. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 15 Dec 2002 06:15:27 +0000
parents 2221f6801577
children c5ce82228a2f
comparison
equal deleted inserted replaced
4075:2221f6801577 4076:91c4bd698d39
2012 g_free(message); 2012 g_free(message);
2013 g_free(data); 2013 g_free(data);
2014 } 2014 }
2015 2015
2016 /* 2016 /*
2017 * For when other people ask you for authorization
2018 */
2019 static void gaim_icq_authask(struct gaim_connection *gc, fu32_t uin, char *msg) {
2020 struct channel4_data *data = g_new(struct channel4_data, 1);
2021 /* The first 6 chars of the message are some type of alien gibberish, so skip them */
2022 char *dialog_msg = g_strdup_printf("The user %lu wants to add you to their buddy list for the following reason: %s", uin, (msg && strlen(msg)>6) ? msg+6 : "No reason given.");
2023 debug_printf("Received an authorization request from UIN %lu\n", uin);
2024 data->gc = gc;
2025 data->uin = g_strdup_printf("%lu", uin);
2026 do_ask_dialog(dialog_msg, (msg && strlen(msg) > 6) ? msg+6 : _("No reason given."), data, _("Authorize"), gaim_icq_authgrant, _("Deny"), gaim_icq_authdeny);
2027 g_free(dialog_msg);
2028 }
2029
2030 /*
2031 * Next 2 functions are for when someone sends you contacts 2017 * Next 2 functions are for when someone sends you contacts
2032 */ 2018 */
2033 static void gaim_icq_contactadd(struct channel4_data *data) { 2019 static void gaim_icq_contactadd(struct channel4_data *data) {
2034 show_add_buddy(data->gc, data->uin, NULL, data->nick); 2020 show_add_buddy(data->gc, data->uin, NULL, data->nick);
2035 free(data->uin); 2021 free(data->uin);
2043 g_free(data); 2029 g_free(data);
2044 } 2030 }
2045 2031
2046 static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch4_args *args, time_t t) { 2032 static int incomingim_chan4(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch4_args *args, time_t t) {
2047 struct gaim_connection *gc = sess->aux_data; 2033 struct gaim_connection *gc = sess->aux_data;
2048 2034 gchar **msg1, **msg2;
2049 debug_printf("Received a channel 4 message of type (type 0x%04d).\n", args->type); 2035 GError *err = NULL;
2036 int i;
2037
2038 debug_printf("Received a channel 4 message of type %d.\n", args->type);
2039
2040 /* Split up the message at the delimeter character, then convert each string to UTF-8 */
2041 msg1 = g_strsplit(args->msg, "þ", 0);
2042 msg2 = (gchar **)g_malloc(10*sizeof(gchar *)); /* AAA */
2043 for (i=0; msg1[i]; i++) {
2044 strip_linefeed(msg1[i]);
2045 msg2[i] = g_convert(msg1[i], strlen(msg1[i]), "UTF-8", "ISO-8859-1", NULL, NULL, &err);
2046 if (err)
2047 debug_printf("Error converting a string from ISO-8859-1 to UTF-8 in oscar ICBM channel 4 parsing\n");
2048 }
2049 msg2[i] = NULL;
2050
2050 switch (args->type) { 2051 switch (args->type) {
2051 case 0x0001: { /* MacICQ message or basic offline message */ 2052 case 0x0001: { /* MacICQ message or basic offline message */
2052 gchar *uin, *message; 2053 if (i >= 1) {
2053 uin = g_strdup_printf("%lu", args->uin); 2054 gchar *uin = g_strdup_printf("%lu", args->uin);
2054 message = g_strdup(args->msg); 2055 if (t) { /* This is an offline message */
2055 strip_linefeed(message); 2056 /* I think this timestamp is in UTC, or something */
2056 if (t) { 2057 serv_got_im(gc, uin, msg2[0], 0, t, -1);
2057 /* This is an offline message */ 2058 } else { /* This is a message from MacICQ/Miranda */
2058 /* I think this timestamp is in UTC, or something */ 2059 serv_got_im(gc, uin, msg2[0], 0, time(NULL), -1);
2059 serv_got_im(gc, uin, message, 0, t, -1); 2060 }
2060 } else { 2061 g_free(uin);
2061 /* This is a message from MacICQ/Miranda */ 2062 }
2063 } break;
2064
2065 case 0x0004: { /* Someone sent you a URL */
2066 if (i >= 2) {
2067 gchar *uin = g_strdup_printf("%lu", args->uin);
2068 gchar *message = g_strdup_printf("<A HREF=\"%s\">%s</A>", msg2[1], msg2[0]);
2062 serv_got_im(gc, uin, message, 0, time(NULL), -1); 2069 serv_got_im(gc, uin, message, 0, time(NULL), -1);
2063 }
2064 g_free(uin);
2065 g_free(message);
2066 } break;
2067
2068 case 0x0004: { /* Someone sent you a URL */
2069 gchar **text, *uin, *message;
2070 text = g_strsplit(args->msg, "þ", 2);
2071 if (text) {
2072 uin = g_strdup_printf("%lu", args->uin);
2073 message = g_strdup_printf("<A HREF=\"%s\">%s</A>", text[1], text[0]);
2074 strip_linefeed(message);
2075 serv_got_im(gc, uin, message, 0, time(NULL), -1);
2076 g_strfreev(text);
2077 g_free(uin); 2070 g_free(uin);
2078 g_free(message); 2071 g_free(message);
2079 } 2072 }
2080 } break; 2073 } break;
2081 2074
2082 case 0x0006: { /* Someone requested authorization */ 2075 case 0x0006: { /* Someone requested authorization */
2083 gaim_icq_authask(gc, args->uin, args->msg); 2076 if (i >= 6) {
2077 struct channel4_data *data = g_new(struct channel4_data, 1);
2078 char *dialog_msg = g_strdup_printf(_("The user %lu wants to add you to their buddy list for the following reason: %s"), args->uin, msg2[5] ? msg2[5] : _("No reason given."));
2079 debug_printf("Received an authorization request from UIN %lu\n", args->uin);
2080 data->gc = gc;
2081 data->uin = g_strdup_printf("%lu", args->uin);
2082 do_ask_dialog(_("Authorization Request"), dialog_msg, data, _("Authorize"), gaim_icq_authgrant, _("Deny"), gaim_icq_authdeny);
2083 g_free(dialog_msg);
2084 }
2084 } break; 2085 } break;
2085 2086
2086 case 0x0007: { /* Someone has denied you authorization */ 2087 case 0x0007: { /* Someone has denied you authorization */
2087 char *dialog_msg; 2088 if (i >= 1) {
2088 dialog_msg = g_strdup_printf(_("The user %lu has denied your request to add them to your contact list for the following reason:\n%s"), args->uin, args->msg ? args->msg : _("No reason given.")); 2089 char *dialog_msg = g_strdup_printf(_("The user %lu has denied your request to add them to your contact list for the following reason:\n%s"), args->uin, msg2[0] ? msg2[0] : _("No reason given."));
2089 do_error_dialog(_("ICQ authorization denied."), dialog_msg, GAIM_ERROR); 2090 do_error_dialog(_("ICQ authorization denied."), dialog_msg, GAIM_ERROR);
2090 g_free(dialog_msg); 2091 g_free(dialog_msg);
2092 }
2091 } break; 2093 } break;
2092 2094
2093 case 0x0008: { /* Someone has granted you authorization */ 2095 case 0x0008: { /* Someone has granted you authorization */
2094 char *dialog_msg; 2096 char *dialog_msg = g_strdup_printf(_("The user %lu has granted your request to add them to your contact list."), args->uin);
2095 dialog_msg = g_strdup_printf(_("The user %lu has granted your request to add them to your contact list."), args->uin);
2096 do_error_dialog("ICQ authorization accepted.", dialog_msg, GAIM_INFO); 2097 do_error_dialog("ICQ authorization accepted.", dialog_msg, GAIM_INFO);
2097 g_free(dialog_msg); 2098 g_free(dialog_msg);
2098 } break; 2099 } break;
2099 2100
2100 case 0x000d: { /* Someone has sent you a pager message from http://web.icq.com/wwp/1,,,00.html?Uin=your_uin */ 2101 case 0x000d: { /* Someone has sent you a pager message from http://www.icq.com/your_uin */
2101 char *dialog_msg; 2102 if (i >= 6) {
2102 gchar **text; 2103 char *dialog_msg = g_strdup_printf(_("You have received an ICQ page\n\nFrom: %s [%s]\n%s"), msg2[0], msg2[3], msg2[5]);
2103 text = g_strsplit(args->msg, "þ", 0); 2104 do_error_dialog("ICQ Page", dialog_msg, GAIM_INFO);
2104 dialog_msg = g_strdup_printf(_("You have received an ICQ page\n\nFrom: %s [%s]\n%s"), text[0], text[3], text[5]); 2105 g_free(dialog_msg);
2105 do_error_dialog("ICQ Page", dialog_msg, GAIM_INFO); 2106 }
2106 g_strfreev(text);
2107 g_free(dialog_msg);
2108 } break; 2107 } break;
2109 2108
2110 case 0x000e: { /* Someone has emailed you at your_uin@pager.icq.com */ 2109 case 0x000e: { /* Someone has emailed you at your_uin@pager.icq.com */
2111 char *dialog_msg; 2110 if (i >= 6) {
2112 gchar **text; 2111 char *dialog_msg = g_strdup_printf(_("You have received an ICQ email\n\n1=%s\n2=%s\n3=%s\n4=%s\n5=%s\n6=%s\n"), msg2[0], msg2[1], msg2[2], msg2[3], msg2[4], msg2[5]);
2113 text = g_strsplit(args->msg, "þ", 0); 2112 do_error_dialog("ICQ Email", dialog_msg, GAIM_INFO);
2114 /* dialog_msg = g_strdup_printf(_("You have received an ICQ email\n\n1=%s\n2=%s\n3=%s\n4=%s\n5=%s\n6=%s\n"), text[0], text[1], text[2], text[3], text[4], text[5]); */ 2113 g_free(dialog_msg);
2115 dialog_msg = g_strdup_printf(_("You have received an ICQ email\n\nFrom: Not yet")); 2114 }
2116 do_error_dialog("ICQ Email", dialog_msg, GAIM_INFO);
2117 g_strfreev(text);
2118 g_free(dialog_msg);
2119 } break; 2115 } break;
2120 2116
2121 case 0x0012: { 2117 case 0x0012: {
2122 /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */ 2118 /* Ack for authorizing/denying someone. Or possibly an ack for sending any system notice */
2123 } break; 2119 } break;
2134 struct channel4_data *data = g_new(struct channel4_data, 1); 2130 struct channel4_data *data = g_new(struct channel4_data, 1);
2135 gchar *message = g_strdup_printf(_("ICQ user %lu has sent you a contact: %s (%s)"), args->uin, text[i*2+2], text[i*2+1]); 2131 gchar *message = g_strdup_printf(_("ICQ user %lu has sent you a contact: %s (%s)"), args->uin, text[i*2+2], text[i*2+1]);
2136 data->gc = gc; 2132 data->gc = gc;
2137 data->uin = g_strdup(text[i*2+2]); 2133 data->uin = g_strdup(text[i*2+2]);
2138 data->nick = g_strdup(text[i*2+1]); 2134 data->nick = g_strdup(text[i*2+1]);
2139 do_ask_dialog(message, "Do you want to add this contact to your Buddy List?", data, _("Add"), gaim_icq_contactadd, _("Deny"), gaim_icq_contactdontadd); 2135 do_ask_dialog(message, _("Do you want to add this contact to your Buddy List?"), data, _("Add"), gaim_icq_contactadd, _("Deny"), gaim_icq_contactdontadd);
2140 g_free(message); 2136 g_free(message);
2141 } 2137 }
2142 g_strfreev(text); 2138 g_strfreev(text);
2143 } 2139 }
2144 } break; 2140 } break;
2149 2145
2150 default: { 2146 default: {
2151 debug_printf("Received a channel 4 message of unknown type (type 0x%04d).\n", args->type); 2147 debug_printf("Received a channel 4 message of unknown type (type 0x%04d).\n", args->type);
2152 } break; 2148 } break;
2153 } 2149 }
2150
2151 g_strfreev(msg1);
2152 g_strfreev(msg2);
2154 2153
2155 return 1; 2154 return 1;
2156 } 2155 }
2157 2156
2158 static int gaim_parse_incoming_im(aim_session_t *sess, aim_frame_t *fr, ...) { 2157 static int gaim_parse_incoming_im(aim_session_t *sess, aim_frame_t *fr, ...) {
3179 va_end(ap); 3178 va_end(ap);
3180 3179
3181 debug_printf("Received offline message. Converting to channel 4 ICBM...\n"); 3180 debug_printf("Received offline message. Converting to channel 4 ICBM...\n");
3182 args.uin = msg->sender; 3181 args.uin = msg->sender;
3183 args.type = msg->type; 3182 args.type = msg->type;
3183 args.msglen = msg->msglen;
3184 args.msg = msg->msg; 3184 args.msg = msg->msg;
3185 t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0); 3185 t = get_time(msg->year, msg->month, msg->day, msg->hour, msg->minute, 0);
3186 incomingim_chan4(sess, fr->conn, NULL, &args, t); 3186 incomingim_chan4(sess, fr->conn, NULL, &args, t);
3187 3187
3188 return 1; 3188 return 1;