LwqqAsyncEvset* lwqq_async_evset_new() { LwqqAsyncEvset_* l = s_malloc0(sizeof(LwqqAsyncEvset_)); pthread_mutex_init(&l->lock,NULL); pthread_cond_init(&l->cond,NULL); return (LwqqAsyncEvset*)l; }
struct str_list_* str_list_prepend(struct str_list_* list,const char* str) { struct str_list_* ret = s_malloc0(sizeof(struct str_list_)); ret->str = s_strdup(str); ret->next = list; return ret; }
static void(loop_stop)() { uv_stop(loop); uv_idle_t* idle = s_malloc0(sizeof(*idle)); uv_idle_init(loop, idle); uv_idle_start(idle, loop_stop_cb); }
void lwqq_async_queue_add(LwqqAsyncQueue* queue,void* func,LwqqAsyncEvent* ev) { LwqqAsyncEntry* entry = s_malloc0(sizeof(*entry)); entry->func = func; entry->ev = ev; LIST_INSERT_HEAD(queue,entry,entries); }
//the entrience for recv file messages void file_message(LwqqClient* lc,LwqqMsgFileMessage* file) { qq_account* ac = lwqq_client_userdata(lc); if(file->mode == MODE_RECV) { PurpleAccount* account = ac->account; LwqqClient* lc = ac->qq; LwqqBuddy* buddy = lc->find_buddy_by_uin(lc,file->super.from); if(buddy == NULL ) return; const char* key = try_get(buddy->qqnumber,buddy->uin); PurpleXfer* xfer = purple_xfer_new(account,PURPLE_XFER_RECEIVE,key); purple_xfer_set_filename(xfer,file->recv.name); purple_xfer_set_init_fnc(xfer,recv_file_init); purple_xfer_set_request_denied_fnc(xfer,recv_file_request_denied); purple_xfer_set_cancel_recv_fnc(xfer,recv_file_cancel); LwqqMsgFileMessage* fdup = s_malloc0(sizeof(*fdup)); lwqq_msg_move(fdup,file); xfer->data = fdup; purple_xfer_request(xfer); } else if(file->mode == MODE_REFUSE) { if(file->refuse.cancel_type == CANCEL_BY_USER) qq_sys_msg_write(ac, LWQQ_MS_BUDDY_MSG, file->super.from, _("Other canceled file transport"), PURPLE_MESSAGE_SYSTEM, time(NULL)); else if(file->refuse.cancel_type == CANCEL_BY_OVERTIME) qq_sys_msg_write(ac, LWQQ_MS_BUDDY_MSG, file->super.from, _("File transport timeout"), PURPLE_MESSAGE_SYSTEM, time(NULL)); } }
void qq_account_insert_index_node(qq_account* ac, const LwqqBuddy* b, const LwqqGroup* g) { #if QQ_USE_FAST_INDEX if (!ac || (!b && !g)) return; index_node* node = s_malloc0(sizeof(*node)); int type = b ? NODE_IS_BUDDY : NODE_IS_GROUP; node->type = type; if (type == NODE_IS_BUDDY) { node->node = b; const LwqqBuddy* buddy = b; g_hash_table_insert(ac->fast_index.uin_index, s_strdup(buddy->uin), node); if (buddy->qqnumber) g_hash_table_insert(ac->fast_index.qqnum_index, s_strdup(buddy->qqnumber), node); } else { node->node = g; const LwqqGroup* group = g; g_hash_table_insert(ac->fast_index.uin_index, s_strdup(group->gid), node); if (group->account) g_hash_table_insert(ac->fast_index.qqnum_index, s_strdup(group->account), node); } #endif }
void lwqq_async_io_watch(LwqqAsyncIoHandle io,int fd,int action,LwqqAsyncIoCallback fun,void* data) { LwqqAsyncIoWrap* wrap = s_malloc0(sizeof(*wrap)); wrap->callback = fun; wrap->data = data; io->ev = purple_input_add(fd,action,event_cb_wrap,wrap); io->wrap = wrap; }
void qq_dispatch(LwqqCommand cmd,unsigned long timeout) { if(timeout==0)timeout=10; LwqqCommand* d = s_malloc0(sizeof(*d)); *d = cmd; purple_timeout_add(timeout,did_dispatch,d); }
LwqqAsyncEvent* lwqq_async_event_new(void* req) { LwqqAsyncEvent* event = s_malloc0(sizeof(LwqqAsyncEvent)); event->req = req; event->lc = req?event->req->lc:NULL; event->failcode = LWQQ_CALLBACK_VALID; event->result = 0; return event; }
LwqqAsyncEvent* lwqq_async_event_new(void* req) { LwqqAsyncEvent* event = s_malloc0(sizeof(_LwqqAsyncEventInternal)); _LwqqAsyncEventInternal* internal = (_LwqqAsyncEventInternal*)event; internal->req = req; event->lc = req?internal->req->lc:NULL; event->failcode = LWQQ_CALLBACK_VALID; event->result = 0; return event; }
void lwqq_async_dispatch(DISPATCH_FUNC dsph,CALLBACK_FUNC func , ...) { async_dispatch_data* data = s_malloc0(sizeof(*data)); data->dsph = dsph; data->func = func; va_list args; va_start(args,func); dsph(NULL,&data->data,&args); va_end(args); lwqq_async_timer_watch(&data->timer, 10, timeout_come, data); }
void lwqq_async_io_watch(LwqqAsyncIoHandle io,int fd,int action,LwqqAsyncIoCallback fun,void* data) { ev_io_init(io,event_cb_wrap,fd,action); LwqqAsyncIoWrap* wrap = s_malloc0(sizeof(*wrap)); wrap->callback = fun; wrap->data = data; io->data = wrap; ev_io_start(EV_DEFAULT,io); if(ev_thread_status!=THREAD_NOW_RUNNING) start_ev_thread(); }
qq_js_t* qq_js_init() { qq_js_t* h =(qq_js_t*) s_malloc0(sizeof(*h)); h->runtime = JS_NewRuntime(8L*1024L*1024L); h->context = JS_NewContext(h->runtime, 8*1024); JS_SetOptions(h->context, JSOPTION_VAROBJFIX); JS_SetErrorReporter(h->context, report_error); h->global = JS_NewCompartmentAndGlobalObject(h->context, &global_class, NULL); JS_InitStandardClasses(h->context, h->global); return h; }
void lwqq_async_dispatch_delay(LwqqCommand cmd,unsigned long timeout) { #ifndef WITHOUT_ASYNC if(timeout==0) timeout=10; async_dispatch_data* data = s_malloc0(sizeof(*data)); data->cmd = cmd; data->timer = lwqq_async_timer_new(); lwqq_async_timer_watch(data->timer, timeout, dispatch_wrap, data); #else vp_do(cmd,NULL); #endif }
void lwqq_async_io_watch(LwqqAsyncIoHandle io,int fd,int action,LwqqAsyncIoCallback fun,void* data) { if(global_quit_lock) return; ev_io_init(io,event_cb_wrap,fd,action); LwqqAsyncIoWrap* wrap = s_malloc0(sizeof(*wrap)); wrap->callback = fun; wrap->data = data; io->data = wrap; if(!ev_default) build_global_loop(); ev_io_start(ev_default,io); if(ev_thread_status!=THREAD_NOW_RUNNING) start_ev_thread(); }
static void upload_file_init(PurpleXfer* xfer) { void** data = xfer->data; qq_account* ac = data[0]; LwqqClient* lc = ac->qq; LwqqMsgOffFile* file = s_malloc0(sizeof(*file)); file->from = s_strdup(lc->myself->uin); file->to = s_strdup(purple_xfer_get_remote_user(xfer)); file->name = s_strdup(purple_xfer_get_local_filename(xfer)); xfer->start_time = time(NULL); data[1] = file; data[2] = xfer; //lwqq_async_add_event_listener( background_upload_file(lc,file,file_trans_on_progress,xfer); //send_file,data); }
lwqq_js_t* lwqq_js_init() { lwqq_js_t* h = s_malloc0(sizeof(*h)); h->runtime = JS_NewRuntime(8L*1024L*1024L); h->context = JS_NewContext(h->runtime, 16*1024); JS_SetOptions(h->context, JSOPTION_VAROBJFIX|JSOPTION_COMPILE_N_GO|JSOPTION_NO_SCRIPT_RVAL); JS_SetErrorReporter(h->context, report_error); #ifdef MOZJS_185 h->global = JS_NewCompartmentAndGlobalObject(h->context, &global_class, NULL); #else h->global = JS_NewGlobalObject(h->context,&global_class,NULL); #endif JS_InitStandardClasses(h->context, h->global); return h; }
static int check_need_verify_back(LwqqHttpRequest* req) { int err = LWQQ_EC_OK; LwqqClient* lc = req->lc; if(req->failcode != LWQQ_CALLBACK_VALID){ err = LWQQ_EC_NETWORK_ERROR; lc->args->login_ec = err; vp_do_repeat(lc->events->login_complete, NULL); goto done; } lwqq__jump_if_http_fail(req, err); /** * * The http message body has two format: * * ptui_checkVC('1','9ed32e3f644d968809e8cbeaaf2cce42de62dfee12c14b74','\x00\x00\x00\x00\x04\x7e\x73\xb2'); * ptui_checkVC('0','!IJG', '\x00\x00\x00\x00\x54\xb3\x3c\x53'); * The former means we need verify code image and the second * parameter is vc_type. * The later means we don't need the verify code image. The second * parameter is the verify code. The vc_type is in the header * "Set-Cookie". */ int need_vf; char param2[256]; char param3[256]; sscanf(req->response,"ptui_checkVC('%d','%[^']','%[^']');",&need_vf,param2,param3); lc->vc = s_malloc0(sizeof(*lc->vc)); lc->vc->uin = s_strdup(param3); lc->vc->str = s_strdup(param2); lc->vc->lc = lc; if (need_vf == 0) { /* We need get the ptvfsession from the header "Set-Cookie" */ lwqq_log(LOG_NOTICE, "Verify code: %s\n", lc->vc->str); } else if (need_vf == 1) { err = LWQQ_EC_LOGIN_NEED_VC; lwqq_log(LOG_NOTICE, "We need verify code image: %s\n", lc->vc->str); } done: lwqq_http_request_free(req); return err; }
LwqqAsyncEvent* lwqq_async_event_new(void* req) { LwqqAsyncEvent* event = s_malloc0(sizeof(LwqqAsyncEvent)); event->req = req; return event; }
static void*(io_new)() { return s_malloc0(sizeof(struct LwqqAsyncIo_)); }
static void*(timer_new)() { return s_malloc0(sizeof(struct LwqqAsyncTimer_)); }
static void get_verify_code(LwqqClient *lc, LwqqErrorCode *err) { LwqqHttpRequest *req; char url[512]; char response[256]; int ret; char chkuin[64]; snprintf(url, sizeof(url), "%s%s?uin=%s&appid=%s", LWQQ_URL_CHECK_HOST, VCCHECKPATH, lc->username, APPID); req = lwqq_http_create_default_request(url, err); if (!req) { goto failed; } snprintf(chkuin, sizeof(chkuin), "chkuin=%s", lc->username); req->set_header(req, "Cookie", chkuin); ret = req->do_request(req, 0, NULL); if (ret) { *err = LWQQ_EC_NETWORK_ERROR; goto failed; } if (req->http_code != 200) { *err = LWQQ_EC_HTTP_ERROR; goto failed; } /** * * The http message body has two format: * * ptui_checkVC('1','9ed32e3f644d968809e8cbeaaf2cce42de62dfee12c14b74'); * ptui_checkVC('0','!LOB'); * The former means we need verify code image and the second * parameter is vc_type. * The later means we don't need the verify code image. The second * parameter is the verify code. The vc_type is in the header * "Set-Cookie". */ snprintf(response, sizeof(response), "%s", req->response); lwqq_log(LOG_NOTICE, "Get response verify code: %s\n", response); char *c = strstr(response, "ptui_checkVC"); char *s; if (!c) { *err = LWQQ_EC_HTTP_ERROR; goto failed; } c = strchr(response, '\''); if (!c) { *err = LWQQ_EC_HTTP_ERROR; goto failed; } c++; lc->vc = s_malloc0(sizeof(*lc->vc)); if (*c == '0') { /* We got the verify code. */ /* Parse uin first */ lc->vc->uin = parse_verify_uin(response); if (!lc->vc->uin) goto failed; s = c; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); *c = '\0'; lc->vc->type = s_strdup("0"); lc->vc->str = s_strdup(s); /* We need get the ptvfsession from the header "Set-Cookie" */ update_cookies(lc->cookies, req, "ptvfsession", 1); lwqq_log(LOG_NOTICE, "Verify code: %s\n", lc->vc->str); } else if (*c == '1') { /* We need get the verify image. */ /* Parse uin first */ lc->vc->uin = parse_verify_uin(response); s = c; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); *c = '\0'; lc->vc->type = s_strdup("1"); // ptui_checkVC('1','7ea19f6d3d2794eb4184c9ae860babf3b9c61441520c6df0', '\x00\x00\x00\x00\x04\x7e\x73\xb2'); lc->vc->str = s_strdup(s); *err = LWQQ_EC_LOGIN_NEED_VC; lwqq_log(LOG_NOTICE, "We need verify code image: %s\n", lc->vc->str); } lwqq_http_request_free(req); return ; failed: lwqq_http_request_free(req); }
static int get_verify_code_back(LwqqHttpRequest* req) { int err = LWQQ_EC_OK; char response[256]; LwqqClient* lc = req->lc; if (req->http_code != 200) { err = LWQQ_EC_HTTP_ERROR; goto failed; } /** * * The http message body has two format: * * ptui_checkVC('1','9ed32e3f644d968809e8cbeaaf2cce42de62dfee12c14b74'); * ptui_checkVC('0','!LOB'); * The former means we need verify code image and the second * parameter is vc_type. * The later means we don't need the verify code image. The second * parameter is the verify code. The vc_type is in the header * "Set-Cookie". */ snprintf(response, sizeof(response), "%s", req->response); lwqq_log(LOG_NOTICE, "Get response verify code: %s\n", response); char *c = strstr(response, "ptui_checkVC"); char *s; if (!c) { err = LWQQ_EC_HTTP_ERROR; goto failed; } c = strchr(response, '\''); if (!c) { err = LWQQ_EC_HTTP_ERROR; goto failed; } c++; lc->vc = s_malloc0(sizeof(*lc->vc)); if (*c == '0') { /* We got the verify code. */ /* Parse uin first */ lc->vc->uin = parse_verify_uin(response); if (!lc->vc->uin){ err = LWQQ_EC_ERROR; goto failed; } s = c; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); *c = '\0'; lc->vc->type = s_strdup("0"); lc->vc->str = s_strdup(s); /* We need get the ptvfsession from the header "Set-Cookie" */ //update_cookies(lc->cookies, req, "ptvfsession", 1); lwqq_log(LOG_NOTICE, "Verify code: %s\n", lc->vc->str); } else if (*c == '1') { /* We need get the verify image. */ /* Parse uin first */ lc->vc->uin = parse_verify_uin(response); s = c; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); s = c + 1; c = strstr(s, "'"); *c = '\0'; lc->vc->type = s_strdup("1"); // ptui_checkVC('1','7ea19f6d3d2794eb4184c9ae860babf3b9c61441520c6df0', '\x00\x00\x00\x00\x04\x7e\x73\xb2'); lc->vc->str = s_strdup(s); err = LWQQ_EC_LOGIN_NEED_VC; lwqq_log(LOG_NOTICE, "We need verify code image: %s\n", lc->vc->str); } failed: lwqq_http_request_free(req); return err; }