libgaim/protocols/qq/sendqueue.c

changeset 15314
9ddca9af9490
parent 15087
78879d4adf13
child 15333
1220b92e8b11
equal deleted inserted replaced
15313:b6ae2956a561 15314:9ddca9af9490
76 i++; 76 i++;
77 } 77 }
78 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d packets in sendqueue are freed!\n", i); 78 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d packets in sendqueue are freed!\n", i);
79 } 79 }
80 80
81 /* packet lost, agree to send again, (and will NOT prompt again) 81 /* packet lost, agree to send again.
82 * it is removed only when ack-ed by server */ 82 * it is removed only when ack-ed by server */
83 static void _qq_send_again(gc_and_packet *gp) 83 static void _qq_send_again(gc_and_packet *gp)
84 { 84 {
85 GaimConnection *gc; 85 GaimConnection *gc;
86 qq_data *qd; 86 qq_data *qd;
123 qq_sendqueue_remove(qd, packet->send_seq); 123 qq_sendqueue_remove(qd, packet->send_seq);
124 124
125 g_free(gp); 125 g_free(gp);
126 } 126 }
127 127
128 static void _notify_packets_lost(GaimConnection *gc, const gchar *msg, qq_sendpacket *p)
129 {
130 gc_and_packet *gp;
131
132 gp = g_new0(gc_and_packet, 1);
133 gp->gc = gc;
134 gp->packet = p;
135 gaim_request_action
136 (gc, NULL, _("Communication timed out"), msg,
137 0, gp, 2, _("Try again"), G_CALLBACK(_qq_send_again),
138 _("Cancel"), G_CALLBACK(_qq_send_cancel));
139 /* keep in sendqueue doing nothing until we hear back from the user */
140 p->resend_times++;
141 }
142
128 gboolean qq_sendqueue_timeout_callback(gpointer data) 143 gboolean qq_sendqueue_timeout_callback(gpointer data)
129 { 144 {
130 GaimConnection *gc; 145 GaimConnection *gc;
131 qq_data *qd; 146 qq_data *qd;
132 GList *list; 147 GList *list;
133 qq_sendpacket *p; 148 qq_sendpacket *p;
134 gc_and_packet *gp;
135 time_t now; 149 time_t now;
136 gint wait_time; 150 gint wait_time;
137 gboolean need_action;
138 151
139 gc = (GaimConnection *) data; 152 gc = (GaimConnection *) data;
140 qd = (qq_data *) gc->proto_data; 153 qd = (qq_data *) gc->proto_data;
141 now = time(NULL); 154 now = time(NULL);
142 list = qd->sendqueue; 155 list = qd->sendqueue;
164 if (p->resend_times == QQ_RESEND_MAX) { /* reach max */ 177 if (p->resend_times == QQ_RESEND_MAX) { /* reach max */
165 switch (p->cmd) { 178 switch (p->cmd) {
166 case QQ_CMD_KEEP_ALIVE: 179 case QQ_CMD_KEEP_ALIVE:
167 if (qd->logged_in) { 180 if (qd->logged_in) {
168 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection lost!\n"); 181 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection lost!\n");
169 gaim_connection_error(gc, _("Connection lost!")); 182 gaim_connection_error(gc, _("Connection lost"));
170 qd->logged_in = FALSE; 183 qd->logged_in = FALSE;
171 } 184 }
172 p->resend_times = -1; 185 p->resend_times = -1;
173 break; 186 break;
174 case QQ_CMD_LOGIN: 187 case QQ_CMD_LOGIN:
188 case QQ_CMD_REQUEST_LOGIN_TOKEN:
175 if (!qd->logged_in) /* cancel logging progress */ 189 if (!qd->logged_in) /* cancel logging progress */
176 gaim_connection_error(gc, _("Login failed, no reply!")); 190 gaim_connection_error(gc, _("Login failed, no reply"));
177 p->resend_times = -1; 191 p->resend_times = -1;
178 break; 192 break;
179 case QQ_CMD_UPDATE_INFO: 193 case QQ_CMD_UPDATE_INFO:
180 gaim_notify_error(gc, NULL, 194 _notify_packets_lost(gc,
181 _("Connection timeout!"), _("User info is not updated")); 195 _("Your attempt to update your info has timed out. Send the information again?"), p);
182 p->resend_times = -1; 196 break;
197 case QQ_CMD_GET_USER_INFO:
198 _notify_packets_lost(gc,
199 _("Your attempt to view a user's info has timed out. Try again?"), p);
200 break;
201 case QQ_CMD_ADD_FRIEND_WO_AUTH:
202 _notify_packets_lost(gc,
203 _("Your attempt to add a buddy has timed out. Try again?"), p);
204 break;
205 case QQ_CMD_DEL_FRIEND:
206 _notify_packets_lost(gc,
207 _("Your attempt to remove a buddy has timed out. Try again?"), p);
208 break;
209 case QQ_CMD_BUDDY_AUTH:
210 _notify_packets_lost(gc,
211 _("Your attempt to add a buddy has timed out. Try again?"), p);
212 break;
213 case QQ_CMD_CHANGE_ONLINE_STATUS:
214 _notify_packets_lost(gc,
215 _("Your attempt to change your online status has timed out. Send the information again?"), p);
216 break;
217 case QQ_CMD_SEND_IM:
218 _notify_packets_lost(gc,
219 _("Your attempt to send an IM has timed out. Send it again?"), p);
220 break;
221 case QQ_CMD_REQUEST_KEY:
222 _notify_packets_lost(gc,
223 _("Your request for a file transfer key has timed out. Request it again?"), p);
183 break; 224 break;
184 default:{ 225 default:{
185 need_action = 226 p->resend_times = -1; /* it will be removed next time */
186 gaim_prefs_get_bool("/plugins/prpl/qq/prompt_for_missing_packet"); 227 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "%s packet lost!\n", qq_get_cmd_desc(p->cmd));
187 if (!need_action)
188 p->resend_times = -1; /* it will be removed next time */
189 else { /* prompt for action */
190 gp = g_new0(gc_and_packet, 1);
191 gp->gc = gc;
192 gp->packet = p;
193 gaim_request_action
194 (gc, NULL,
195 _
196 ("Send packet"),
197 _
198 ("Packets lost, send again?"),
199 0, gp, 2,
200 _("Send"),
201 G_CALLBACK
202 (_qq_send_again),
203 _("Cancel"), G_CALLBACK(_qq_send_cancel));
204 /* will send once more, but only once */
205 p->resend_times++;
206 }
207 } 228 }
208 } 229 }
209 } 230 }
210 } else { /* resend_times < QQ_RESEND_MAX, so sent it again */ 231 } else { /* resend_times < QQ_RESEND_MAX, so sent it again */
211 wait_time = (gint) (QQ_SENDQUEUE_TIMEOUT / 1000); 232 wait_time = (gint) (QQ_SENDQUEUE_TIMEOUT / 1000);

mercurial