Mercurial > pidgin.yaz
comparison src/server.c @ 6479:b808f9734879
[gaim-migrate @ 6992]
(19:12:00) Robot101: replacing some slightly crufty old code which makes assumptions like AIM-only, ignores gcs, could've messed up in certain obscure circumstances.
(19:12:10) Robot101: my code's probably more efficient in cpu and memory too.
(19:12:28) Robot101: and it's orthogonal to my message queue work so I split it off.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 15 Aug 2003 23:13:42 +0000 |
parents | 338147ea6896 |
children | 70d5122bc3ff |
comparison
equal
deleted
inserted
replaced
6478:338147ea6896 | 6479:b808f9734879 |
---|---|
174 return prpl_info->send_typing(g, name, typing); | 174 return prpl_info->send_typing(g, name, typing); |
175 | 175 |
176 return 0; | 176 return 0; |
177 } | 177 } |
178 | 178 |
179 struct queued_away_response { | 179 GSList *last_auto_responses = NULL; |
180 struct last_auto_response { | |
181 GaimConnection *gc; | |
180 char name[80]; | 182 char name[80]; |
181 time_t sent_away; | 183 time_t sent; |
182 }; | 184 }; |
183 | 185 |
184 struct queued_away_response *find_queued_away_response_by_name(const char *name); | 186 gboolean expire_last_auto_responses(gpointer data) |
187 { | |
188 GSList *tmp, *cur; | |
189 struct last_auto_response *lar; | |
190 | |
191 tmp = last_auto_responses; | |
192 | |
193 while (tmp) { | |
194 cur = tmp; | |
195 tmp = tmp->next; | |
196 lar = (struct last_auto_response *)cur->data; | |
197 | |
198 if ((time(NULL) - lar->sent) > | |
199 gaim_prefs_get_int("/core/away/auto_response/sec_before_resend")) { | |
200 | |
201 last_auto_responses = g_slist_remove(last_auto_responses, lar); | |
202 g_free(lar); | |
203 } | |
204 } | |
205 | |
206 return FALSE; /* do not run again */ | |
207 } | |
208 | |
209 struct last_auto_response *get_last_auto_response(GaimConnection *gc, const char *name) | |
210 { | |
211 GSList *tmp; | |
212 struct last_auto_response *lar; | |
213 | |
214 /* because we're modifying or creating a lar, schedule the | |
215 * function to expire them as the pref dictates */ | |
216 g_timeout_add((gaim_prefs_get_int("/core/away/auto_response/sec_before_resend") + 1) * 1000, | |
217 expire_last_auto_responses, NULL); | |
218 | |
219 tmp = last_auto_responses; | |
220 | |
221 while (tmp) { | |
222 lar = (struct last_auto_response *)tmp->data; | |
223 | |
224 if (gc == lar->gc && !strncmp(name, lar->name, sizeof(lar->name))) | |
225 return lar; | |
226 | |
227 tmp = tmp->next; | |
228 } | |
229 | |
230 lar = (struct last_auto_response *)g_new0(struct last_auto_response, 1); | |
231 g_snprintf(lar->name, sizeof(lar->name), "%s", name); | |
232 lar->gc = gc; | |
233 lar->sent = 0; | |
234 last_auto_responses = g_slist_append(last_auto_responses, lar); | |
235 | |
236 return lar; | |
237 } | |
238 | |
239 void flush_last_auto_responses(GaimConnection *gc) | |
240 { | |
241 GSList *tmp, *cur; | |
242 struct last_auto_response *lar; | |
243 | |
244 tmp = last_auto_responses; | |
245 | |
246 while (tmp) { | |
247 cur = tmp; | |
248 tmp = tmp->next; | |
249 lar = (struct last_auto_response *)cur->data; | |
250 | |
251 if (lar->gc == gc) { | |
252 last_auto_responses = g_slist_remove(last_auto_responses, lar); | |
253 g_free(lar); | |
254 } | |
255 } | |
256 } | |
185 | 257 |
186 int serv_send_im(GaimConnection *gc, const char *name, const char *message, | 258 int serv_send_im(GaimConnection *gc, const char *name, const char *message, |
187 int len, int flags) | 259 int len, int flags) |
188 { | 260 { |
189 GaimConversation *c; | 261 GaimConversation *c; |
200 | 272 |
201 if (!(flags & IM_FLAG_AWAY)) | 273 if (!(flags & IM_FLAG_AWAY)) |
202 serv_touch_idle(gc); | 274 serv_touch_idle(gc); |
203 | 275 |
204 if (gc->away && | 276 if (gc->away && |
205 !gaim_prefs_get_bool("/core/away/auto_response/in_active_conv") && | 277 (gc->flags & OPT_CONN_AUTO_RESP) && |
206 gaim_prefs_get_bool("/core/away/auto_response/enabled")) { | 278 gaim_prefs_get_bool("/core/away/auto_response/enabled") && |
207 | 279 !gaim_prefs_get_bool("/core/away/auto_response/in_active_conv")) { |
208 time_t t; | 280 |
209 struct queued_away_response *qar; | 281 struct last_auto_response *lar; |
210 time(&t); | 282 lar = get_last_auto_response(gc, name); |
211 qar = find_queued_away_response_by_name(name); | 283 lar->sent = time(NULL); |
212 if (!qar) { | |
213 qar = (struct queued_away_response *)g_new0(struct queued_away_response, 1); | |
214 g_snprintf(qar->name, sizeof(qar->name), "%s", name); | |
215 qar->sent_away = 0; | |
216 away_time_queue = g_slist_append(away_time_queue, qar); | |
217 } | |
218 qar->sent_away = t; | |
219 } | 284 } |
220 | 285 |
221 if (c && gaim_im_get_type_again_timeout(GAIM_IM(c))) | 286 if (c && gaim_im_get_type_again_timeout(GAIM_IM(c))) |
222 gaim_im_stop_type_again_timeout(GAIM_IM(c)); | 287 gaim_im_stop_type_again_timeout(GAIM_IM(c)); |
223 | 288 |
322 } | 387 } |
323 | 388 |
324 gaim_event_broadcast(event_away, gc, state, message); | 389 gaim_event_broadcast(event_away, gc, state, message); |
325 | 390 |
326 } | 391 } |
392 | |
393 /* New away message... Clear out the record of sent autoresponses */ | |
394 flush_last_auto_responses(gc); | |
327 | 395 |
328 system_log(log_away, gc, NULL, OPT_LOG_BUDDY_AWAY | OPT_LOG_MY_SIGNON); | 396 system_log(log_away, gc, NULL, OPT_LOG_BUDDY_AWAY | OPT_LOG_MY_SIGNON); |
329 } | 397 } |
330 | 398 |
331 void serv_set_away_all(const char *message) | 399 void serv_set_away_all(const char *message) |
712 | 780 |
713 templist = templist->next; | 781 templist = templist->next; |
714 } | 782 } |
715 | 783 |
716 return i; | 784 return i; |
717 } | |
718 | |
719 struct queued_away_response *find_queued_away_response_by_name(const char *name) | |
720 { | |
721 GSList *templist; | |
722 struct queued_away_response *qar; | |
723 | |
724 templist = away_time_queue; | |
725 | |
726 while (templist) { | |
727 qar = (struct queued_away_response *)templist->data; | |
728 | |
729 if (!strcmp(name, qar->name)) | |
730 return qar; | |
731 | |
732 templist = templist->next; | |
733 } | |
734 | |
735 return NULL; | |
736 } | 785 } |
737 | 786 |
738 /* | 787 /* |
739 * woo. i'm actually going to comment this function. isn't that fun. make | 788 * woo. i'm actually going to comment this function. isn't that fun. make |
740 * sure to follow along, kids | 789 * sure to follow along, kids |
824 * we're not. If we're not, then it's easy. If we are, then there | 873 * we're not. If we're not, then it's easy. If we are, then there |
825 * are three or four different ways of handling it and different | 874 * are three or four different ways of handling it and different |
826 * things we have to do for each. | 875 * things we have to do for each. |
827 */ | 876 */ |
828 if (gc->away) { | 877 if (gc->away) { |
829 time_t t; | 878 time_t t = time(NULL); |
830 char *tmpmsg; | 879 char *tmpmsg; |
831 struct buddy *b = gaim_find_buddy(gc->account, name); | 880 struct buddy *b = gaim_find_buddy(gc->account, name); |
832 char *alias = b ? gaim_get_buddy_alias(b) : name; | 881 char *alias = b ? gaim_get_buddy_alias(b) : name; |
833 int row; | 882 int row; |
834 struct queued_away_response *qar; | 883 struct last_auto_response *lar; |
835 | |
836 time(&t); | |
837 | 884 |
838 /* | 885 /* |
839 * Either we're going to queue it or not. Because of the way | 886 * Either we're going to queue it or not. Because of the way |
840 * awayness currently works, this is fucked up. It's possible | 887 * awayness currently works, this is fucked up. It's possible |
841 * for an account to be away without the imaway dialog being | 888 * for an account to be away without the imaway dialog being |
928 * you went away, and someone sent you a message and got your | 975 * you went away, and someone sent you a message and got your |
929 * auto-response, and then you closed the window, and then the | 976 * auto-response, and then you closed the window, and then the |
930 * sent you another one, they'd get the auto-response back too | 977 * sent you another one, they'd get the auto-response back too |
931 * soon. Besides that, we need to keep track of this even if we've | 978 * soon. Besides that, we need to keep track of this even if we've |
932 * got a queue. So the rest of this block is just the auto-response, | 979 * got a queue. So the rest of this block is just the auto-response, |
933 * if necessary | 980 * if necessary. |
934 */ | 981 */ |
935 qar = find_queued_away_response_by_name(name); | 982 lar = get_last_auto_response(gc, name); |
936 if (!qar) { | 983 if ((t - lar->sent) < |
937 qar = (struct queued_away_response *)g_new0(struct queued_away_response, 1); | |
938 g_snprintf(qar->name, sizeof(qar->name), "%s", name); | |
939 qar->sent_away = 0; | |
940 away_time_queue = g_slist_append(away_time_queue, qar); | |
941 } | |
942 if ((t - qar->sent_away) < | |
943 gaim_prefs_get_int("/core/away/auto_response/sec_before_resend")) { | 984 gaim_prefs_get_int("/core/away/auto_response/sec_before_resend")) { |
944 | 985 |
945 g_free(name); | 986 g_free(name); |
946 g_free(message); | 987 g_free(message); |
947 return; | 988 return; |
948 } | 989 } |
949 qar->sent_away = t; | 990 lar->sent = t; |
950 | 991 |
951 /* apply default fonts and colors */ | 992 /* apply default fonts and colors */ |
952 tmpmsg = stylize(gc->away, MSG_LEN); | 993 tmpmsg = stylize(gc->away, MSG_LEN); |
953 serv_send_im(gc, name, away_subs(tmpmsg, alias), -1, IM_FLAG_AWAY); | 994 serv_send_im(gc, name, away_subs(tmpmsg, alias), -1, IM_FLAG_AWAY); |
954 if (!cnv && awayqueue && | 995 if (!cnv && awayqueue && |