Changeset 661
- Timestamp:
- 12/29/05 22:40:16 (3 years ago)
- Files:
-
- trunk/src/presence.c (modified) (6 diffs)
- trunk/src/users.c (modified) (8 diffs)
- trunk/src/users.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/presence.c
r659 r661 235 235 if (jid_is_me(to)){ 236 236 debug(L_("Presence subscribe request sent to me")); 237 if (!u) presence_send_unsubscribed(stream,to,from); 238 else presence_send_subscribed(stream,to,from); 237 if (!u) { 238 presence_send_unsubscribed(stream,to,from); 239 return 0; 240 } 241 presence_send_subscribed(stream,to,from); 242 if (u->subscribe==SUB_UNDEFINED || u->subscribe==SUB_NONE) u->subscribe=SUB_TO; 243 else if (u->subscribe==SUB_FROM) u->subscribe=SUB_BOTH; 244 if (u->subscribe!=SUB_FROM && u->subscribe!=SUB_BOTH){ 245 presence_send_subscribe(stream,to,from); 246 } 247 user_save(u); 239 248 return 0; 240 249 } … … 264 273 presence_send_subscribed(stream,to,from); 265 274 bare=jid_normalized(from,FALSE); 266 presence_send_subscribe(stream,to,bare); 275 if (c->subscribe!=SUB_FROM && c->subscribe!=SUB_BOTH) { 276 presence_send_subscribe(stream,to,bare); 277 } 267 278 g_free(bare); 268 279 return 0; … … 282 293 } 283 294 if (jid_is_me(to)){ 295 if (u->subscribe==SUB_NONE) u->subscribe=SUB_FROM; 296 else if (u->subscribe==SUB_UNDEFINED || u->subscribe==SUB_TO) u->subscribe=SUB_BOTH; 297 user_save(u); 284 298 debug(L_("Presence 'subscribed' sent to me")); 285 299 return 0; … … 317 331 } 318 332 if (jid_is_me(to)){ 333 if (u->subscribe==SUB_FROM) u->subscribe=SUB_NONE; 334 else if (u->subscribe==SUB_BOTH || c->subscribe==SUB_UNDEFINED) u->subscribe=SUB_TO; 335 user_save(u); 319 336 debug(L_("Presence 'unsubscribed' sent to me")); 320 337 return 0; … … 347 364 if (jid_is_me(to)){ 348 365 debug(L_("Presence unsubscribe request sent to me")); 366 if (u->subscribe==SUB_TO || c->subscribe==SUB_UNDEFINED) u->subscribe=SUB_NONE; 367 else if (u->subscribe==SUB_BOTH) u->subscribe=SUB_FROM; 368 user_save(u); 349 369 presence_send_unsubscribed(stream,to,from); 350 370 return 0; … … 373 393 374 394 if (s) session_update_contact(s,c); 375 376 395 377 396 debug(L_("Unsubscribed.")); trunk/src/users.c
r659 r661 30 30 #include "presence.h" 31 31 #include "conf.h" 32 #include "encoding.h" 32 33 #include "debug.h" 33 34 … … 126 127 } 127 128 129 static void set_subscribe(xmlnode node, SubscriptionType subscription) { 130 131 switch (subscription){ 132 case SUB_NONE: 133 xmlnode_put_attrib(node,"subscribe","none"); 134 break; 135 case SUB_FROM: 136 xmlnode_put_attrib(node,"subscribe","from"); 137 break; 138 case SUB_TO: 139 xmlnode_put_attrib(node,"subscribe","to"); 140 break; 141 case SUB_BOTH: 142 xmlnode_put_attrib(node,"subscribe","both"); 143 break; 144 default: 145 break; 146 } 147 } 128 148 129 149 int user_save(User *u){ … … 162 182 tag=xmlnode_insert_tag(xml,"jid"); 163 183 xmlnode_insert_cdata(tag,u->jid,-1); 184 set_subscribe(tag, u->subscribe); 164 185 tag=xmlnode_insert_tag(xml,"uin"); 165 186 str=g_strdup_printf("%lu",(unsigned long)u->uin); … … 200 221 if (c->ignored) xmlnode_put_attrib(ctag,"ignored","ignored"); 201 222 if (c->blocked) xmlnode_put_attrib(ctag,"blocked","blocked"); 202 switch (c->subscribe){ 203 case SUB_NONE: 204 xmlnode_put_attrib(ctag,"subscribe","none"); 205 break; 206 case SUB_FROM: 207 xmlnode_put_attrib(ctag,"subscribe","from"); 208 break; 209 case SUB_TO: 210 xmlnode_put_attrib(ctag,"subscribe","to"); 211 break; 212 case SUB_BOTH: 213 xmlnode_put_attrib(ctag,"subscribe","both"); 214 break; 215 default: 216 break; 217 } 223 set_subscribe(ctag, c->subscribe); 218 224 g_free(str); 219 225 } … … 256 262 } 257 263 264 static SubscriptionType get_subscribe(xmlnode node, unsigned int file_format_version){ 265 char *tmp; 266 267 tmp=xmlnode_get_attrib(node,"subscribe"); 268 if (tmp) { 269 switch (tmp[0]) { 270 case 'f': 271 return SUB_FROM; 272 break; 273 case 't': 274 /* version 2.2.0 has a bug which causes 275 * SUB_BOTH to be changed to SUB_TO 276 * this will force resynchronisation with 277 * user's roster. User will be asked for 278 * subscription authorisation if the 279 * subscription was really "to" 280 */ 281 if (file_format_version<=0x02020000) return SUB_UNDEFINED; 282 else return SUB_TO; 283 break; 284 case 'b': 285 return SUB_BOTH; 286 break; 287 default: 288 return SUB_NONE; 289 break; 290 } 291 } 292 return SUB_UNDEFINED; 293 } 294 258 295 User *user_load(const char *jid){ 259 296 char *fn,*njid; … … 263 300 int last_sys_msg=0,invisible=0,friends_only=0,ignore_unknown=0; 264 301 unsigned int file_format_version=0; 302 SubscriptionType subscribe; 265 303 User *u; 266 304 GList *contacts; … … 283 321 } 284 322 g_free(fn); 323 tag=xmlnode_get_tag(xml,"version"); 324 if (tag!=NULL) { 325 p=xmlnode_get_attrib(tag,"file_format"); 326 if (p!=NULL) file_format_version=(unsigned int)strtol(p,NULL,16); 327 } 285 328 tag=xmlnode_get_tag(xml,"jid"); 286 329 if (tag!=NULL) { 287 p=xmlnode_get_data(tag); 288 if (p!=NULL) file_format_version=(unsigned int)strtol(p,NULL,16); 289 } 290 tag=xmlnode_get_tag(xml,"jid"); 291 if (tag!=NULL) ujid=xmlnode_get_data(tag); 330 ujid=xmlnode_get_data(tag); 331 subscribe=get_subscribe(tag, file_format_version); 332 } 292 333 if (ujid==NULL){ 293 334 g_warning(L_("Couldn't find JID in %s's file"),jid); … … 375 416 if (d!=NULL && d[0]!='\000') c->blocked=1; 376 417 else c->blocked=0; 377 d=xmlnode_get_attrib(t,"subscribe"); 378 if (d) { 379 switch (d[0]) { 380 case 'f': 381 c->subscribe=SUB_FROM; 382 break; 383 case 't': 384 /* version 2.2.0 has a bug which causes 385 * SUB_BOTH to be changed to SUB_TO 386 * this will force resynchronisation with 387 * user's roster. User will be asked for 388 * subscription authorisation if the 389 * subscription was really "to" 390 */ 391 if (file_format_version<=0x02020000) c->subscribe=SUB_UNDEFINED; 392 else c->subscribe=SUB_TO; 393 break; 394 case 'b': 395 c->subscribe=SUB_BOTH; 396 break; 397 default: 398 c->subscribe=SUB_NONE; 399 break; 400 } 401 } 402 else c->subscribe=SUB_UNDEFINED; 418 c->subscribe=get_subscribe(t, file_format_version); 403 419 contacts=g_list_append(contacts,c); 404 420 } trunk/src/users.h
r659 r661 23 23 #include <libgadu.h> 24 24 25 #define USER_FILE_FORMAT_VERSION 0x02020 001U /* first change after 2.2.0*/25 #define USER_FILE_FORMAT_VERSION 0x02020101U /* first change after 2.2.1 */ 26 26 27 27 typedef enum subscription_type_e { … … 62 62 char *locale; 63 63 char * status; 64 SubscriptionType subscribe; 64 65 65 66 int confirmed;
