Permalink
Browse files

readd account alias support

Signed-off-by: xiehuc <xiehuc@gmail.com>
  • Loading branch information...
1 parent 5b8214e commit 2ba6314e1dee8838569eee2fc4e25ff67a63fd1f @xiehuc committed Dec 18, 2012
Showing with 61 additions and 43 deletions.
  1. +12 −0 src/liblwqq/async.h
  2. +19 −29 src/liblwqq/info.c
  3. +1 −2 src/liblwqq/info.h
  4. +18 −6 src/liblwqq/msg.c
  5. +11 −6 src/webqq.c
View
@@ -156,11 +156,23 @@ extern int LWQQ_ASYNC_GLOBAL_SYNC_ENABLED;
*
*/
struct _LwqqAsyncOption {
+ /**
+ * this is login complete .whatever successed or failed
+ * except need verify code
+ */
void (*login_complete)(LwqqClient* lc,LwqqErrorCode ec);
+ /* this is login complete when need verify code */
void (*login_verify)(LwqqClient* lc);
+ /* this is very important when poll message come */
void (*poll_msg)(LwqqClient* lc);
+ /* this is poll lost after recv retcode 112 or 108 */
void (*poll_lost)(LwqqClient* lc);
+ /* this is upload content failed such as lwqq offline pic */
void (*upload_fail)(LwqqClient* lc,const char* serv_id,struct LwqqMsgContent* c);
+ /* this is you confirmed a friend request
+ * you should add buddy to gui level.
+ */
+ void (*request_confirm)(LwqqClient* lc,LwqqBuddy* buddy);
};
void lwqq_async_dispatch(DISPATCH_FUNC dsph,CALLBACK_FUNC func , ...);
View
@@ -38,6 +38,7 @@ static int group_detail_back(LwqqHttpRequest* req,LwqqClient* lc,LwqqGroup* grou
static int info_commom_back(LwqqHttpRequest* req,void* data);
static int get_discu_list_back(LwqqHttpRequest* req,void* data);
static int get_discu_detail_info_back(LwqqHttpRequest* req,LwqqClient* lc,LwqqGroup* discu);
+static int get_friend_detail_back(LwqqHttpRequest* req,LwqqBuddy* buddy);
/**
@@ -1361,43 +1362,41 @@ static int get_qqnumber_back(LwqqHttpRequest* req,LwqqGroup* group,LwqqBuddy* bu
* @param buddy
* @param err
*/
-void lwqq_info_get_friend_detail_info(LwqqClient *lc, LwqqBuddy *buddy,
- LwqqErrorCode *err)
+LwqqAsyncEvent* lwqq_info_get_friend_detail_info(LwqqClient *lc, LwqqBuddy *buddy)
{
lwqq_log(LOG_DEBUG, "in function.");
char url[512];
LwqqHttpRequest *req = NULL;
- int ret;
- json_t *json = NULL, *json_tmp;
if (!lc || ! buddy) {
- return ;
+ return NULL;
}
/* Make sure we know uin. */
if (!buddy->uin) {
- if (err)
- *err = LWQQ_EC_NULL_POINTER;
- return ;
+ return NULL;
}
/* Create a GET request */
snprintf(url, sizeof(url),
"%s/api/get_friend_info2?tuin=%s&verifysession=&code=&vfwebqq=%s",
"http://s.web2.qq.com", buddy->uin, lc->vfwebqq);
- req = lwqq_http_create_default_request(lc,url, err);
- if (!req) {
- goto done;
- }
+ req = lwqq_http_create_default_request(lc,url, NULL);
req->set_header(req, "Referer", "http://s.web2.qq.com/proxy.html?v=20101025002");
req->set_header(req, "Content-Transfer-Encoding", "binary");
req->set_header(req, "Content-type", "utf-8");
req->set_header(req, "Cookie", lwqq_get_cookies(lc));
- ret = req->do_request(req, 0, NULL);
- if (ret || req->http_code != 200) {
- if (err)
- *err = LWQQ_EC_HTTP_ERROR;
+ return req->do_request_async(req, 0, NULL,_C_(2p_i,get_friend_detail_back,req,buddy));
+}
+
+static int get_friend_detail_back(LwqqHttpRequest* req,LwqqBuddy* buddy)
+{
+ json_t *json = NULL, *json_tmp;
+ int err = LWQQ_EC_OK;
+ int ret;
+ if (req->http_code != 200) {
+ err = LWQQ_EC_HTTP_ERROR;
goto done;
}
@@ -1416,15 +1415,15 @@ void lwqq_info_get_friend_detail_info(LwqqClient *lc, LwqqBuddy *buddy,
ret = json_parse_document(&json, req->response);
if (ret != JSON_OK) {
lwqq_log(LOG_ERROR, "Parse json object of groups error: %s\n", req->response);
- if (err)
- *err = LWQQ_EC_ERROR;
+ err = LWQQ_EC_ERROR;
goto done;
}
json_tmp = get_result_json_object(json);
if (!json_tmp) {
lwqq_log(LOG_ERROR, "Parse json object error: %s\n", req->response);
- goto json_error;
+ err = LWQQ_EC_ERROR;
+ goto done;
}
/** It seems everything is ok, we start parsing information
@@ -1469,20 +1468,11 @@ void lwqq_info_get_friend_detail_info(LwqqClient *lc, LwqqBuddy *buddy,
#undef SET_BUDDY_INFO
}
-
done:
if (json)
json_free_value(&json);
lwqq_http_request_free(req);
- return ;
-
-json_error:
- if (err)
- *err = LWQQ_EC_ERROR;
- /* Free temporary string */
- if (json)
- json_free_value(&json);
- lwqq_http_request_free(req);
+ return err;
}
static void update_online_buddies(LwqqClient *lc, json_t *json)
View
@@ -42,8 +42,7 @@ LwqqAsyncEvent* lwqq_info_get_discu_name_list(LwqqClient* lc);
* @param buddy
* @param err
*/
-void lwqq_info_get_friend_detail_info(LwqqClient *lc, LwqqBuddy *buddy,
- LwqqErrorCode *err);
+LwqqAsyncEvent* lwqq_info_get_friend_detail_info(LwqqClient *lc, LwqqBuddy *buddy);
/**
* Store QQ face to LwqqBuddy::avatar
* and save it possibly
View
@@ -616,6 +616,11 @@ static int parse_kick_message(json_t *json,void *opaque)
}
return 0;
}
+static void confirm_friend_request_notify(LwqqClient* lc,LwqqBuddy* buddy)
+{
+ LIST_INSERT_HEAD(&lc->friends,buddy,entries);
+ lc->async_opt->request_confirm(lc,buddy);
+}
static int parse_system_message(json_t *json,void* opaque,void* _lc)
{
LwqqMsgSystem* system = opaque;
@@ -644,10 +649,14 @@ static int parse_system_message(json_t *json,void* opaque,void* _lc)
LwqqBuddy* buddy = lwqq_buddy_new();
buddy->uin = s_strdup(system->from_uin);
buddy->cate_index = s_strdup(system->verify_pass.group_id);
- lwqq_info_get_friend_detail_info(lc,buddy,NULL);
- LIST_INSERT_HEAD(&lc->friends,buddy,entries);
- //this will raise FRIEND_COME and add target to gui level.
- lwqq_info_get_friend_qqnumber(lc,buddy);
+
+ LwqqAsyncEvset *set = lwqq_async_evset_new();
+ LwqqAsyncEvent *ev;
+ ev = lwqq_info_get_friend_detail_info(lc,buddy);
+ lwqq_async_evset_add_event(set,ev);
+ ev = lwqq_info_get_friend_qqnumber(lc,buddy);
+ lwqq_async_evset_add_event(set,ev);
+ lwqq_async_add_evset_listener(set,_C_(2p,confirm_friend_request_notify,lc,buddy));
}
return 0;
}
@@ -667,9 +676,12 @@ static int parse_blist_change(json_t* json,void* opaque,void* _lc)
buddy = lwqq_buddy_new();
buddy->uin = s_strdup(json_parse_simple_value(ptr,"uin"));
buddy->cate_index = s_strdup(json_parse_simple_value(ptr,"groupid"));
- lwqq_info_get_friend_detail_info(lc,buddy,NULL);
LIST_INSERT_HEAD(&lc->friends,buddy,entries);
- lwqq_info_get_friend_qqnumber(lc,buddy);
+ //note in here we didn't trigger request_confirm
+ //you should watch LwqqMsgBlistChange object and read
+ //simple buddy list.
+ //and get qqnumber by your self.
+ lwqq_info_get_friend_detail_info(lc,buddy);
ptr = ptr->next;
}
ptr = json_find_first_label_all(json,"removed_friends");
View
@@ -280,12 +280,11 @@ static void qq_set_status(PurpleAccount* account,PurpleStatus* status)
#define buddy_status(bu) ((bu->stat == LWQQ_STATUS_ONLINE && bu->client_type == LWQQ_CLIENT_MOBILE) \
? "mobile":lwqq_status_to_str(bu->stat))
-static int friend_come(LwqqClient* lc,void* data)
+static void friend_come(LwqqClient* lc,LwqqBuddy* buddy)
{
qq_account* ac = lwqq_client_userdata(lc);
ac->disable_send_server = 1;
PurpleAccount* account=ac->account;
- LwqqBuddy* buddy = data;
PurpleBuddy* bu = NULL;
LwqqFriendCategory* cate;
@@ -334,7 +333,6 @@ static int friend_come(LwqqClient* lc,void* data)
qq_account_insert_index_node(ac, NODE_IS_BUDDY, buddy);
ac->disable_send_server = 0;
- return 0;
}
static const char* group_name(LwqqGroup* group)
{
@@ -750,7 +748,8 @@ static void login_stage_f(LwqqClient* lc)
//we must put this here. avoid group_come stupid add duplicate group
purple_connection_set_state(purple_account_get_connection(ac->account),PURPLE_CONNECTED);
- purple_account_set_alias(ac->account,lc->myself->nick);
+ if(!purple_account_get_alias(ac->account))
+ purple_account_set_alias(ac->account,lc->myself->nick);
if(purple_buddy_icons_find_account_icon(ac->account)==NULL){
LwqqAsyncEvent* ev=lwqq_info_get_friend_avatar(lc,lc->myself);
lwqq_async_add_event_listener(ev,_C_(2p,friend_avatar,ac,lc->myself));
@@ -879,6 +878,7 @@ static void upload_content_fail(LwqqClient* lc,const char* serv_id,LwqqMsgConten
static LwqqAsyncOption qq_async_opt = {
.login_complete = login_stage_1,
.login_verify = verify_come,
+ .request_confirm = friend_come,
.poll_msg = qq_msg_check,
.poll_lost = lost_connection,
.upload_fail = upload_content_fail,
@@ -919,8 +919,13 @@ static void login_stage_2(LwqqClient* lc)
lwqq_async_evset_add_event(set,ev);
ev = lwqq_info_get_online_buddies(lc,NULL);
lwqq_async_evset_add_event(set,ev);
- //ev = lwqq_info_get_friend_detail_info(lc,lc->myself,NULL);
- //lwqq_async_evset_add_event(set,ev);
+
+ qq_account* ac = lwqq_client_userdata(lc);
+ const char* alias = purple_account_get_alias(ac->account);
+ if(alias == NULL){
+ ev = lwqq_info_get_friend_detail_info(lc,lc->myself);
+ lwqq_async_evset_add_event(set,ev);
+ }
lwqq_async_add_evset_listener(set,_C_(p,login_stage_f,lc));
}

0 comments on commit 2ba6314

Please sign in to comment.