void CCssSoap::GetBanListSinceTimestamp(char * lastBanCheckTimestamp, char * currentTimestamp, char * lastBanList) { char szHdrs[512]; sprintf(szHdrs, "Content-Type: text/xml;charset=UTF-8\r\nSOAPAction: \"http://tempuri.org/IClientService/GetBannedUsernamesAfterTimestamp\""); char soapBody[4092]; sprintf(soapBody, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"> \ <soapenv:Header/> \ <soapenv:Body> \ <tem:GetBannedUsernamesAfterTimestamp> \ <tem:unixTimeStamp>%s</tem:unixTimeStamp> \ </tem:GetBannedUsernamesAfterTimestamp> \ </soapenv:Body> \ </soapenv:Envelope>", lastBanCheckTimestamp); int soapLength = strlen(soapBody); ZString Response = UTL::DoHTTP(szHdrs, m_szCssServerDomain, "POST", m_szCssClientServicePath, soapBody, soapLength, true); char * szToken; char * szResponse = (char*)_alloca(10000); Strcpy(szResponse, (PCC)Response); // Parse results std::tr1::regex rgxBannedUserNames("<GetBannedUsernamesAfterTimestampResult .*?>.*?<a:BannedUserNames>(.*?)</a:BannedUserNames>.*?</GetBannedUsernamesAfterTimestampResult>"); std::tr1::regex rgxCurrentTimestamp("<GetBannedUsernamesAfterTimestampResult .*?>.*?<a:CurrentTimestamp>(.*?)</a:CurrentTimestamp>.*?</GetBannedUsernamesAfterTimestampResult>"); std::tr1::smatch result; std::string strResponse(szResponse); lastBanList[0] = '\0'; if (std::tr1::regex_search(strResponse, result, rgxBannedUserNames) == true && result.size() > 1) { if (strlen(result[1].str().c_str()) < 4096) sprintf(lastBanList, result[1].str().c_str()); } if (std::tr1::regex_search(strResponse, result, rgxCurrentTimestamp) == true && result.size() > 1) { sprintf(currentTimestamp, result[1].str().c_str()); } }
bool CCssSoap::GetUsernameForUsernameOrCallsign(char * szCharacterName, char * szUsername, char * szReason) { char szHdrs[512]; sprintf(szHdrs, "Content-Type: text/xml;charset=UTF-8\r\nSOAPAction: \"http://tempuri.org/IClientService/GetUsernameFromCallsignOrUsername\""); char soapBody[4092]; sprintf(soapBody, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\"> \ <soapenv:Header/> \ <soapenv:Body> \ <tem:GetUsernameFromCallsignOrUsername> \ <tem:callsignOrUsername><![CDATA[%s]]></tem:callsignOrUsername> \ </tem:GetUsernameFromCallsignOrUsername> \ </soapenv:Body> \ </soapenv:Envelope>", szCharacterName); int soapLength = strlen(soapBody); ZString Response = UTL::DoHTTP(szHdrs, m_szCssServerDomain, "POST", m_szCssClientServicePath, soapBody, soapLength, true); char * szToken; char * szResponse = (char*)_alloca(10000); Strcpy(szResponse, (PCC)Response); // Parse results std::tr1::regex rgx("<GetUsernameFromCallsignOrUsernameResult.*?>.*?<a:Username>(.*?)</a:Username>.*?</GetUsernameFromCallsignOrUsernameResult>"); std::tr1::smatch result; std::string strResponse(szResponse); if (std::tr1::regex_search(strResponse, result, rgx) == true && result.size() > 1) { sprintf(szUsername, result[1].str().c_str()); return true; } else { sprintf(szReason, "Your primary login couldn't be found from this callsign. Please log in with your main account. Please visit www.freeallegiance.org to request help in the forums."); return false; } sprintf(szReason, "A general sign in error occurred. Please visit www.freeallegiance.org to request help in the forums."); return false; }
bool CCssSoap::ValidateUserLogin(char *username, char *password, char * szReason, int & iID) { char szHdrs[512]; sprintf(szHdrs, "Content-Type: text/xml;charset=UTF-8\r\nSOAPAction: \"http://tempuri.org/IClientService/LauncherSignIn\""); char soapBody[4092]; sprintf(soapBody, "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\" xmlns:all=\"http://schemas.datacontract.org/2004/07/Allegiance.CommunitySecuritySystem.Server.Contracts\"> \ <soapenv:Header/> \ <soapenv:Body> \ <tem:LauncherSignIn> \ <tem:data> \ <all:Password><![CDATA[%s]]></all:Password> \ <all:Username><![CDATA[%s]]></all:Username> \ </tem:data> \ </tem:LauncherSignIn> \ </soapenv:Body> \ </soapenv:Envelope>", password, username); int soapLength = strlen(soapBody); ZString Response = UTL::DoHTTP(szHdrs, m_szCssServerDomain, "POST", m_szCssClientServicePath, soapBody, soapLength, true); char * szToken; char * szResponse = (char*)_alloca(10000); Strcpy(szResponse, (PCC)Response); puts(szHdrs); puts("\r\n"); puts(soapBody); puts("\r\n"); puts(szResponse); puts("\r\n"); // Parse results std::tr1::regex rgx("<LauncherSignInResult.*?>.*?<a:Status>(.*?)</a:Status>.*?</LauncherSignInResult>"); std::tr1::regex rgxLoginID("<LauncherSignInResult.*?>.*?<a:LoginID>(.*?)</a:LoginID>.*?</LauncherSignInResult>"); std::tr1::smatch result; std::string strResponse(szResponse); if (std::tr1::regex_search(strResponse, result, rgxLoginID) == true && result.size() > 1) { char szLoginID[50]; sprintf(szLoginID, result[1].str().c_str()); iID = atoi(szLoginID); } if (std::tr1::regex_search(strResponse, result, rgx) == true && result.size() > 1) { char status[50]; sprintf(status, result[1].str().c_str()); if (stricmp(status, "Ok") == 0) { return true; } else if (stricmp(status, "InvalidCredentials") == 0) { sprintf(szReason, "Your user name or password are invalid. Go to acss.alleg.net to create an account, or reset a forgotten password."); return false; } else if (stricmp(status, "AccountLinked") == 0) { sprintf(szReason, "Your account has been linked to another user's account. Please log in with your main account. Please visit www.freeallegiance.org to request help in the forums."); return false; } else if (stricmp(status, "PermissionDenied") == 0) { sprintf(szReason, "Your account access has been denied. Please visit www.freeallegiance.org to request help in the forums."); return false; } else if (stricmp(status, "AccountLocked") == 0) { sprintf(szReason, "Your account has been locked. Please visit www.freeallegiance.org to request help in the forums."); return false; } else { sprintf(szReason, "Login failed with status: %s. Please visit www.freeallegiance.org to request help in the forums.", status); return false; } } sprintf(szReason, "A general sign in error occurred. Please visit www.freeallegiance.org to request help in the forums."); return false; }
void ShowAwayMsgDlg::doneEvent(ICQEvent *e) { if ( !e->Equals(icqEventTag) ) return; bool isOk = (e->Result() == EVENT_ACKED || e->Result() == EVENT_SUCCESS); QString title, result; if (e->ExtendedAck() && !e->ExtendedAck()->Accepted()) result = tr("refused"); else { switch (e->Result()) { case EVENT_FAILED: result = tr("failed"); break; case EVENT_TIMEDOUT: result = tr("timed out"); break; case EVENT_ERROR: result = tr("error"); break; default: break; } } if(!result.isEmpty()) { title = " [" + result + "]"; setCaption(caption() + title); } icqEventTag = 0; if (isOk && (e->Command() == ICQ_CMDxTCP_START || e->SNAC() == MAKESNAC(ICQ_SNACxFAM_MESSAGE, ICQ_SNACxMSG_SENDxSERVER) || e->SNAC() == MAKESNAC(ICQ_SNACxFAM_LOCATION, ICQ_SNACxLOC_INFOxREQ))) { ICQUser *u = gUserManager.FetchUser(m_szId, m_nPPID, LOCK_R); QTextCodec * codec = UserCodec::codecForICQUser(u); const char *szAutoResp = (e->ExtendedAck() && !e->ExtendedAck()->Accepted())? e->ExtendedAck()->Response() : u->AutoResponse(); if (m_nPPID == LICQ_PPID && isalpha(m_szId[0])) { // Strip HTML QString strResponse(codec->toUnicode(szAutoResp)); QRegExp regExp("<.*>"); regExp.setMinimal(true); strResponse.remove(regExp); mleAwayMsg->setText(strResponse); } else mleAwayMsg->setText(codec->toUnicode(szAutoResp)); gUserManager.DropUser(u); mleAwayMsg->setEnabled(true); mleAwayMsg->setBackgroundMode(PaletteBase); } }
BOOL CWebSocketProtocol::HandShake(HttpRequestHeader &header, CConnectionSession<CWebSocketProtocol> &pConn) { if (header.GetField("Sec-WebSocket-Key").size() > 0 && header.GetField("Sec-WebSocket-Version") == "13") { //V76协议 std::string RawKey = header.GetField("Sec-WebSocket-Key") + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; //获取Sec-WebSocket-Key然后加上固定字符串组合成新的Key //新Key SHA1后再BASE64编码成的字符串成为Sec-WebSocket-Accept的值返回给客户端 BYTE DigestKey[20]; CSHA1 sha1; CBase64 base64; sha1.Input((CHAR *)RawKey.c_str(), RawKey.size()); sha1.Result(DigestKey); std::string str = base64.Encode(DigestKey, 20); std::string strResponse("HTTP/1.1 101 Switching Protocols\r\n"); strResponse += "Upgrade: websocket\r\n"; strResponse += "Connection: Upgrade\r\n"; strResponse += "Sec-WebSocket-Accept: " + str + "\r\n"; strResponse += "WebSocket-Origin: " + header.GetOrigin() + "\r\n"; strResponse += "WebSocket-Location: ws://"; strResponse += header.GetHost() + header.GetPath() + "\r\n\r\n"; pConn.WritePacket((BYTE *)strResponse.c_str(), strResponse.size()); mWebsocketVersion = 76; mIshandShaked = TRUE; mRemainLength = 0; ZeroMemory(mDataBuffer, MAX_PACKET_BUFFER_LENGTH); GetPacket = &CWebSocketProtocol::GetPacket76; WritePacket = &CWebSocketProtocol::WritePacket76; return TRUE; } else if (header.GetField("Sec-WebSocket-Key1").size() > 0) { //如果是V75协议,头后面还跟着8字节的内容 if (header.ContentSize() == 8) { DWORD Space1Num = 0; DWORD Space2Num = 0; DWORD Key1Length; DWORD Key2Length; BYTE Digits1[20], Digits2[20]; DWORD Index = 0; DWORD Result1, Result2; const char *szkey1 = header.GetField("Sec-WebSocket-Key1").c_str(); const char *szKey2 = header.GetField("Sec-WebSocket-Key2").c_str(); Key1Length = strlen(szkey1); Key2Length = strlen(szKey2); //数空格,获取数字 for (DWORD i = 0; i<Key1Length; i++) { if (szkey1[i] == ' ') Space1Num++; else if (szkey1[i] >= '0' && szkey1[i] <= '9') { Digits1[Index++] = szkey1[i]; } } Index = 0; for (DWORD i = 0; i<Key2Length; i++) { if (szKey2[i] == ' ') Space2Num++; else if (szKey2[i] >= '0' && szKey2[i] <= '9') { Digits2[Index++] = szKey2[i]; } } //根据Key1, Key2获取两个无符号正整数,Big Endian Result1 = htonl((DWORD)((strtoul((const char *)Digits1, NULL, 10)) / Space1Num)); Result2 = htonl((DWORD)((strtoul((const char *)Digits2, NULL, 10)) / Space2Num)); //把两个整数与最后的8个字节合并成16字节数组 BYTE ResultKey[16]; CopyMemory(ResultKey, &Result1, sizeof(DWORD)); CopyMemory(ResultKey + sizeof(DWORD), &Result2, sizeof(DWORD)); CopyMemory(ResultKey + sizeof(DWORD) * 2, header.Content(), 8); std::string strResponse("HTTP/1.1 101 Web Socket Protocol Handshake\r\n"); strResponse += "Upgrade: WebSocket\r\n"; strResponse += "Connection: Upgrade\r\n"; strResponse += "Sec-WebSocket-Origin: "; strResponse += header.GetOrigin() + "\r\n"; strResponse += "Sec-WebSocket-Location: ws://"; strResponse += header.GetHost() + header.GetPath() + "\r\n\r\n"; //Md5得到的16字节 发送出去 CMD5 md5(ResultKey, 16); BYTE *md5Key = (BYTE *)md5.Digest(); BYTE Response[200]; DWORD ResponseHeaderLength = strResponse.size(); CopyMemory(Response, strResponse.c_str(), ResponseHeaderLength); CopyMemory(Response + ResponseHeaderLength, md5Key, 16); pConn.WritePacket(Response, ResponseHeaderLength+16); Response[ResponseHeaderLength+16] = '\0'; GetPacket = &CWebSocketProtocol::GetPacket75; WritePacket = &CWebSocketProtocol::WritePacket75; ZeroMemory(mDataBuffer, MAX_PACKET_BUFFER_LENGTH); mRemainLength = 0; mIshandShaked = TRUE; return TRUE; } } else { //其他情况未实现的协议,不处理 mRemainLength = 0; return FALSE; } return FALSE; }