Mercurial > pidgin.yaz
comparison src/protocols/irc/irc.c @ 5136:381da05cb5ed
[gaim-migrate @ 5500]
this started out as simply adding an option to right-click on a jabber buddy
and re-request authorization. Then I ended up chasing the disgusting mess
of const vs non-const parameters all over gaim.
The end result is that you can now right-click on jabber buddies and
re-request auth like you can for ICQ. Also, a lot more things are const
that should be, I fixed a bug or two, and I cleaned up one of my least
favorite functions in gaim (linkify_text). It is now decidedly less evil.
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 15 Apr 2003 04:18:00 +0000 |
parents | b37d7d09ec83 |
children | 9a19c0a1e1be |
comparison
equal
deleted
inserted
replaced
5135:102135caa225 | 5136:381da05cb5ed |
---|---|
110 GString *liststr; | 110 GString *liststr; |
111 GSList *file_transfers; | 111 GSList *file_transfers; |
112 }; | 112 }; |
113 | 113 |
114 /* Prototypes */ | 114 /* Prototypes */ |
115 static void irc_start_chat(struct gaim_connection *gc, char *who); | 115 static void irc_start_chat(struct gaim_connection *gc, const char *who); |
116 static void irc_ctcp_clientinfo(struct gaim_connection *gc, char *who); | 116 static void irc_ctcp_clientinfo(struct gaim_connection *gc, const char *who); |
117 static void irc_ctcp_userinfo(struct gaim_connection *gc, char *who); | 117 static void irc_ctcp_userinfo(struct gaim_connection *gc, const char *who); |
118 static void irc_ctcp_version(struct gaim_connection *gc, char *who); | 118 static void irc_ctcp_version(struct gaim_connection *gc, const char *who); |
119 static void irc_ctcp_ping(struct gaim_connection *gc, char *who); | 119 static void irc_ctcp_ping(struct gaim_connection *gc, const char *who); |
120 | 120 |
121 static void irc_send_privmsg(struct gaim_connection *gc, char *who, char *what, gboolean fragment); | 121 static void irc_send_privmsg(struct gaim_connection *gc, const char *who, const char *what, gboolean fragment); |
122 static void irc_send_notice(struct gaim_connection *gc, char *who, char *what); | 122 static void irc_send_notice(struct gaim_connection *gc, char *who, char *what); |
123 | 123 |
124 static char *irc_send_convert(struct gaim_connection *gc, char *string, int maxlen, int *done); | 124 static char *irc_send_convert(struct gaim_connection *gc, const char *string, int maxlen, int *done); |
125 static char *irc_recv_convert(struct gaim_connection *gc, char *string); | 125 static char *irc_recv_convert(struct gaim_connection *gc, char *string); |
126 static void irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex, | 126 static void irc_parse_notice(struct gaim_connection *gc, char *nick, char *ex, |
127 char *word[], char *word_eol[]); | 127 char *word[], char *word_eol[]); |
128 static void irc_parse_join(struct gaim_connection *gc, char *nick, | 128 static void irc_parse_join(struct gaim_connection *gc, char *nick, |
129 char *word[], char *word_eol[]); | 129 char *word[], char *word_eol[]); |
136 | 136 |
137 /* Global variables */ | 137 /* Global variables */ |
138 GSList *dcc_chat_list = NULL; | 138 GSList *dcc_chat_list = NULL; |
139 | 139 |
140 struct dcc_chat * | 140 struct dcc_chat * |
141 find_dcc_chat (struct gaim_connection *gc, char *nick) | 141 find_dcc_chat (struct gaim_connection *gc, const char *nick) |
142 { | 142 { |
143 GSList *tmp; | 143 GSList *tmp; |
144 struct dcc_chat *data; | 144 struct dcc_chat *data; |
145 tmp = dcc_chat_list; | 145 tmp = dcc_chat_list; |
146 while (tmp != NULL) | 146 while (tmp != NULL) |
164 debug_printf("IRC C: %s", data); | 164 debug_printf("IRC C: %s", data); |
165 return write(fd, data, len); | 165 return write(fd, data, len); |
166 } | 166 } |
167 | 167 |
168 static char * | 168 static char * |
169 irc_send_convert(struct gaim_connection *gc, char *string, int maxlen, int *done) | 169 irc_send_convert(struct gaim_connection *gc, const char *string, int maxlen, int *done) |
170 { | 170 { |
171 char *converted = g_malloc(maxlen + 1); | 171 char *converted = g_malloc(maxlen + 1); |
172 gchar *inptr = string, *outptr = converted; | 172 gchar *inptr = (gchar*)string, *outptr = converted; |
173 int inleft = strlen(string), outleft = maxlen; | 173 int inleft = strlen(string), outleft = maxlen; |
174 GIConv conv; | 174 GIConv conv; |
175 | 175 |
176 conv = g_iconv_open(gc->account->proto_opt[USEROPT_CHARSET], "UTF-8"); | 176 conv = g_iconv_open(gc->account->proto_opt[USEROPT_CHARSET], "UTF-8"); |
177 if (g_iconv(conv, &inptr, &inleft, &outptr, &outleft) == -1) { | 177 if (g_iconv(conv, &inptr, &inleft, &outptr, &outleft) == -1) { |
202 | 202 |
203 return (utf8); | 203 return (utf8); |
204 } | 204 } |
205 | 205 |
206 static struct gaim_conversation * | 206 static struct gaim_conversation * |
207 irc_find_chat(struct gaim_connection *gc, char *name) | 207 irc_find_chat(struct gaim_connection *gc, const char *name) |
208 { | 208 { |
209 GSList *bcs = gc->buddy_chats; | 209 GSList *bcs = gc->buddy_chats; |
210 | 210 |
211 while (bcs) { | 211 while (bcs) { |
212 struct gaim_conversation *b = bcs->data; | 212 struct gaim_conversation *b = bcs->data; |
1114 break; | 1114 break; |
1115 } | 1115 } |
1116 } | 1116 } |
1117 | 1117 |
1118 static gboolean | 1118 static gboolean |
1119 is_channel(struct gaim_connection *gc, char *name) | 1119 is_channel(struct gaim_connection *gc, const char *name) |
1120 { | 1120 { |
1121 struct irc_data *id = gc->proto_data; | 1121 struct irc_data *id = gc->proto_data; |
1122 if (strchr(id->chantypes, *name)) | 1122 if (strchr(id->chantypes, *name)) |
1123 return TRUE; | 1123 return TRUE; |
1124 return FALSE; | 1124 return FALSE; |
1916 close(idata->fd); | 1916 close(idata->fd); |
1917 g_free(gc->proto_data); | 1917 g_free(gc->proto_data); |
1918 } | 1918 } |
1919 | 1919 |
1920 static void | 1920 static void |
1921 set_mode_3(struct gaim_connection *gc, char *who, int sign, int mode, | 1921 set_mode_3(struct gaim_connection *gc, const char *who, int sign, int mode, |
1922 int start, int end, char *word[]) | 1922 int start, int end, char *word[]) |
1923 { | 1923 { |
1924 struct irc_data *id = gc->proto_data; | 1924 struct irc_data *id = gc->proto_data; |
1925 char buf[IRC_BUF_LEN]; | 1925 char buf[IRC_BUF_LEN]; |
1926 int left; | 1926 int left; |
1953 return; | 1953 return; |
1954 } | 1954 } |
1955 } | 1955 } |
1956 | 1956 |
1957 static void | 1957 static void |
1958 set_mode_6(struct gaim_connection *gc, char *who, int sign, int mode, | 1958 set_mode_6(struct gaim_connection *gc, const char *who, int sign, int mode, |
1959 int start, int end, char *word[]) | 1959 int start, int end, char *word[]) |
1960 { | 1960 { |
1961 struct irc_data *id = gc->proto_data; | 1961 struct irc_data *id = gc->proto_data; |
1962 char buf[IRC_BUF_LEN]; | 1962 char buf[IRC_BUF_LEN]; |
1963 int left; | 1963 int left; |
2010 return; | 2010 return; |
2011 } | 2011 } |
2012 } | 2012 } |
2013 | 2013 |
2014 static void | 2014 static void |
2015 set_mode(struct gaim_connection *gc, char *who, int sign, int mode, char *word[]) | 2015 set_mode(struct gaim_connection *gc, const char *who, int sign, int mode, char *word[]) |
2016 { | 2016 { |
2017 struct irc_data *id = gc->proto_data; | 2017 struct irc_data *id = gc->proto_data; |
2018 int i = 2; | 2018 int i = 2; |
2019 | 2019 |
2020 while (1) { | 2020 while (1) { |
2030 i++; | 2030 i++; |
2031 } | 2031 } |
2032 } | 2032 } |
2033 | 2033 |
2034 static void | 2034 static void |
2035 set_chan_mode(struct gaim_connection *gc, char *chan, char *mode_str) | 2035 set_chan_mode(struct gaim_connection *gc, const char *chan, const char *mode_str) |
2036 { | 2036 { |
2037 struct irc_data *id = gc->proto_data; | 2037 struct irc_data *id = gc->proto_data; |
2038 char buf[IRC_BUF_LEN]; | 2038 char buf[IRC_BUF_LEN]; |
2039 | 2039 |
2040 if ((mode_str[0] == '-') || (mode_str[0] == '+')) { | 2040 if ((mode_str[0] == '-') || (mode_str[0] == '+')) { |
2042 irc_write(id->fd, buf, strlen(buf)); | 2042 irc_write(id->fd, buf, strlen(buf)); |
2043 } | 2043 } |
2044 } | 2044 } |
2045 | 2045 |
2046 static int | 2046 static int |
2047 handle_command(struct gaim_connection *gc, char *who, char *what) | 2047 handle_command(struct gaim_connection *gc, const char *who, const char *in_what) |
2048 { | 2048 { |
2049 char buf[IRC_BUF_LEN]; | 2049 char buf[IRC_BUF_LEN]; |
2050 char pdibuf[IRC_BUF_LEN]; | 2050 char pdibuf[IRC_BUF_LEN]; |
2051 char *word[PDIWORDS], *word_eol[PDIWORDS]; | 2051 char *word[PDIWORDS], *word_eol[PDIWORDS]; |
2052 char *tmp = g_strdup(what); | 2052 char *tmp = g_strdup(in_what); |
2053 GString *str = encode_html(tmp); | 2053 GString *str = encode_html(tmp); |
2054 char *intl; | 2054 char *intl; |
2055 int len; | 2055 int len; |
2056 struct dcc_chat *dccchat = find_dcc_chat(gc, who); | 2056 struct dcc_chat *dccchat = find_dcc_chat(gc, who); |
2057 struct irc_data *id = gc->proto_data; | 2057 struct irc_data *id = gc->proto_data; |
2058 char *what = str->str; | |
2058 | 2059 |
2059 g_free(tmp); | 2060 g_free(tmp); |
2060 what = str->str; | |
2061 | 2061 |
2062 if (*what != '/') { | 2062 if (*what != '/') { |
2063 if (dccchat) { | 2063 if (dccchat) { |
2064 intl = irc_send_convert(gc, what, sizeof(buf), &len); | 2064 intl = irc_send_convert(gc, what, sizeof(buf), &len); |
2065 g_snprintf(buf, sizeof(buf), "%s\r\n", intl); | 2065 g_snprintf(buf, sizeof(buf), "%s\r\n", intl); |
2128 } else if (!g_ascii_strcasecmp(pdibuf, "VOICE")) { | 2128 } else if (!g_ascii_strcasecmp(pdibuf, "VOICE")) { |
2129 set_mode(gc, who, '+', 'v', word); | 2129 set_mode(gc, who, '+', 'v', word); |
2130 } else if (!g_ascii_strcasecmp(pdibuf, "DEVOICE")) { | 2130 } else if (!g_ascii_strcasecmp(pdibuf, "DEVOICE")) { |
2131 set_mode(gc, who, '-', 'v', word); | 2131 set_mode(gc, who, '-', 'v', word); |
2132 } else if (!g_ascii_strcasecmp(pdibuf, "MODE")) { | 2132 } else if (!g_ascii_strcasecmp(pdibuf, "MODE")) { |
2133 char *chan = who; | 2133 set_chan_mode(gc, who, word_eol[2]); |
2134 set_chan_mode(gc, chan, word_eol[2]); | |
2135 } else if (!g_ascii_strcasecmp(pdibuf, "QUOTE")) { | 2134 } else if (!g_ascii_strcasecmp(pdibuf, "QUOTE")) { |
2136 if (!*word_eol[2]) { | 2135 if (!*word_eol[2]) { |
2137 g_free(what); | 2136 g_free(what); |
2138 return -EINVAL; | 2137 return -EINVAL; |
2139 } | 2138 } |
2177 g_snprintf(buf, sizeof(buf), "JOIN %s %s\r\n", word[2], word[3]); | 2176 g_snprintf(buf, sizeof(buf), "JOIN %s %s\r\n", word[2], word[3]); |
2178 else | 2177 else |
2179 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", word[2]); | 2178 g_snprintf(buf, sizeof(buf), "JOIN %s\r\n", word[2]); |
2180 irc_write(id->fd, buf, strlen(buf)); | 2179 irc_write(id->fd, buf, strlen(buf)); |
2181 } else if (!g_ascii_strcasecmp(pdibuf, "PART")) { | 2180 } else if (!g_ascii_strcasecmp(pdibuf, "PART")) { |
2182 char *chan = *word[2] ? word[2] : who; | 2181 const char *chan = *word[2] ? word[2] : who; |
2183 char *reason = word_eol[3]; | 2182 char *reason = word_eol[3]; |
2184 struct gaim_conversation *c; | 2183 struct gaim_conversation *c; |
2185 if (!is_channel(gc, chan)) { | 2184 if (!is_channel(gc, chan)) { |
2186 g_free(what); | 2185 g_free(what); |
2187 return -EINVAL; | 2186 return -EINVAL; |
2317 g_free(what); | 2316 g_free(what); |
2318 return 0; | 2317 return 0; |
2319 } | 2318 } |
2320 | 2319 |
2321 static int | 2320 static int |
2322 send_msg(struct gaim_connection *gc, char *who, char *what) | 2321 send_msg(struct gaim_connection *gc, const char *who, const char *what) |
2323 { | 2322 { |
2324 char *cr = strchr(what, '\n'); | 2323 char *cr = strchr(what, '\n'); |
2325 if (cr) { | 2324 if (cr) { |
2326 int ret = 0; | 2325 int ret = 0; |
2327 while (TRUE) { | 2326 while (TRUE) { |
2349 g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name); | 2348 g_snprintf(buf, sizeof(buf), "INVITE %s %s\r\n", name, c->name); |
2350 irc_write(id->fd, buf, strlen(buf)); | 2349 irc_write(id->fd, buf, strlen(buf)); |
2351 } | 2350 } |
2352 | 2351 |
2353 static int | 2352 static int |
2354 irc_send_im(struct gaim_connection *gc, char *who, char *what, int len, int flags) | 2353 irc_send_im(struct gaim_connection *gc, const char *who, const char *what, int len, int flags) |
2355 { | 2354 { |
2356 if (*who == '@' || *who == '%' || *who == '+') | 2355 if (*who == '@' || *who == '%' || *who == '+') |
2357 return send_msg(gc, who + 1, what); | 2356 return send_msg(gc, who + 1, what); |
2358 return send_msg(gc, who, what); | 2357 return send_msg(gc, who, what); |
2359 } | 2358 } |
2649 proxy_connect(gc->account, ift->ip, ift->port, dcc_recv_callback, ift); | 2648 proxy_connect(gc->account, ift->ip, ift->port, dcc_recv_callback, ift); |
2650 } | 2649 } |
2651 #endif | 2650 #endif |
2652 | 2651 |
2653 static void | 2652 static void |
2654 irc_ctcp_clientinfo(struct gaim_connection *gc, char *who) | 2653 irc_ctcp_clientinfo(struct gaim_connection *gc, const char *who) |
2655 { | 2654 { |
2656 char buf[IRC_BUF_LEN]; | 2655 char buf[IRC_BUF_LEN]; |
2657 | 2656 |
2658 snprintf (buf, sizeof buf, "\001CLIENTINFO\001"); | 2657 snprintf (buf, sizeof buf, "\001CLIENTINFO\001"); |
2659 irc_send_privmsg(gc, who, buf, FALSE); | 2658 irc_send_privmsg(gc, who, buf, FALSE); |
2660 } | 2659 } |
2661 | 2660 |
2662 static void | 2661 static void |
2663 irc_ctcp_userinfo(struct gaim_connection *gc, char *who) | 2662 irc_ctcp_userinfo(struct gaim_connection *gc, const char *who) |
2664 { | 2663 { |
2665 char buf[IRC_BUF_LEN]; | 2664 char buf[IRC_BUF_LEN]; |
2666 | 2665 |
2667 snprintf (buf, sizeof buf, "\001USERINFO\001"); | 2666 snprintf (buf, sizeof buf, "\001USERINFO\001"); |
2668 irc_send_privmsg(gc, who, buf, FALSE); | 2667 irc_send_privmsg(gc, who, buf, FALSE); |
2669 } | 2668 } |
2670 | 2669 |
2671 static void | 2670 static void |
2672 irc_ctcp_version(struct gaim_connection *gc, char *who) | 2671 irc_ctcp_version(struct gaim_connection *gc, const char *who) |
2673 { | 2672 { |
2674 char buf[IRC_BUF_LEN]; | 2673 char buf[IRC_BUF_LEN]; |
2675 | 2674 |
2676 snprintf (buf, sizeof buf, "\001VERSION\001"); | 2675 snprintf (buf, sizeof buf, "\001VERSION\001"); |
2677 irc_send_privmsg(gc, who, buf, FALSE); | 2676 irc_send_privmsg(gc, who, buf, FALSE); |
2678 } | 2677 } |
2679 | 2678 |
2680 static void | 2679 static void |
2681 irc_ctcp_ping(struct gaim_connection *gc, char *who) | 2680 irc_ctcp_ping(struct gaim_connection *gc, const char *who) |
2682 { | 2681 { |
2683 char buf[IRC_BUF_LEN]; | 2682 char buf[IRC_BUF_LEN]; |
2684 | 2683 |
2685 g_snprintf (buf, sizeof(buf), "\001PING %ld\001", time(NULL)); | 2684 g_snprintf (buf, sizeof(buf), "\001PING %ld\001", time(NULL)); |
2686 irc_send_privmsg(gc, who, buf, FALSE); | 2685 irc_send_privmsg(gc, who, buf, FALSE); |
2714 * to NINETY-THREE chars on dancer, which seems to be a pretty liberal | 2713 * to NINETY-THREE chars on dancer, which seems to be a pretty liberal |
2715 * ircd. My rough calculation for now is ":<nick>!~<user>@<host> ", | 2714 * ircd. My rough calculation for now is ":<nick>!~<user>@<host> ", |
2716 * where <host> is a max of an (uncalculated) 63 chars. Thanks to | 2715 * where <host> is a max of an (uncalculated) 63 chars. Thanks to |
2717 * trelane and #freenode for giving a hand here. */ | 2716 * trelane and #freenode for giving a hand here. */ |
2718 static void | 2717 static void |
2719 irc_send_privmsg(struct gaim_connection *gc, char *who, char *what, gboolean fragment) | 2718 irc_send_privmsg(struct gaim_connection *gc, const char *who, const char *what, gboolean fragment) |
2720 { | 2719 { |
2721 char buf[IRC_BUF_LEN], *intl; | 2720 char buf[IRC_BUF_LEN], *intl; |
2722 struct irc_data *id = gc->proto_data; | 2721 struct irc_data *id = gc->proto_data; |
2723 /* 512 - 12 (for PRIVMSG" "" :""\r\n") - namelen - nicklen - 68 */ | 2722 /* 512 - 12 (for PRIVMSG" "" :""\r\n") - namelen - nicklen - 68 */ |
2724 int nicklen = (gc->account->alias && strlen(gc->account->alias)) ? strlen(gc->account->alias) : 4; | 2723 int nicklen = (gc->account->alias && strlen(gc->account->alias)) ? strlen(gc->account->alias) : 4; |
2736 what += len; | 2735 what += len; |
2737 } while (fragment && strlen(what)); | 2736 } while (fragment && strlen(what)); |
2738 } | 2737 } |
2739 | 2738 |
2740 static void | 2739 static void |
2741 irc_start_chat(struct gaim_connection *gc, char *who) { | 2740 irc_start_chat(struct gaim_connection *gc, const char *who) { |
2742 struct dcc_chat *chat; | 2741 struct dcc_chat *chat; |
2743 int len; | 2742 int len; |
2744 struct sockaddr_in addr; | 2743 struct sockaddr_in addr; |
2745 char buf[IRC_BUF_LEN]; | 2744 char buf[IRC_BUF_LEN]; |
2746 | 2745 |
2769 chat->ip_address, chat->port); | 2768 chat->ip_address, chat->port); |
2770 irc_send_im (gc, who, buf, -1, 0); | 2769 irc_send_im (gc, who, buf, -1, 0); |
2771 } | 2770 } |
2772 | 2771 |
2773 static void | 2772 static void |
2774 irc_get_info(struct gaim_connection *gc, char *who) | 2773 irc_get_info(struct gaim_connection *gc, const char *who) |
2775 { | 2774 { |
2776 struct irc_data *idata = gc->proto_data; | 2775 struct irc_data *idata = gc->proto_data; |
2777 char buf[IRC_BUF_LEN]; | 2776 char buf[IRC_BUF_LEN]; |
2778 | 2777 |
2779 if (*who == '@') | 2778 if (*who == '@') |
2786 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", who); | 2785 g_snprintf(buf, sizeof(buf), "WHOIS %s\r\n", who); |
2787 irc_write(idata->fd, buf, strlen(buf)); | 2786 irc_write(idata->fd, buf, strlen(buf)); |
2788 } | 2787 } |
2789 | 2788 |
2790 static GList * | 2789 static GList * |
2791 irc_buddy_menu(struct gaim_connection *gc, char *who) | 2790 irc_buddy_menu(struct gaim_connection *gc, const char *who) |
2792 { | 2791 { |
2793 GList *m = NULL; | 2792 GList *m = NULL; |
2794 struct proto_buddy_menu *pbm; | 2793 struct proto_buddy_menu *pbm; |
2795 | 2794 |
2796 pbm = g_new0(struct proto_buddy_menu, 1); | 2795 pbm = g_new0(struct proto_buddy_menu, 1); |