Exemplo n.º 1
0
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));
}
Exemplo n.º 2
0
Arquivo: lwjs.c Projeto: HenryHu/lwqq
static void report_error(JSContext* cx, const char* message,
                         JSErrorReport* report)
{
   lwqq_verbose(3, "%s:%u:%s\n",
                report->filename ? report->filename : "<no filename>",
                (unsigned int)report->lineno, message);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
static LwqqAsyncEvent* get_verify_code(LwqqClient *lc,const char* appid)
{
    LwqqHttpRequest *req;
    char url[512];
    char chkuin[64];

    snprintf(url, sizeof(url), WEBQQ_CHECK_HOST"/check?uin=%s&appid=%s",
             lc->username, appid);
    req = lwqq_http_create_default_request(lc,url,NULL);
    lwqq_verbose(3,"%s\n",url);
    
    snprintf(chkuin, sizeof(chkuin), "chkuin=%s", lc->username);
    req->set_header(req, "Cookie", chkuin);
    return req->do_request_async(req, 0, NULL,_C_(p_i,get_verify_code_back,req));
}
Exemplo n.º 5
0
/** 
 * Do really login
 * 
 * @param lc 
 * @param md5 The md5 calculated from calculate_password_md5() 
 * @param err 
 */
static LwqqAsyncEvent* do_login(LwqqClient *lc, const char *md5, LwqqErrorCode *err)
{
    char url[1024];
    LwqqHttpRequest *req;
    
    snprintf(url, sizeof(url), WEBQQ_LOGIN_HOST"/login?"
            "u=%s&p=%s&verifycode=%s&"
             "webqq_type=%d&remember_uin=1&aid=1003903&login2qq=1&"
             "u1=http%%3A%%2F%%2Fweb.qq.com%%2Floginproxy.html"
             "%%3Flogin2qq%%3D1%%26webqq_type%%3D10&h=1&ptredirect=0&"
             "ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert&"
             "action=2-11-7438&mibao_css=m_webqq&t=1&g=1",  lc->username, md5, lc->vc->str,lc->stat);

    req = lwqq_http_create_default_request(lc,url, err);
    lwqq_verbose(3,"%s\n",url);
    /* Setup http header */
    req->set_header(req, "Cookie", lwqq_get_cookies(lc));

    /* Send request */
    return req->do_request_async(req, 0, NULL,_C_(p_i,do_login_back,req));
}
Exemplo n.º 6
0
/** 
 * Set online status, this is the last step of login
 * 
 * @param err
 * @param lc 
 */
static LwqqAsyncEvent* set_online_status(LwqqClient *lc,const char *status)
{
    char msg[1024] ={0};
    char *buf;
    LwqqHttpRequest *req = NULL;  

    if (!status) {
        return NULL;
    }

    lc->clientid = generate_clientid();
    if (!lc->clientid) {
        lwqq_log(LOG_ERROR, "Generate clientid error\n");
        return NULL;
    }

    snprintf(msg, sizeof(msg), "{\"status\":\"%s\",\"ptwebqq\":\"%s\","
             "\"passwd_sig\":""\"\",\"clientid\":\"%s\""
             ", \"psessionid\":null}"
             ,status, lc->cookies->ptwebqq
             ,lc->clientid);
    buf = url_encode(msg);
    snprintf(msg, sizeof(msg), "r=%s", buf);
    s_free(buf);

    /* Create a POST request */
    req = lwqq_http_create_default_request(lc,WEBQQ_D_HOST"/channel/login2", NULL);

    lwqq_verbose(3,"%s\n",msg);
    /* Set header needed by server */
    //req->set_header(req, "Cookie2", "$Version=1");
    req->set_header(req, "Referer", WEBQQ_D_REF_URL);
    req->set_header(req, "Content-type", "application/x-www-form-urlencoded");
    
    /* Set http cookie */
    req->set_header(req, "Cookie", lwqq_get_cookies(lc));
    
    return  req->do_request_async(req, 1, msg,_C_(p_i,set_online_status_back,req));
}
Exemplo n.º 7
0
static int do_login_back(LwqqHttpRequest* req,LwqqAsyncEvent* event)
{
	char refer[1024];
	LwqqClient* lc = req->lc;
	int err = LWQQ_EC_OK;
	const char* response;
	//const char redirect_url[512];
	if (req->http_code != 200) {
		err = LWQQ_EC_HTTP_ERROR;
		goto done;
	}
	if (strstr(req->response,"aq.qq.com")!=NULL){
		err = LWQQ_EC_LOGIN_ABNORMAL;
		const char* beg = strstr(req->response,"http://aq.qq.com");
		if(beg) sscanf(beg,"%[^']",lc->error_description); // beg may be null
		goto done;
	}
	if(req->response == NULL){
		lwqq_puts("login no response\n");
		err = LWQQ_EC_NETWORK_ERROR;
		goto done;
	}

	response = req->response;
	lwqq_verbose(3,"%s\n",response);
	char *p = strstr(response, "\'");
	if (!p) {
		err = LWQQ_EC_ERROR;
		goto done;
	}
	int status,param2;
	char url[512];
	int param4;
	char msg[512];
	char user[64];
	//void url is '' which makes sscanf failed
	//%*c is for eat a blank before 'user'
	sscanf(response,"ptuiCB('%d','%d','%[^,],'%d','%[^']',%*c'%[^']');",
			&status,&param2,url,&param4,msg,user);
	url[strlen(url)-1]=0;
	switch (status) {
		case 0:
			{
				err = LWQQ_EC_OK;
				LwqqHttpRequest* req = lwqq_http_create_default_request(lc, url, NULL);
				req->set_header(req,"Referer",WEBQQ_LOGIN_LONG_REF_URL(refer));
				lwqq_http_set_option(req, LWQQ_HTTP_MAXREDIRS,1L);
				LwqqAsyncEvent* ev = req->do_request_async(req,lwqq__hasnot_post(),_C_(p_i,lwqq__process_empty,req));
				lwqq_async_add_event_chain(ev, event);
			} break;
		case 1:
			lwqq_log(LOG_WARNING, "Server busy! Please try again\n");
			lc->last_err = "Server busy! Please try again";
			err = LWQQ_EC_ERROR;
			goto done;

		case 2:
			lwqq_log(LOG_ERROR, "Out of date QQ number\n");
			lc->last_err = "Out of date QQ number";
			err = LWQQ_EC_ERROR;
			goto done;

		case 3:
			lwqq_log(LOG_ERROR, "Wrong password\n");
			err = LWQQ_EC_WRONG_PASS;
			lc->last_err = "Wrong username or password";
			goto done;

		case 4:
			lwqq_log(LOG_ERROR, "Wrong verify code\n");
			err = LWQQ_EC_WRONG_VERIFY;
			lc->last_err = "Wrong verify code";
			goto done;

		case 5:
			lwqq_log(LOG_ERROR, "Verify failed\n");
			lc->last_err = "Verify failed";
			err = LWQQ_EC_FAILD_VERIFY;
			goto done;

		case 6:
			lwqq_log(LOG_WARNING, "You may need to try login again\n");
			lc->last_err = "You may need to try login again";
			err = LWQQ_EC_ERROR;
			goto done;

		case 7:
			lwqq_log(LOG_ERROR, "Wrong input\n");
			lc->last_err = "Wrong input";
			err = LWQQ_EC_ERROR;
			goto done;

		case 8:
			lwqq_log(LOG_ERROR, "Too many logins on this IP. Please try again\n");
			lc->last_err = "Too many logins on this IP.Please try again";
			err = LWQQ_EC_ERROR;
			goto done;
		case LWQQ_EC_LOGIN_NEED_BARCODE:
			lwqq_log(LOG_ERROR, "%s\n",msg);
			lc->error_description = s_strdup(msg);
			err = LWQQ_EC_LOGIN_NEED_BARCODE;
			goto done;

		default:
			err = LWQQ_EC_ERROR;
			lc->last_err = "Unknow error";
			lwqq_log(LOG_ERROR, "Unknow error");
			goto done;
	}

done:
	lwqq_http_request_free(req);
	return err;
}
Exemplo n.º 8
0
static int do_login_back(LwqqHttpRequest* req)
{
    LwqqClient* lc = req->lc;
    int err = LWQQ_EC_OK;
    const char* response;
    if (req->http_code != 200) {
        err = LWQQ_EC_HTTP_ERROR;
        goto done;
    }
    if (strstr(req->response,"aq.qq.com")!=NULL){
        err = LWQQ_EC_LOGIN_ABNORMAL;
        const char* beg = strstr(req->response,"http://aq.qq.com");
        sscanf(beg,"%[^']",lc->error_description);
        goto done;
    }
    if(req->response == NULL){
        lwqq_puts("login no response\n");
        err = LWQQ_EC_NETWORK_ERROR;
        goto done;
    }

    response = req->response;
    lwqq_verbose(3,"%s\n",response);
    char *p = strstr(response, "\'");
    if (!p) {
        err = LWQQ_EC_ERROR;
        goto done;
    }
    char buf[4] = {0};
    int status;
    strncpy(buf, p + 1, 1);
    status = atoi(buf);

    switch (status) {
    case 0:
        //sava_cookie(lc, req, NULL);
        err = LWQQ_EC_OK;
        break;
        
    case 1:
        lwqq_log(LOG_WARNING, "Server busy! Please try again\n");
        lc->last_err = "Server busy! Please try again";
        err = LWQQ_EC_ERROR;
        goto done;

    case 2:
        lwqq_log(LOG_ERROR, "Out of date QQ number\n");
        lc->last_err = "Out of date QQ number";
        err = LWQQ_EC_ERROR;
        goto done;

    case 3:
        lwqq_log(LOG_ERROR, "Wrong password\n");
        err = LWQQ_EC_ERROR;
        lc->last_err = "Wrong username or password";
        goto done;

    case 4:
        lwqq_log(LOG_ERROR, "Wrong verify code\n");
        err = LWQQ_EC_ERROR;
        lc->last_err = "Wrong verify code";
        goto done;

    case 5:
        lwqq_log(LOG_ERROR, "Verify failed\n");
        lc->last_err = "Verify failed";
        err = LWQQ_EC_ERROR;
        goto done;

    case 6:
        lwqq_log(LOG_WARNING, "You may need to try login again\n");
        lc->last_err = "You may need to try login again";
        err = LWQQ_EC_ERROR;
        goto done;

    case 7:
        lwqq_log(LOG_ERROR, "Wrong input\n");
        lc->last_err = "Wrong input";
        err = LWQQ_EC_ERROR;
        goto done;

    case 8:
        lwqq_log(LOG_ERROR, "Too many logins on this IP. Please try again\n");
        lc->last_err = "Too many logins on this IP.Please try again";
        err = LWQQ_EC_ERROR;
        goto done;

    default:
        err = LWQQ_EC_ERROR;
        lc->last_err = "Unknow error";
        lwqq_log(LOG_ERROR, "Unknow error");
        goto done;
    }

done:
    lwqq_http_request_free(req);
    return err;
}