LwqqStatus qq_status_from_str(const char* str) { if (str == NULL) return LWQQ_STATUS_LOGOUT; if (strcmp(str, "available") == 0) return LWQQ_STATUS_ONLINE; return lwqq_status_from_str(str); }
static int set_online_status_back(LwqqHttpRequest* req) { int err = LWQQ_EC_OK; int ret; char* response; char* value; json_t * json = NULL; LwqqClient* lc = req->lc; if(!lwqq_client_valid(lc)){ err = LWQQ_EC_ERROR; goto done; } if (req->http_code != 200) { err = LWQQ_EC_HTTP_ERROR; goto done; } /** * Here, we got a json object like this: * {"retcode":0,"result":{"uin":1421032531,"cip":2013211875,"index":1060,"port":43415,"status":"online","vfwebqq":"e7ce7913336ad0d28de9cdb9b46a57e4a6127161e35b87d09486001870226ec1fca4c2ba31c025c7","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3133332e34312e32303200006b2900001544016e0400533cb3546d0000000a4046674d4652585136496d00000028e7ce7913336ad0d28de9cdb9b46a57e4a6127161e35b87d09486001870226ec1fca4c2ba31c025c7","user_state":0,"f":0}} * */ response = req->response; lwqq_verbose(3,"%s\n",response); ret = json_parse_document(&json, response); if (ret != JSON_OK) { err = LWQQ_EC_ERROR; goto done; } if (!(value = json_parse_simple_value(json, "retcode"))) { err = LWQQ_EC_ERROR; goto done; } /** * Do we need parse "seskey? from kernelhcy's code, we need it, * but from the response we got like above, we dont need * */ lwqq__override(lc->seskey,lwqq__json_get_value(json,"seskey")); lwqq__override(lc->cip,lwqq__json_get_value(json,"cip")); lwqq__override(lc->myself->uin,lwqq__json_get_value(json,"uin")); lwqq__override(lc->index,lwqq__json_get_value(json,"index")); lwqq__override(lc->port,lwqq__json_get_value(json,"port")); lwqq__override(lc->vfwebqq,lwqq__json_get_value(json,"vfwebqq")); lwqq__override(lc->psessionid,lwqq__json_get_value(json,"psessionid")); lc->stat = lwqq_status_from_str( json_parse_simple_value(json, "status")); err = LWQQ_EC_OK; done: if (json) json_free_value(&json); lwqq_http_request_free(req); return err; }
static int process_login2(LwqqHttpRequest* req) { /* * {"retcode":0,"result":{"uin":2501542492,"cip":3396791469,"index":1075,"port":49648,"status":"online","vfwebqq":"8e6abfdb20f9436be07e652397a1197553f49fabd3e67fc88ad7ee4de763f337e120fdf7036176c9","psessionid":"8368046764001d636f6e6e7365727665725f77656271714031302e3133392e372e31363000003bce00000f8a026e04005c821a956d0000000a407646664c41737a42416d000000288e6abfdb20f9436be07e652397a1197553f49fabd3e67fc88ad7ee4de763f337e120fdf7036176c9","user_state":0,"f":0}} */ int err = 0; LwqqClient* lc = req->lc; json_t* root = NULL,*result; lwqq__jump_if_http_fail(req,err); lwqq__jump_if_json_fail(root,req->response,err); result = lwqq__parse_retcode_result(root, &err); switch(err){ case 0: lwqq_puts("[ReLinkSuccess]"); break; case 103: lwqq_puts("[Not Relogin]"); vp_do_repeat(lc->events->poll_lost, NULL); goto done; case 113: case 115: case 112: lwqq_puts("[RelinkFailure]"); vp_do_repeat(lc->events->poll_lost, NULL); goto done; default: lwqq_puts("[RelinkStop]"); vp_do_repeat(lc->events->poll_lost, NULL); goto done; } if(result){ lwqq_override(lc->cip,lwqq__json_get_value(result,"cip")); lwqq_override(lc->index,lwqq__json_get_value(result,"index")); lwqq_override(lc->port,lwqq__json_get_value(result,"port")); lwqq_override(lc->psessionid,lwqq__json_get_value(result,"psessionid")); lwqq_override(lc->vfwebqq,lwqq__json_get_value(result,"vfwebqq")); lc->stat = lwqq_status_from_str(json_parse_simple_value(result, "status")); } done: lwqq__log_if_error(err, req); lwqq__clean_json_and_req(root,req); return err; }
static void* _background_login(void* data) { qq_account* ac=(qq_account*)data; if(!qq_account_valid(ac)) return NULL; LwqqClient* lc = ac->qq; LwqqErrorCode err; //it would raise a invalid ac when wake up from sleep. //it would login twice,why? //so what i can do is disable the invalid one. if(!lwqq_client_valid(lc)) return NULL; const char* status = purple_status_get_id(purple_account_get_active_status(ac->account)); lwqq_login(lc,lwqq_status_from_str(status), &err); if (err == LWQQ_EC_LOGIN_NEED_VC) { lc->dispatch(vp_func_pi,(CALLBACK_FUNC)extra_async_opt.need_verify,lc,err); }else{ lc->dispatch(vp_func_pi,(CALLBACK_FUNC)extra_async_opt.login_complete,lc,err); } return NULL; }
static int set_online_status_back(LwqqHttpRequest* req) { int err = 0; LwqqClient* lc = req->lc; json_t* root = NULL,*result; lwqq__jump_if_http_fail(req,err); lwqq__jump_if_json_fail(root,req->response,err); result = lwqq__parse_retcode_result(root, &err); if(err) goto done; if(result){ lwqq_override(lc->seskey,lwqq__json_get_value(result,"seskey")); lwqq_override(lc->cip,lwqq__json_get_value(result,"cip")); lwqq_override(lc->myself->uin,lwqq__json_get_value(result,"uin")); lwqq_override(lc->index,lwqq__json_get_value(result,"index")); lwqq_override(lc->port,lwqq__json_get_value(result,"port")); lwqq_override(lc->psessionid,lwqq__json_get_value(result,"psessionid")); lwqq_override(lc->vfwebqq,lwqq__json_get_value(result,"vfwebqq")); lc->stat = lwqq_status_from_str(json_parse_simple_value(result, "status")); } done: lwqq__log_if_error(err, req); lwqq__clean_json_and_req(root,req); return err; }
static int process_login2(LwqqHttpRequest* req) { /* * {"retcode":0,"result":{"uin":2501542492,"cip":3396791469,"index":1075,"port":49648,"status":"online","vfwebqq":"8e6abfdb20f9436be07e652397a1197553f49fabd3e67fc88ad7ee4de763f337e120fdf7036176c9","psessionid":"8368046764001d636f6e6e7365727665725f77656271714031302e3133392e372e31363000003bce00000f8a026e04005c821a956d0000000a407646664c41737a42416d000000288e6abfdb20f9436be07e652397a1197553f49fabd3e67fc88ad7ee4de763f337e120fdf7036176c9","user_state":0,"f":0}} */ int err = 0; LwqqClient* lc = req->lc; json_t* root = NULL,*result; lwqq__jump_if_http_fail(req,err); lwqq__jump_if_json_fail(root,req->response,err); result = lwqq__parse_retcode_result(root, &err); if(err!=WEBQQ_OK) goto done; if(result){ lwqq__override(lc->cip,lwqq__json_get_value(result,"cip")); lwqq__override(lc->index,lwqq__json_get_value(result,"index")); lwqq__override(lc->port,lwqq__json_get_value(result,"port")); lwqq__override(lc->psessionid,lwqq__json_get_value(result,"psessionid")); lc->stat = lwqq_status_from_str(json_parse_simple_value(result, "status")); lwqq__override(lc->vfwebqq,lwqq__json_get_value(result,"vfwebqq")); } done: lwqq__clean_json_and_req(root,req); return err; }