Changeset 5969 for pjproject/trunk/pjsip/src/pjsua2/presence.cpp
- Timestamp:
- Apr 15, 2019 10:52:16 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua2/presence.cpp
r4704 r5969 74 74 75 75 ////////////////////////////////////////////////////////////////////////////// 76 typedef struct BuddyUserData 77 { 78 Buddy *self; 79 Account *acc; 80 } BuddyUserData; 76 81 77 82 /* … … 83 88 } 84 89 90 Buddy::Buddy(pjsua_buddy_id buddy_id) 91 : id(buddy_id) 92 { 93 } 94 95 Buddy *Buddy::getOriginalInstance() 96 { 97 BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 98 return (bud? bud->self : NULL); 99 } 100 85 101 /* 86 102 * Destructor. … … 88 104 Buddy::~Buddy() 89 105 { 90 if (isValid()) { 106 if (isValid() && getOriginalInstance()==this) { 107 Account *acc = NULL; 108 BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 109 if (bud) { 110 acc = bud->acc; 111 delete bud; 112 } 113 91 114 pjsua_buddy_set_user_data(id, NULL); 92 115 pjsua_buddy_del(id); 93 116 94 117 /* Remove from account buddy list */ 95 acc->removeBuddy(this); 118 if (acc) 119 acc->removeBuddy(this); 96 120 } 97 121 } … … 108 132 PJSUA2_RAISE_ERROR3(PJ_EINVAL, "Buddy::create()", "Invalid account"); 109 133 134 BuddyUserData *bud = new BuddyUserData(); 135 bud->self = this; 136 bud->acc = &account; 137 110 138 pj_cfg.uri = str2Pj(cfg.uri); 111 139 pj_cfg.subscribe = cfg.subscribe; 112 pj_cfg.user_data = (void*) this;140 pj_cfg.user_data = (void*)bud; 113 141 PJSUA2_CHECK_EXPR( pjsua_buddy_add(&pj_cfg, &id) ); 114 142 115 acc = &account; 116 acc->addBuddy(this); 143 account.addBuddy(this); 117 144 } 118 145 … … 161 188 { 162 189 BuddyInfo bi = getInfo(); 190 BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 191 Account *acc = bud? bud->acc : NULL; 192 193 if (!bud || !acc || !acc->isValid()) { 194 PJSUA2_RAISE_ERROR3(PJ_EINVAL, "sendInstantMessage()", 195 "Invalid Buddy"); 196 } 163 197 164 198 pj_str_t to = str2Pj(bi.contact.empty()? bi.uri : bi.contact); … … 180 214 { 181 215 BuddyInfo bi = getInfo(); 216 BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 217 Account *acc = bud? bud->acc : NULL; 218 219 if (!bud || !acc || !acc->isValid()) { 220 PJSUA2_RAISE_ERROR3(PJ_EINVAL, "sendInstantMessage()", 221 "Invalid Buddy"); 222 } 182 223 183 224 pj_str_t to = str2Pj(bi.contact.empty()? bi.uri : bi.contact);
Note: See TracChangeset
for help on using the changeset viewer.