comparison src/protocols/oscar/oscar.c @ 2167:edf8c5a70e5b

[gaim-migrate @ 2177] limiting chat message lengths committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sun, 26 Aug 2001 20:21:45 +0000
parents a464da684307
children c24595d3c364
comparison
equal deleted inserted replaced
2166:dbd74f49dabb 2167:edf8c5a70e5b
104 struct aim_conn_t *conn; 104 struct aim_conn_t *conn;
105 int inpa; 105 int inpa;
106 int id; 106 int id;
107 struct gaim_connection *gc; /* i hate this. */ 107 struct gaim_connection *gc; /* i hate this. */
108 struct conversation *cnv; /* bah. */ 108 struct conversation *cnv; /* bah. */
109 int maxlen;
110 int maxvis;
109 }; 111 };
110 112
111 struct direct_im { 113 struct direct_im {
112 struct gaim_connection *gc; 114 struct gaim_connection *gc;
113 char name[80]; 115 char name[80];
279 static int gaim_rateresp (struct aim_session_t *, struct command_rx_struct *, ...); 281 static int gaim_rateresp (struct aim_session_t *, struct command_rx_struct *, ...);
280 static int gaim_reportinterval (struct aim_session_t *, struct command_rx_struct *, ...); 282 static int gaim_reportinterval (struct aim_session_t *, struct command_rx_struct *, ...);
281 static int gaim_parse_msgerr (struct aim_session_t *, struct command_rx_struct *, ...); 283 static int gaim_parse_msgerr (struct aim_session_t *, struct command_rx_struct *, ...);
282 static int gaim_parse_buddyrights(struct aim_session_t *, struct command_rx_struct *, ...); 284 static int gaim_parse_buddyrights(struct aim_session_t *, struct command_rx_struct *, ...);
283 static int gaim_parse_locerr (struct aim_session_t *, struct command_rx_struct *, ...); 285 static int gaim_parse_locerr (struct aim_session_t *, struct command_rx_struct *, ...);
286 static int gaim_icbm_param_info (struct aim_session_t *, struct command_rx_struct *, ...);
284 static int gaim_parse_genericerr (struct aim_session_t *, struct command_rx_struct *, ...); 287 static int gaim_parse_genericerr (struct aim_session_t *, struct command_rx_struct *, ...);
285 static int gaim_memrequest (struct aim_session_t *, struct command_rx_struct *, ...); 288 static int gaim_memrequest (struct aim_session_t *, struct command_rx_struct *, ...);
286 289
287 static int gaim_directim_initiate (struct aim_session_t *, struct command_rx_struct *, ...); 290 static int gaim_directim_initiate (struct aim_session_t *, struct command_rx_struct *, ...);
288 static int gaim_directim_incoming (struct aim_session_t *, struct command_rx_struct *, ...); 291 static int gaim_directim_incoming (struct aim_session_t *, struct command_rx_struct *, ...);
690 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, 0x0003, gaim_parse_searchreply, 0); 693 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOK, 0x0003, gaim_parse_searchreply, 0);
691 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, gaim_parse_msgerr, 0); 694 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, gaim_parse_msgerr, 0);
692 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, gaim_parse_user_info, 0); 695 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, gaim_parse_user_info, 0);
693 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, gaim_parse_msgack, 0); 696 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, gaim_parse_msgack, 0);
694 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); 697 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0);
698 aim_conn_addhandler(sess, bosconn, 0x0004, 0x0005, gaim_icbm_param_info, 0);
695 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, gaim_parse_genericerr, 0); 699 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, gaim_parse_genericerr, 0);
696 aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, gaim_parse_genericerr, 0); 700 aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, gaim_parse_genericerr, 0);
697 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, gaim_parse_genericerr, 0); 701 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, gaim_parse_genericerr, 0);
698 aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, gaim_memrequest, 0); 702 aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, gaim_memrequest, 0);
699 703
1913 nummissed = (unsigned short)va_arg(ap, unsigned int); 1917 nummissed = (unsigned short)va_arg(ap, unsigned int);
1914 reason = (unsigned short)va_arg(ap, unsigned int); 1918 reason = (unsigned short)va_arg(ap, unsigned int);
1915 va_end(ap); 1919 va_end(ap);
1916 1920
1917 switch(reason) { 1921 switch(reason) {
1922 case 0:
1923 /* Invalid (0) */
1924 g_snprintf(buf,
1925 sizeof(buf),
1926 _("You missed %d message%s from %s because %s invalid."),
1927 nummissed,
1928 nummissed == 1 ? "" : "s",
1929 nummissed == 1 ? "it was" : "they were",
1930 userinfo->sn);
1931 break;
1918 case 1: 1932 case 1:
1919 /* message too large */ 1933 /* Message too large */
1920 sprintf(buf, _("You missed a message from %s because it was too large."), userinfo->sn); 1934 g_snprintf(buf,
1921 do_error_dialog(buf, _("Gaim - Error")); 1935 sizeof(buf),
1922 plugin_event(event_error, (void *)961, 0, 0, 0); 1936 _("You missed %d message%s from %s because %s too large."),
1937 nummissed,
1938 nummissed == 1 ? "" : "s",
1939 nummissed == 1 ? "it was" : "they were",
1940 userinfo->sn);
1941 break;
1942 case 2:
1943 /* Rate exceeded */
1944 g_snprintf(buf,
1945 sizeof(buf),
1946 _("You missed %d message%s from %s because the rate limit has been exceeded."),
1947 nummissed,
1948 nummissed == 1 ? "" : "s",
1949 userinfo->sn);
1950 break;
1951 case 3:
1952 /* Evil Sender */
1953 g_snprintf(buf,
1954 sizeof(buf),
1955 _("You missed %d message%s from %s because they are too evil."),
1956 nummissed,
1957 nummissed == 1 ? "" : "s",
1958 userinfo->sn);
1959 break;
1960 case 4:
1961 /* Evil Receiver */
1962 g_snprintf(buf,
1963 sizeof(buf),
1964 _("You missed %d message%s from %s because you are too evil."),
1965 nummissed,
1966 nummissed == 1 ? "" : "s",
1967 userinfo->sn);
1923 break; 1968 break;
1924 default: 1969 default:
1925 sprintf(buf, _("You missed a message from %s for unknown reasons."), userinfo->sn); 1970 g_snprintf(buf,
1926 do_error_dialog(buf, _("Gaim - Error")); 1971 sizeof(buf),
1927 plugin_event(event_error, (void *)970, 0, 0, 0); 1972 _("You missed %d message%s from %s for unknown reasons."),
1973 nummissed,
1974 nummissed == 1 ? "" : "s",
1975 userinfo->sn);
1928 break; 1976 break;
1929 } 1977 }
1978 do_error_dialog(buf, _("Gaim - Error"));
1930 1979
1931 return 1; 1980 return 1;
1932 } 1981 }
1933 1982
1934 int gaim_parse_genericerr(struct aim_session_t *sess, struct command_rx_struct *command, ...) { 1983 int gaim_parse_genericerr(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
2192 return 1; 2241 return 1;
2193 } 2242 }
2194 2243
2195 int gaim_chat_info_update(struct aim_session_t *sess, 2244 int gaim_chat_info_update(struct aim_session_t *sess,
2196 struct command_rx_struct *command, ...) { 2245 struct command_rx_struct *command, ...) {
2197 debug_printf("inside chat_info_update\n"); 2246 va_list ap;
2247 struct aim_userinfo_s *userinfo;
2248 struct aim_chat_roominfo *roominfo;
2249 char *roomname;
2250 int usercount;
2251 char *roomdesc;
2252 unsigned short unknown_c9, unknown_d2, unknown_d5, maxmsglen, maxvisiblemsglen;
2253 unsigned long creationtime;
2254 struct gaim_connection *gc = sess->aux_data;
2255 struct chat_connection *ccon = find_oscar_chat_by_conn(gc, command->conn);
2256
2257 va_start(ap, command);
2258 roominfo = va_arg(ap, struct aim_chat_roominfo *);
2259 roomname = va_arg(ap, char *);
2260 usercount= va_arg(ap, int);
2261 userinfo = va_arg(ap, struct aim_userinfo_s *);
2262 roomdesc = va_arg(ap, char *);
2263 unknown_c9 = va_arg(ap, int);
2264 creationtime = va_arg(ap, unsigned long);
2265 maxmsglen = va_arg(ap, int);
2266 unknown_d2 = va_arg(ap, int);
2267 unknown_d5 = va_arg(ap, int);
2268 maxvisiblemsglen = va_arg(ap, int);
2269 va_end(ap);
2270
2271 debug_printf("inside chat_info_update (maxmsglen = %d, maxvislen = %d)\n",
2272 maxmsglen, maxvisiblemsglen);
2273
2274 ccon->maxlen = maxmsglen;
2275 ccon->maxvis = maxvisiblemsglen;
2276
2198 return 1; 2277 return 1;
2199 } 2278 }
2200 2279
2201 int gaim_chat_incoming_msg(struct aim_session_t *sess, 2280 int gaim_chat_incoming_msg(struct aim_session_t *sess,
2202 struct command_rx_struct *command, ...) { 2281 struct command_rx_struct *command, ...) {
2315 if (bud_list_cache_exists(gc)) 2394 if (bud_list_cache_exists(gc))
2316 do_import(NULL, gc); 2395 do_import(NULL, gc);
2317 2396
2318 debug_printf("buddy list loaded\n"); 2397 debug_printf("buddy list loaded\n");
2319 2398
2320 aim_addicbmparam(sess, command->conn); 2399 aim_reqicbmparams(sess, command->conn);
2321 aim_bos_reqicbmparaminfo(sess, command->conn);
2322 2400
2323 aim_bos_reqrights(sess, command->conn); 2401 aim_bos_reqrights(sess, command->conn);
2324 aim_bos_setgroupperm(sess, command->conn, AIM_FLAG_ALLUSERS); 2402 aim_bos_setgroupperm(sess, command->conn, AIM_FLAG_ALLUSERS);
2325 aim_bos_setprivacyflags(sess, command->conn, AIM_PRIVFLAGS_ALLOWIDLE | 2403 aim_bos_setprivacyflags(sess, command->conn, AIM_PRIVFLAGS_ALLOWIDLE |
2326 AIM_PRIVFLAGS_ALLOWMEMBERSINCE); 2404 AIM_PRIVFLAGS_ALLOWMEMBERSINCE);
2338 } 2416 }
2339 2417
2340 return 1; 2418 return 1;
2341 } 2419 }
2342 2420
2421 int gaim_icbm_param_info(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
2422 struct aim_icbmparameters *params;
2423 va_list ap;
2424
2425 va_start(ap, command);
2426 params = va_arg(ap, struct aim_icbmparameters *);
2427 va_end(ap);
2428
2429 debug_printf("ICBM Parameters: maxchannel = %d, default flags = 0x%08lx, max msg len = %d, "
2430 "max sender evil = %f, max receiver evil = %f, min msg interval = %ld\n",
2431 params->maxchan, params->flags, params->maxmsglen,
2432 ((float)params->maxsenderwarn)/10.0, ((float)params->maxrecverwarn)/10.0,
2433 params->minmsginterval);
2434
2435 params->maxmsglen = 8000;
2436 params->minmsginterval = 0;
2437
2438 aim_seticbmparam(sess, command->conn, params);
2439
2440 return 1;
2441 }
2442
2343 int gaim_reportinterval(struct aim_session_t *sess, struct command_rx_struct *command, ...) { 2443 int gaim_reportinterval(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
2344 if (command->data) { 2444 va_list ap;
2345 debug_printf("minimum report interval: %d (seconds?)\n", aimutil_get16(command->data+10)); 2445 unsigned short interval = 0;
2346 } else 2446
2347 debug_printf("NULL minimum report interval!\n"); 2447 va_start(ap, command);
2448 interval = va_arg(ap, int);
2449 va_end(ap);
2450
2451 debug_printf("minimum report interval: %d (seconds?)\n", interval);
2452
2453 aim_reqicbmparams(sess, command->conn);
2454
2348 return 1; 2455 return 1;
2349 } 2456 }
2350 2457
2351 int gaim_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...) { 2458 int gaim_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...) {
2352 va_list ap; 2459 va_list ap;
2711 } 2818 }
2712 /* we do this because with Oscar it doesn't tell us we left */ 2819 /* we do this because with Oscar it doesn't tell us we left */
2713 serv_got_chat_left(g, b->id); 2820 serv_got_chat_left(g, b->id);
2714 } 2821 }
2715 2822
2716 static void oscar_chat_send(struct gaim_connection *g, int id, char *message) { 2823 static int oscar_chat_send(struct gaim_connection *g, int id, char *message) {
2717 struct oscar_data *odata = (struct oscar_data *)g->proto_data; 2824 struct oscar_data *odata = (struct oscar_data *)g->proto_data;
2718 GSList *bcs = g->buddy_chats; 2825 GSList *bcs = g->buddy_chats;
2719 struct conversation *b = NULL; 2826 struct conversation *b = NULL;
2720 struct chat_connection *c = NULL; 2827 struct chat_connection *c = NULL;
2721 char *buf; 2828 char *buf, *buf2;
2722 int i, j; 2829 int i, j;
2723 2830
2724 while (bcs) { 2831 while (bcs) {
2725 b = (struct conversation *)bcs->data; 2832 b = (struct conversation *)bcs->data;
2726 if (id == b->id) 2833 if (id == b->id)
2727 break; 2834 break;
2728 bcs = bcs->next; 2835 bcs = bcs->next;
2729 b = NULL; 2836 b = NULL;
2730 } 2837 }
2731 if (!b) 2838 if (!b)
2732 return; 2839 return -EINVAL;
2733 2840
2734 bcs = odata->oscar_chats; 2841 bcs = odata->oscar_chats;
2735 while (bcs) { 2842 while (bcs) {
2736 c = (struct chat_connection *)bcs->data; 2843 c = (struct chat_connection *)bcs->data;
2737 if (b == c->cnv) 2844 if (b == c->cnv)
2738 break; 2845 break;
2739 bcs = bcs->next; 2846 bcs = bcs->next;
2740 c = NULL; 2847 c = NULL;
2741 } 2848 }
2742 if (!c) 2849 if (!c)
2743 return; 2850 return -EINVAL;
2744 2851
2745 buf = g_malloc(strlen(message) * 4 + 1); 2852 buf = g_malloc(strlen(message) * 4 + 1);
2746 for (i = 0, j = 0; i < strlen(message); i++) { 2853 for (i = 0, j = 0; i < strlen(message); i++) {
2747 if (message[i] == '\n') { 2854 if (message[i] == '\n') {
2748 buf[j++] = '<'; 2855 buf[j++] = '<';
2752 } else { 2859 } else {
2753 buf[j++] = message[i]; 2860 buf[j++] = message[i];
2754 } 2861 }
2755 } 2862 }
2756 buf[j] = '\0'; 2863 buf[j] = '\0';
2864
2865 if (strlen(buf) > c->maxlen)
2866 return -E2BIG;
2867
2868 buf2 = strip_html(buf);
2869 if (strlen(buf2) > c->maxvis) {
2870 g_free(buf2);
2871 return -E2BIG;
2872 }
2873 g_free(buf2);
2874
2757 aim_chat_send_im(odata->sess, c->conn, 0, buf, strlen(buf)); 2875 aim_chat_send_im(odata->sess, c->conn, 0, buf, strlen(buf));
2758 g_free(buf); 2876 g_free(buf);
2877 return 0;
2759 } 2878 }
2760 2879
2761 static char **oscar_list_icon(int uc) { 2880 static char **oscar_list_icon(int uc) {
2762 if (uc & UC_UNAVAILABLE) 2881 if (uc & UC_UNAVAILABLE)
2763 return (char **)away_icon_xpm; 2882 return (char **)away_icon_xpm;