lwqq_change_status(boost::shared_ptr<qqimpl::WebQQ> webqq, LWQQ_STATUS status, boost::function<void (boost::system::error_code) > handler) : m_webqq(webqq), m_handler(handler) { std::string msg = boost::str( boost::format( "{\"status\":\"%s\",\"ptwebqq\":\"%s\"," "\"passwd_sig\":""\"\",\"clientid\":\"%s\"" ", \"psessionid\": \"%s\"}" ) % lwqq_status_to_str( LWQQ_STATUS_ONLINE ) % m_webqq->m_cookies.ptwebqq % m_webqq->m_clientid % (m_webqq->m_psessionid.empty() ? std::string("null") : m_webqq->m_psessionid) ); msg = boost::str( boost::format( "r=%s" ) % boost::url_encode(msg) ); stream.reset( new avhttp::http_stream( m_webqq->get_ioservice() ) ); stream->request_options( avhttp::request_opts() ( avhttp::http_options::request_method, "POST" ) ( avhttp::http_options::cookie, m_webqq->m_cookies.lwcookies ) ( avhttp::http_options::referer, "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2" ) ( avhttp::http_options::content_type, "application/x-www-form-urlencoded; charset=UTF-8" ) ( avhttp::http_options::request_body, msg ) ( avhttp::http_options::content_length, boost::lexical_cast<std::string>( msg.length() ) ) ( avhttp::http_options::connection, "close" ) ); buf = boost::make_shared<boost::asio::streambuf>(); avhttp::async_read_body(* stream, LWQQ_URL_SET_STATUS , * buf, * this ); }
static void login_stage_5(LwqqAsyncEvent* ev) { if(lwqq_async_event_get_code(ev) == LWQQ_CALLBACK_FAILED) return; int err = lwqq_async_event_get_result(ev); LwqqClient* lc = lwqq_async_event_get_owner(ev); if(!lwqq_client_valid(lc)) return; /* Free old value */ if(err != LWQQ_EC_OK){ lc->async_opt->login_complete(lc,err); } LwqqAsyncEvent* event = set_online_status(lc, lwqq_status_to_str(lc->stat)); lwqq_async_add_event_listener(event,_C_(p,login_stage_f,event)); }
static void login_stage_5(LwqqAsyncEvent* ev,LwqqErrorCode* ec) { if(lwqq_async_event_get_code(ev) == LWQQ_CALLBACK_FAILED) return; int err = lwqq_async_event_get_result(ev); if(ec)(*ec=err); LwqqClient* lc = lwqq_async_event_get_owner(ev); if(!lwqq_client_valid(lc)) return; /* Free old value */ if(err != LWQQ_EC_OK){ lc->stat = LWQQ_STATUS_LOGOUT; lc->args->login_ec = err; vp_do_repeat(lc->events->login_complete, NULL); return; } LwqqAsyncEvent* event = set_online_status(lc, lwqq_status_to_str(lc->stat)); lwqq_async_add_event_listener(event,_C_(2p,login_stage_f,event,ec)); }
change_status_op(boost::shared_ptr<qqimpl::WebQQ> webqq, LWQQ_STATUS status, Handler handler) : m_webqq(webqq), m_handler(handler) { std::stringstream post_val_r; boost::property_tree::ptree r; r.put("status", lwqq_status_to_str( LWQQ_STATUS_ONLINE )); avhttp::cookies cookies = m_webqq->m_cookie_mgr.get_cookie(LWQQ_URL_SET_STATUS); r.put("ptwebqq", cookies["ptwebqq"]); r.put("clientid", m_webqq->m_clientid); if (m_webqq->m_psessionid.empty()) r.put_child("psessionid", boost::property_tree::ptree()); else r.put("psessionid", m_webqq->m_psessionid); boost::property_tree::json_parser::write_json(post_val_r , r); std::string msg = boost::str( boost::format( "r=%s" ) % avhttp::detail::escape_string(post_val_r.str()) ); stream.reset( new avhttp::http_stream( m_webqq->get_ioservice() ) ); stream->http_cookies(cookies); stream->request_options( avhttp::request_opts() ( avhttp::http_options::request_method, "POST" ) ( avhttp::http_options::referer, "http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2") ( avhttp::http_options::content_type, "application/x-www-form-urlencoded; charset=UTF-8" ) ( avhttp::http_options::request_body, msg ) ( avhttp::http_options::content_length, boost::lexical_cast<std::string>( msg.length() ) ) ( avhttp::http_options::connection, "close" ) ); buf = boost::make_shared<boost::asio::streambuf>(); avhttp::async_read_body(* stream, LWQQ_URL_SET_STATUS , * buf, * this ); }
const char* qq_status_to_str(LwqqStatus status) { if(status == LWQQ_STATUS_ONLINE) return "available"; return lwqq_status_to_str(status); }
LWQQ_EXPORT LwqqAsyncEvent* lwqq_relink(LwqqClient* lc) { if(!lc) return NULL; char url[128]; char post[512]; if(!lc->new_ptwebqq){ lc->new_ptwebqq = lwqq_http_get_cookie(lwqq_get_http_handle(lc), "ptwebqq"); } snprintf(url, sizeof(url), "%s/channel/login2",WEBQQ_D_HOST); snprintf(post, sizeof(post), "r={\"status\":\"%s\",\"ptwebqq\":\"%s\",\"passwd_sig\":\"\",\"clientid\":\"%s\",\"psessionid\":\"%s\"}",lwqq_status_to_str(lc->stat),lc->new_ptwebqq,lc->clientid,lc->psessionid); LwqqHttpRequest* req = lwqq_http_create_default_request(lc, url, NULL); req->set_header(req,"Referer",WEBQQ_D_REF_URL); lwqq_http_set_cookie(req, "ptwebqq", lc->new_ptwebqq); req->retry = 0; return req->do_request_async(req,lwqq__has_post(),_C_(p_i,process_login2,req)); }
LwqqAsyncEvent* lwqq_relogin(LwqqClient* lc) { if(!lc) return NULL; char url[128]; char post[512]; if(!lc->new_ptwebqq) lc->new_ptwebqq = s_strdup(lc->cookies->ptwebqq); snprintf(url, sizeof(url), WEBQQ_D_HOST"/channel/login2"); snprintf(post, sizeof(post), "r={\"status\":\"%s\",\"ptwebqq\":\"%s\",\"passwd_sig\":\"\",\"clientid\":\"%s\",\"psessionid\":\"%s\"}",lwqq_status_to_str(lc->stat),lc->new_ptwebqq,lc->clientid,lc->psessionid); lwqq_verbose(3,"%s\n",url); lwqq_verbose(3,"%s\n",post); LwqqHttpRequest* req = lwqq_http_create_default_request(lc, url, NULL); req->set_header(req,"Referer",WEBQQ_D_REF_URL); lwqq_set_cookie(lc->cookies, "ptwebqq", lc->new_ptwebqq); req->set_header(req,"Cookie",lwqq_get_cookies(lc)); return req->do_request_async(req,1,post,_C_(p_i,process_login2,req)); }