void RequestDownloadTask::onFail(HttpDownloader* loader) { FileLog( SnifferLogFileName, "RequestDownloadTask::onFail( " "loader : %p " ")", loader ); if( mpCallback != NULL ) { mpCallback->OnDownload(false, mFilePath, this); } mbFinishOK = false; // Send message to main thread OnTaskFinish(); }
void RequestUpdateTask::onSuccess(HttpDownloader* loader) { FileLog( SnifferLogFileName, "RequestUpdateTask::onSuccess( " "loader : %p " ")", loader ); if( mpCallback != NULL ) { mpCallback->OnUpdateFinish(true, mFilePath, this); } mbFinishOK = true; // Send message to main thread OnTaskFinish(); }
bool RequestOperator::ErrcodeHandle(const RequestBaseTask* request, const string &errnum) { FileLog("httprequest", "RequestOperator::ErrcodeHandle( " "errnum : %s, " "mbAlreadyHandle : %s, " "mbCanBeHandle : %s " ")", errnum.c_str(), mbAlreadyHandle?"true":"false", mbCanBeHandle?"true":"false" ); // 符合处理逻辑, 并且未被处理 if( strcmp(errnum.c_str(), ERROR_CODE_MBCE0003) == 0 && !mbAlreadyHandle ) { mbCanBeHandle = true; return false; } return true; }
void RequestAdvertController::PushAdvertCallbackHandle(long requestId, const string& url, bool requestRet, const char* buf, int size) { AdPushAdvertList list; string errnum = ""; string errmsg = ""; bool bFlag = false; if (requestRet) { // request success Json::Value dataJson; if( HandleResult(buf, size, errnum, errmsg, &dataJson) ) { if (dataJson[COMMON_DATA_LIST].isArray()) { bFlag = true; int i = 0; for (i = 0; i < dataJson[COMMON_DATA_LIST].size(); i++) { AdPushAdvertItem item; if (item.Parsing(dataJson[COMMON_DATA_LIST].get(i, Json::Value::null))) { list.push_back(item); } } } if (!bFlag) { // parsing fail errnum = LOCAL_ERROR_CODE_PARSEFAIL; errmsg = LOCAL_ERROR_CODE_PARSEFAIL_DESC; FileLog("httprequest", "RequestAdvertController::WomanListAdvertCallbackHandle() parsing fail:" "(url:%s, size:%d, buf:%s)", url.c_str(), size, buf); } } } else { // request fail errnum = LOCAL_ERROR_CODE_TIMEOUT; errmsg = LOCAL_ERROR_CODE_TIMEOUT_DESC; } if( m_Callback.onRequestAdPushAdvert != NULL ) { m_Callback.onRequestAdPushAdvert(requestId, bFlag, errnum, errmsg, list); } }
// ----------------------- PushAdvert ----------------------- long RequestAdvertController::PushAdvert(const string& deviceId, const string& pushId) { // char temp[16]; HttpEntiy entiy; // deviceId entiy.AddContent(ADVERT_REQUEST_DEVICEID, deviceId); // pushId if (!pushId.empty()) { entiy.AddContent(ADVERT_REQUEST_PUSHID, pushId); } string url = ADVERT_PUSHADVERT_PATH; FileLog("httprequest", "RequestAdvertController::PushAdvert" "( url:%s, deviceId:%s, pushId:%s)", url.c_str(), deviceId.c_str(), pushId.c_str()); return StartRequest(url, entiy, this); }
void HttpRequestManager::onFail(long requestId, string url) { FileLog("httprequest", "HttpRequestManager::onFail( " "requestId : %ld, " "url : %s " ")", requestId, url.c_str() ); mKMutex.lock(); string path; HttpRequest *request = NULL; HttpRequestMap::iterator itr2 = mHttpRequestMap.find(requestId); if( itr2 != mHttpRequestMap.end() ) { path = itr2->second->GetPath(); IHttpRequestManagerCallbackMap::iterator itr = mIHttpRequestManagerCallbackMap.find(requestId); if( itr != mIHttpRequestManagerCallbackMap.end() ) { if( itr->second != NULL ) { itr->second->onFail(requestId, path); } mIHttpRequestManagerCallbackMap.erase(itr); } request = itr2->second; if( request != NULL ) { delete request; } mHttpRequestMap.erase(itr2); } mKMutex.unlock(); // FileLog("httprequest", "HttpRequestManager::onFail( " // "requestId ; %ld, " // "url : %s, " // "exit " // ")", // requestId, // url.c_str() // ); }
// 11.3 获取LoveCall未处理数 long RequestLoveCallController::QueryLoveCallRequestCount(int searchType) { HttpEntiy entiy; char temp[16]; sprintf(temp, "%d", searchType); entiy.AddContent(LOVECALL_QUERY_REQUESTCOUNT_TYPE, temp); string url = LOVECALL_QUERY_REQUESTCOUNT_PATH; FileLog("httprequest", "RequestLoveCallController::QueryLoveCallRequestCount( " "url : %s, " "searchType : %d " ")", url.c_str(), searchType ); return StartRequest(url, entiy, this); }
// 处理已接收数据 bool ManApplyThemeTask::Handle(const TransportProtocol* tp) { // 服务器有可能返回空,因此默认为成功 bool result = false; m_errType = LCC_ERR_SUCCESS; m_errMsg = ""; ThemeInfoItem item; AmfParser parser; amf_object_handle root = parser.Decode((char*)tp->data, tp->GetDataLength()); if (!root.isnull()) { // 解析成功协议 if (root->type == DT_OBJECT) { result = ParsingThemeInfoItem(root, item); } else { result = false; } // 解析失败协议 int errType = 0; string errMsg = ""; if (GetAMFProtocolError(root, errType, errMsg)) { m_errType = (LCC_ERR_TYPE)errType; m_errMsg = errMsg; // 解析成功 result = true; } } FileLog("LiveChatClient", "ManApplyThemeTask::Handle() result:%d", result); // 通知listener if (NULL != m_listener) { m_listener->OnManApplyTheme(m_userId, m_themeId, m_errType, m_errMsg, item); } return result; }
void RequestAdvertController::WomanListAdvertCallbackHandle(long requestId, const string& url, bool requestRet, const char* buf, int size) { AdWomanListAdvertItem item; string errnum = ""; string errmsg = ""; bool bFlag = false; if (requestRet) { // request success Json::Value dataJson; if( HandleResult(buf, size, errnum, errmsg, &dataJson) ) { if (dataJson.isObject()) { bFlag = item.Parsing(dataJson); } if (!bFlag) { // parsing fail errnum = LOCAL_ERROR_CODE_PARSEFAIL; errmsg = LOCAL_ERROR_CODE_PARSEFAIL_DESC; FileLog("httprequest", "RequestAdvertController::WomanListAdvertCallbackHandle() parsing fail:" "(url:%s, size:%d, buf:%s)", url.c_str(), size, buf); } } } else { // request fail errnum = LOCAL_ERROR_CODE_TIMEOUT; errmsg = LOCAL_ERROR_CODE_TIMEOUT_DESC; } if( m_Callback.onRequestAdWomanListAdvert != NULL ) { // item.advertId = "advertId"; // item.image = "image"; // item.height = 15; // item.width = 12; // item.adurl = "adurl"; // item.openType = AD_OT_SYSTEMBROWER; m_Callback.onRequestAdWomanListAdvert(requestId, bFlag, errnum, errmsg, item); } }
void RequestDownloadTask::SetParam( const string& url, const string& filePath ) { char temp[16]; mUrl = url; mFilePath = filePath; FileLog( SnifferLogFileName, "RequestDownloadTask::SetParam( " "url : %s, " "filePath : %s " ")", url.c_str(), filePath.c_str() ); }
/** * @param email 电子邮箱 * @param password 密码 * @param deviceId 设备唯一标识 * @param versioncode 客户端内部版本号 * @param model 移动设备型号 * @param manufacturer 制造厂商 */ void RequestUploadTask::SetParam( const string& filePath ) { char temp[16]; mHttpEntiy.Reset(); mHttpEntiy.SetSaveCookie(true); if( filePath.length() > 0 ) { } FileLog( SnifferLogFileName, "RequestUploadTask::SetParam( " "filePath : %s " ")", filePath.c_str() ); }
/** * 2.3.获取验证码 * @param callback * @return 请求唯一标识 */ long RequestAuthorizationController::GetCheckCode(bool isUseCode) { HttpEntiy entiy; entiy.SetSaveCookie(true); if (isUseCode) { // 需要验证码 entiy.AddContent(AUTHORIZATION_USECODE, "1"); } else { // 无限制 entiy.AddContent(AUTHORIZATION_USECODE, "0"); } string url = CEHCKCODE_PATH; FileLog("httprequest", "RequestAuthorizationController::GetCheckCode( " "url : %s, " ")", url.c_str()); return StartRequest(url, entiy, this); }
void RequestLCAddInviteTemplateTask::SetParam(const string& tempContent , bool isInviteAssistant) { mHttpEntiy.Reset(); if( tempContent.length() > 0 ) { mHttpEntiy.AddContent(LC_ADDINVITETEMPLATE_CONTENT, tempContent.c_str()); } char temp[16]; sprintf(temp, "%d", isInviteAssistant?1:0); mHttpEntiy.AddContent(LC_ADDINVITETEMPLATE_AUTOINVITEFLAG, temp); FileLog("httprequest", "RequestLCAddInviteTemplateTask::SetParam( " "tempContent : %s ," "isInviteAssistant : %s" ")", tempContent.c_str(), isInviteAssistant?"true":"false" ); }
bool RequestDownloadTask::Start() { bool bFlag = false; if( BaseTask::Start() ) { if( mHttpDownloader.StartDownload(mUrl, mFilePath, this) ) { bFlag = true; } else { OnTaskFinish(); } } FileLog( SnifferLogFileName, "RequestDownloadTask::Start( " "bFlag : %s " ")", bFlag?"true":"false" ); return bFlag; }
/** * 2.1.检查真假服务器 * @param email 电子邮箱 * @return 请求唯一标识 */ long RequestFakeController::CheckServer( string email ) { HttpEntiy entiy; if( email.length() > 0 ) { entiy.AddContent(FAKE_EMAIL, email.c_str()); } string url = FAKE_CHECK_SERVER_PATH; FileLog("httprequest", "RequestFakeController::LoginWithFacebook( " "url : %s, " "email : %s " " )", url.c_str(), email.c_str() ); return StartRequest(url, entiy, this, FakeSite); }
long RequestAuthorizationController::ModifyPassword( string email, string newPassword, string verifyCode, string deviceId ) { HttpEntiy entiy; if( email.length() > 0 ) { entiy.AddContent(AUTHORIZATION_EMAIL, email.c_str()); } if( newPassword.length() > 0 ) { entiy.AddContent(AUTHORIZATION_NEWPASSWORD, newPassword.c_str()); } if( verifyCode.length() > 0 ) { entiy.AddContent(AUTHORIZATION_VERIFYCODE, verifyCode.c_str()); } if( deviceId.length() > 0 ) { entiy.AddContent(AUTHORIZATION_DEVICEID, deviceId.c_str()); } string url = MODIFY_PASSWORD_PATH; FileLog("httprequest", "RequestAuthorizationController::GetPhoneVerifyCode( " "email : %s, " "newPassword : %s, " "verifyCode : %s, " "deviceId : %s, " ")", email.c_str(), newPassword.c_str(), verifyCode.c_str(), deviceId.c_str() ); return StartRequest(url, entiy, this); }
void RequestAdvertController::Html5AdCallbackHandle(long requestId, const string& url, bool requestRet, const char* buf, int size) { AdHtml5AdvertItem item; string errnum = ""; string errmsg = ""; bool bFlag = false; if (requestRet) { // request success Json::Value dataJson; if( HandleResult(buf, size, errnum, errmsg, &dataJson) ) { if (dataJson.isObject()) { item.Parsing(dataJson); } if (errnum.length() <= 0) { bFlag = true; } if (!bFlag) { // parsing fail errnum = LOCAL_ERROR_CODE_PARSEFAIL; errmsg = LOCAL_ERROR_CODE_PARSEFAIL_DESC; FileLog("httprequest", "RequestAdvertController::AdmirerListAdCallbackHandle() parsing fail:" "(url:%s, size:%d, buf:%s)", url.c_str(), size, buf); } } } else { // request fail errnum = LOCAL_ERROR_CODE_TIMEOUT; errmsg = LOCAL_ERROR_CODE_TIMEOUT_DESC; } if( m_Callback.onRequestAdmirerListAd != NULL ) { m_Callback.onRequestHtml5Ad(requestId, bFlag, errnum, errmsg, item); } }
void RequestAdvertController::PopNoticeCallbackHandle(long requestId, const string& url, bool requestRet, const char* buf, int size) { string noticeUrl = ""; string errnum = ""; string errmsg = ""; bool isCanClose = false; bool bFlag = false; if (requestRet) { // request success Json::Value dataJson; if( HandleResult(buf, size, errnum, errmsg, &dataJson) ) { if (dataJson[ADVERT_NOTICEURL].isString()) { noticeUrl = dataJson[ADVERT_NOTICEURL].asString(); } if (dataJson[ADVERT_CANCLOSE].isInt()) { isCanClose = dataJson[ADVERT_CANCLOSE].asInt() == 0 ? false : true; bFlag = true; } if (!bFlag) { // parsing fail errnum = LOCAL_ERROR_CODE_PARSEFAIL; errmsg = LOCAL_ERROR_CODE_PARSEFAIL_DESC; FileLog("httprequest", "RequestAdvertController::PopNoticeCallbackHandle() parsing fail:" "(url:%s, size:%d, buf:%s)", url.c_str(), size, buf); } } } else { // request fail errnum = LOCAL_ERROR_CODE_TIMEOUT; errmsg = LOCAL_ERROR_CODE_TIMEOUT_DESC; } if( m_Callback.onRequestPopNoticeAdvert != NULL ) { m_Callback.onRequestPopNoticeAdvert(requestId, bFlag, errnum, errmsg, noticeUrl, isCanClose); } }
long HttpRequest::StartRequest(string host, string path, const HttpEntiy& entiy) { FileLog("httprequest", "HttpRequest::StartRequest( " "host : %s, " "path : %s, " "entiy : %p " ")", host.c_str(), path.c_str(), &entiy); // InitRespondBuffer(); mHost = host; mPath = path; // mUrl = host + path; // mEntiy = entiy; // mHttpClient.Init(mUrl); // mKThread.stop(); // return mKThread.start(mpHttpRequestRunnable); return StartRequest(host + path, entiy); }
int Sniffer::SinfferData() { FileLog(SnifferLogFileName, "等待数据..."); int iRet = -1; sockaddr_in remoteAd; bzero(&remoteAd, sizeof(remoteAd)); int iRemoteAdLen = sizeof(sockaddr_in); unsigned char buff[2048]; memset(buff, '\0', sizeof(buff)); iRet = recvfrom(mSocket, buff, sizeof(buff), 0, (struct sockaddr *)&remoteAd, &iRemoteAdLen); timeval tout; tout.tv_sec = 3; tout.tv_usec = 0; fd_set rset; FD_ZERO(&rset); FD_SET(mSocket, &rset); int iRetS = select(mSocket + 1, &rset, NULL, NULL, &tout); if(iRetS > 0) { iRet = recvfrom(mSocket, buff, sizeof(buff), 0, (struct sockaddr *)&remoteAd, &iRemoteAdLen); if(iRet > 0) { AnalyseData(buff, iRet); } } else if(iRetS == 0){ iRet = 0; // showLog("Jni.Sniffer.SinfferData", "Sinffer no data for 3 second!"); } else { // ILog("Jni.Sniffer.SinfferData", "Sinffer data error!"); } return iRet; }
/** * 2.7.手机短信认证 * @param verify_code 验证码 * @param v_type 验证类型 * @return 请求唯一标识 */ long RequestAuthorizationController::VerifySms(string verify_code, int v_type) { HttpEntiy entiy; if (verify_code.length() > 0) { entiy.AddContent(AUTHORIZATION_VERIFY_CODE, verify_code.c_str()); } if (v_type > -1 && v_type < VerifyArrayCount) { entiy.AddContent(AUTHORIZATION_V_TYPE, VerifyArray[v_type]); } string url = VERIFY_SMS_PATH; FileLog("httprequest", "RequestAuthorizationController::VerifySms( " "url : %s, " "verify_code : %s, " "v_type : %d, " ")", url.c_str(), verify_code.c_str(), v_type); return StartRequest(url, entiy, this); }
/** * 2.5.找回密码 * @param email 用户注册的邮箱 * @return 请求唯一标识 */ long RequestAuthorizationController::FindPassword(string email, string checkcode) { HttpEntiy entiy; if (email.length() > 0) { entiy.AddContent(AUTHORIZATION_SENDMAIL, email.c_str()); } if (checkcode.length() > 0) { entiy.AddContent(AUTHORIZATION_CHECKCODE, checkcode.c_str()); } string url = FINDPASSWORD_PATH; FileLog("httprequest", "RequestAuthorizationController::FindPassword( " "url : %s, " "email : %s, " "checkcode : %s " ")", url.c_str(), email.c_str(), checkcode.c_str()); return StartRequest(url, entiy, this); }
// 初始化参数 bool SendMsgTask::InitParam(const string& userId, const string& message, bool illegal, int ticket, INVITE_TYPE inviteType) { // 打log FileLog("LiveChatClient", "SendMsgTask::InitParam() inviteType:%d", inviteType); bool result = false; if (!userId.empty() && !message.empty()) { m_userId = userId; m_message = message; m_illegal = illegal; m_ticket = ticket; if(inviteType != INVITE_TYPE_UNKNOW){ m_inviteType = inviteType; }else{ m_inviteType = INVITE_TYPE_CHAT; } result = true; } return result; }
/** * 3.1.修改密码 * @param oldPassword 新密码 * @param newPassword 旧密码 * @param callback * @return 请求唯一标识 */ long RequestSettingController::ChangePassword(string oldPassword, string newPassword) { HttpEntiy entiy; if( oldPassword.length() > 0 ) { entiy.AddContent(SETTING_PASSWORDOLD, oldPassword); } if( newPassword.length() > 0 ) { entiy.AddContent(SETTING_PASSWORDNEW, newPassword); } string url = CHANGE_PASSWORD_PATH; FileLog("httprequest", "RequestSettingController::ChangePassword( " "url : %s, " "oldPassword : %s " "newPassword : %s ", url.c_str(), oldPassword.c_str(), newPassword.c_str() ); return StartRequest(url, entiy, this); }
// 获取待发送的数据,可先获取data长度,如:GetSendData(NULL, 0, dataLen); bool GetUsersInfoTask::GetSendData(void* data, unsigned int dataSize, unsigned int& dataLen) { bool result = false; // 构造参数 string param = ""; int i; list<string>::const_iterator iter; for (i = 0, iter = m_userIdList.begin(); iter != m_userIdList.end(); i++, iter++) { if (!param.empty()) { param += USERID_DELIMITED; } param += *iter; } // 构造json协议 Json::Value root(param); Json::FastWriter writer; string json = writer.write(root); // 填入buffer if (json.length() < dataSize) { memcpy(data, json.c_str(), json.length()); dataLen = json.length(); result = true; } // 打log FileLog("LiveChatClient", "GetUsersInfoTask::GetSendData() result:%d, json:%s" , result, json.c_str()); return result; }
void RequestAdvertController::AppPromotionCallbackHandle(long requestId, const string& url, bool requestRet, const char* buf, int size) { string adOverview = ""; string errnum = ""; string errmsg = ""; bool bFlag = false; if (requestRet) { // request success Json::Value dataJson; if( HandleResult(buf, size, errnum, errmsg, &dataJson) ) { if (dataJson[ADVERT_ADOVERVIEW].isString()) { adOverview = dataJson[ADVERT_ADOVERVIEW].asString(); bFlag = true; } if (!bFlag) { // parsing fail errnum = LOCAL_ERROR_CODE_PARSEFAIL; errmsg = LOCAL_ERROR_CODE_PARSEFAIL_DESC; FileLog("httprequest", "RequestAdvertController::AppPromotionCallbackHandle() parsing fail:" "(url:%s, size:%d, buf:%s)", url.c_str(), size, buf); } } } else { // request fail errnum = LOCAL_ERROR_CODE_TIMEOUT; errmsg = LOCAL_ERROR_CODE_TIMEOUT_DESC; } if( m_Callback.onRequestAppPromotionAdvert != NULL ) { m_Callback.onRequestAppPromotionAdvert(requestId, bFlag, errnum, errmsg, adOverview); } }
// 获取待发送的数据,可先获取data长度,如:GetSendData(NULL, 0, dataLen); bool SearchOnlineManTask::GetSendData(void* data, unsigned int dataSize, unsigned int& dataLen) { bool result = false; // 构造json协议 Json::Value root; root[BEGIN_AGE_PARAM] = m_beginAge; root[END_AGE_PARAM] = m_endAge; Json::FastWriter writer; string json = writer.write(root); // 填入buffer if (json.length() < dataSize) { memcpy(data, json.c_str(), json.length()); dataLen = json.length(); result = true; } // 打log FileLog("LiveChatClient", "SearchOnlineManTask::GetSendData() result:%d, json:%s", result, json.c_str()); return result; }
/** * 10.2.提交已标记的女士 * @param likeList 喜爱的女士列表 * @param unlikeList 不喜爱女士列表 * @return 请求唯一标识 */ long RequestQuickMatchController::SubmitQuickMatchMarkLadyList(list<string> likeListId, list<string> unlikeListId) { HttpEntiy entiy; string likeId = ""; for(list<string>::iterator itr = likeListId.begin(); itr != likeListId.end(); itr++) { likeId += *itr; likeId += ","; } if( likeId.length() > 0 ) { likeId = likeId.substr(0, likeId.length() - 1); entiy.AddContent(QUICKMATCH_UPLOAD_CONFIRMTYPE, likeId); } string unlikeId = ""; for(list<string>::iterator itr = unlikeListId.begin(); itr != unlikeListId.end(); itr++) { unlikeId += *itr; unlikeId += ","; } if( unlikeId.length() > 0 ) { unlikeId = unlikeId.substr(0, unlikeId.length() - 1); entiy.AddContent(QUICKMATCH_UPLOAD_CONFIRMTYPE, unlikeId); } string url = QUICKMATCH_UPLOAD_PATH; FileLog("httprequest", "RequestQuickMatchController::SubmitQuickMatchMarkLadyList( " "url : %s, " "likeId : %s, " "unlikeId : %s " ")", url.c_str(), likeId.c_str(), unlikeId.c_str() ); return StartRequest(url, entiy, this); }
/** * 10.3.查询已标记like的女士列表 * @return 请求唯一标识 */ long RequestQuickMatchController::QueryQuickMatchLikeLadyList(int pageIndex, int pageSize) { char temp[16]; HttpEntiy entiy; sprintf(temp, "%d", pageIndex); entiy.AddContent(COMMON_PAGE_INDEX, temp); sprintf(temp, "%d", pageSize); entiy.AddContent(COMMON_PAGE_SIZE, temp); string url = QUICKMATCH_LIKE_LIST_PATH; FileLog("httprequest", "RequestQuickMatchController::QueryQuickMatchLikeLadyList( " "url : %s, " "pageIndex : %d, " "pageSize : %d " ")", url.c_str(), pageIndex, pageSize ); return StartRequest(url, entiy, this); }
/** * 11.2.确定Love Call接口 * @param orderId 订单ID * @param confirmType 确定类型(1:接受,0:拒绝) * @return 请求唯一标识 */ long RequestLoveCallController::ConfirmLoveCall(string orderId, int confirmType) { HttpEntiy entiy; char temp[16]; if( orderId.length() > 0 ) { entiy.AddContent(LOVECALL_QUERY_LIST_ORDERID, orderId); } sprintf(temp, "%d", confirmType); entiy.AddContent(LOVECALL_CONFIRM_CONFIRMTYPE, temp); string url = LOVECALL_CONFIRM_PATH; FileLog("httprequest", "RequestLoveCallController::ConfirmLoveCall( " "url : %s, " "orderId : %s, " "confirmType : %d " ")", url.c_str(), orderId.c_str(), confirmType ); return StartRequest(url, entiy, this); }