comparison libpurple/protocols/qq/keep_alive.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents b258250b72c9
children b8572b937c09
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /** 1 /**
2 * @file keep_alive.c 2 * @file keep_alive.c
3 * 3 *
4 * gaim 4 * purple
5 * 5 *
6 * Gaim is the legal property of its developers, whose names are too numerous 6 * Purple is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this 7 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * source distribution. 8 * source distribution.
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
42 #include "utils.h" 42 #include "utils.h"
43 43
44 #define QQ_UPDATE_ONLINE_INTERVAL 300 /* in sec */ 44 #define QQ_UPDATE_ONLINE_INTERVAL 300 /* in sec */
45 45
46 /* send keep-alive packet to QQ server (it is a heart-beat) */ 46 /* send keep-alive packet to QQ server (it is a heart-beat) */
47 void qq_send_packet_keep_alive(GaimConnection *gc) 47 void qq_send_packet_keep_alive(PurpleConnection *gc)
48 { 48 {
49 qq_data *qd; 49 qq_data *qd;
50 guint8 *raw_data, *cursor; 50 guint8 *raw_data, *cursor;
51 51
52 qd = (qq_data *) gc->proto_data; 52 qd = (qq_data *) gc->proto_data;
60 60
61 qq_send_cmd(gc, QQ_CMD_KEEP_ALIVE, TRUE, 0, TRUE, raw_data, 4); 61 qq_send_cmd(gc, QQ_CMD_KEEP_ALIVE, TRUE, 0, TRUE, raw_data, 4);
62 } 62 }
63 63
64 /* parse the return of keep-alive packet, it includes some system information */ 64 /* parse the return of keep-alive packet, it includes some system information */
65 void qq_process_keep_alive_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 65 void qq_process_keep_alive_reply(guint8 *buf, gint buf_len, PurpleConnection *gc)
66 { 66 {
67 qq_data *qd; 67 qq_data *qd;
68 gint len; 68 gint len;
69 gchar **segments; 69 gchar **segments;
70 guint8 *data; 70 guint8 *data;
80 if (NULL == (segments = split_data(data, len, "\x1f", 6))) 80 if (NULL == (segments = split_data(data, len, "\x1f", 6)))
81 return; 81 return;
82 /* segments[0] and segment[1] are all 0x30 ("0") */ 82 /* segments[0] and segment[1] are all 0x30 ("0") */
83 qd->all_online = strtol(segments[2], NULL, 10); 83 qd->all_online = strtol(segments[2], NULL, 10);
84 if(0 == qd->all_online) 84 if(0 == qd->all_online)
85 gaim_connection_error(gc, _("Keep alive error, seems connection lost!")); 85 purple_connection_error(gc, _("Keep alive error, seems connection lost!"));
86 g_free(qd->my_ip); 86 g_free(qd->my_ip);
87 qd->my_ip = g_strdup(segments[3]); 87 qd->my_ip = g_strdup(segments[3]);
88 qd->my_port = strtol(segments[4], NULL, 10); 88 qd->my_port = strtol(segments[4], NULL, 10);
89 g_strfreev(segments); 89 g_strfreev(segments);
90 } else 90 } else
91 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt keep alive reply\n"); 91 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt keep alive reply\n");
92 92
93 /* we refresh buddies's online status periodically */ 93 /* we refresh buddies's online status periodically */
94 /* qd->last_get_online is updated when setting get_buddies_online packet */ 94 /* qd->last_get_online is updated when setting get_buddies_online packet */
95 if ((time(NULL) - qd->last_get_online) >= QQ_UPDATE_ONLINE_INTERVAL) 95 if ((time(NULL) - qd->last_get_online) >= QQ_UPDATE_ONLINE_INTERVAL)
96 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START); 96 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
97 } 97 }
98 98
99 /* refresh all buddies online/offline, 99 /* refresh all buddies online/offline,
100 * after receiving reply for get_buddies_online packet */ 100 * after receiving reply for get_buddies_online packet */
101 void qq_refresh_all_buddy_status(GaimConnection *gc) 101 void qq_refresh_all_buddy_status(PurpleConnection *gc)
102 { 102 {
103 time_t now; 103 time_t now;
104 GList *list; 104 GList *list;
105 qq_data *qd; 105 qq_data *qd;
106 qq_buddy *q_bud; 106 qq_buddy *q_bud;
119 list = list->next; 119 list = list->next;
120 } 120 }
121 } 121 }
122 122
123 /*TODO: maybe this should be qq_update_buddy_status() ?*/ 123 /*TODO: maybe this should be qq_update_buddy_status() ?*/
124 void qq_update_buddy_contact(GaimConnection *gc, qq_buddy *q_bud) 124 void qq_update_buddy_contact(PurpleConnection *gc, qq_buddy *q_bud)
125 { 125 {
126 gchar *name; 126 gchar *name;
127 GaimBuddy *bud; 127 PurpleBuddy *bud;
128 gchar *status_id; 128 gchar *status_id;
129 129
130 g_return_if_fail(q_bud != NULL); 130 g_return_if_fail(q_bud != NULL);
131 131
132 name = uid_to_gaim_name(q_bud->uid); 132 name = uid_to_purple_name(q_bud->uid);
133 bud = gaim_find_buddy(gc->account, name); 133 bud = purple_find_buddy(gc->account, name);
134 g_return_if_fail(bud != NULL); 134 g_return_if_fail(bud != NULL);
135 135
136 if (bud != NULL) { 136 if (bud != NULL) {
137 gaim_blist_server_alias_buddy(bud, q_bud->nickname); /* server */ 137 purple_blist_server_alias_buddy(bud, q_bud->nickname); /* server */
138 q_bud->last_refresh = time(NULL); 138 q_bud->last_refresh = time(NULL);
139 139
140 /* gaim supports signon and idle time 140 /* purple supports signon and idle time
141 * but it is not much use for QQ, I do not use them */ 141 * but it is not much use for QQ, I do not use them */
142 /* serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); */ 142 /* serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); */
143 status_id = "available"; 143 status_id = "available";
144 switch(q_bud->status) { 144 switch(q_bud->status) {
145 case QQ_BUDDY_OFFLINE: 145 case QQ_BUDDY_OFFLINE:
157 case QQ_BUDDY_ONLINE_INVISIBLE: 157 case QQ_BUDDY_ONLINE_INVISIBLE:
158 status_id = "invisible"; 158 status_id = "invisible";
159 break; 159 break;
160 default: 160 default:
161 status_id = "invisible"; 161 status_id = "invisible";
162 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown status: %x\n", q_bud->status); 162 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "unknown status: %x\n", q_bud->status);
163 break; 163 break;
164 } 164 }
165 gaim_debug(GAIM_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id); 165 purple_debug(PURPLE_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id);
166 gaim_prpl_got_user_status(gc->account, name, status_id, NULL); 166 purple_prpl_got_user_status(gc->account, name, status_id, NULL);
167 167
168 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE && q_bud->status != QQ_BUDDY_OFFLINE) 168 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE && q_bud->status != QQ_BUDDY_OFFLINE)
169 gaim_prpl_got_user_status(gc->account, name, "mobile", NULL); 169 purple_prpl_got_user_status(gc->account, name, "mobile", NULL);
170 else 170 else
171 gaim_prpl_got_user_status_deactive(gc->account, name, "mobile"); 171 purple_prpl_got_user_status_deactive(gc->account, name, "mobile");
172 } else { 172 } else {
173 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy: %d\n", q_bud->uid); 173 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "unknown buddy: %d\n", q_bud->uid);
174 } 174 }
175 175
176 gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_update_buddy_contact, client=%04x\n", q_bud->client_version); 176 purple_debug(PURPLE_DEBUG_INFO, "QQ", "qq_update_buddy_contact, client=%04x\n", q_bud->client_version);
177 g_free(name); 177 g_free(name);
178 } 178 }