📄 passport.cc
字号:
{ break; } else { Sum += Ret; if (Sum >= KP_BUFFER_SIZE) { Sum = KP_BUFFER_SIZE; break; } } } close(sk);#ifdef _DEBUG_ printf("Recive Data! [%d]\n", Sum);#endif if (Sum <= 0) { delete(m_Buffer); m_Buffer = NULL; strcpy(m_ErrorText, "接收数据错误!"); return 4; } //m_Buffer[Sum] = NULL; m_Buffer[Sum] = '\0'; //----------------------------------------------------------------------------------------- // Remove The Useless Header //----------------------------------------------------------------------------------------- while (GetReplyCode() == 1) { SetCookie(); Found = strstr(m_Buffer, "\r\n\r\nHTTP/1."); if (Found == NULL) { Found = strstr(m_Buffer, "\n\nHTTP/1."); if (Found != NULL) { Found += 2; } } else { Found += 4; } if (Found == NULL) { strcpy(m_ErrorText, "无效的HTTP应答!"); return 5; } else { strcpy(m_Buffer, Found); } } if (m_ReplyCode < 1) return 6; else SetCookie(); return 0;}int Passport::GetViewState(){ char * Found = NULL; char EC; unsigned int i = 0; if (m_Buffer != NULL) { Found = strstr(m_Buffer, "__VIEWSTATE"); if (Found != NULL) {#ifdef _DEBUG_ printf("Found VS! [%p]\n", Found);#endif Found += 12; while (i < 100) { // if (strnicmp("value", Found++, 5) == 0){ if (strncmp("value", Found++, 5) == 0){#ifdef _DEBUG_ printf("Found VS Value! [%p]\n", Found);#endif Found += 5; i = 0; while (i < 100){ if ((*Found != '=') && (*Found != ' ') && (*Found != '"') && (*Found != '\'') && (*Found != '\0')){ break; } Found++; i++; } if ((i < 100) && (*Found != '\0')){ i = 0; EC = *(Found-1); while (i < 508){ i = EncodeData(m_ViewState, i, *Found); Found++; if ((*Found == EC) || (*Found == '\0')){ break; } } m_ViewState[i] = '\0'; return true; } break; } i++; } } } strcpy(m_ErrorText, "找不到ViewState变量!"); return false;}int Passport::GetLocation(char *URL){ char * Body = NULL; char * Found = NULL; unsigned int i; if (m_Buffer == NULL) return false; Body = strstr(m_Buffer, "\r\n\r\n"); if (Body == NULL){ Body = strstr(m_Buffer, "\n\n"); }#ifdef _DEBUG_ printf("Location Body! [%p]\n", Body);#endif#ifdef _DEBUG_ printf("BODY: %s\n", Body);#endif Found = strstr(m_Buffer, "Location:");#ifdef _DEBUG_ printf("Location Found! [%p]\n", Found);#endif#ifdef _DEBUG_ printf("Location: %s\n", Found);#endif if ((Found == NULL) || (Found > Body)) return false; Found += 9; while (Found < Body){ if (*Found != ' '){ break; } Found++; } if (Found >= Body) return false; for (i = 0; i < 100; i++){ if ((Found[i] == '\r') || (Found[i] == '\n')) break; URL[i] = Found[i]; } URL[i] = '\0'; return true;}char * Passport::GetCookie(char *Data, char *Name, char *Value){ char * Body = NULL; char * Found = NULL; unsigned int i; if (Data == NULL) return false; Body = strstr(Data, "\r\n\r\n"); if (Body == NULL){ Body = strstr(Data, "\n\n"); } Found = strstr(Data, "Set-Cookie:"); if ((Found == NULL) || (Found > Body)) return NULL; Found += 11; while (Found < Body){ if (*Found != ' '){ break; } Found++; } for (i=0; i<39; i++){ Name[i] = Found[i]; if (Found[i] == '=') break; } if (Found[i] != '=') return NULL; Name[i++] = '\0'; Found += i; for (i=0; i<127; i++){ Value[i] = Found[i]; if ((Found[i] == ';') || (Found[i] == '\r') || (Found[i] == '\n')) break; } Value[i++] = '\0'; Found += i; return Found;}void Passport::SetCookie(){ bool Updated = false; char * p; char CName[40]; char CValue[128]; int Len; CookieList * CL; p = m_Buffer; while (p = GetCookie(p, CName, CValue)){ CL = m_CookieList; while (CL != NULL){ if (strcmp(CL->Name, CName) == 0) break; CL = CL->Next; } if (CL == NULL){ //------------------------ // Create New Cookie //------------------------ CL = new(CookieList); Len = strlen(CName) + 1; CL->Name = new(char[Len]); strncpy(CL->Name, CName, Len); Len = strlen(CValue) + 1; CL->Value = new(char[Len]); strncpy(CL->Value, CValue, Len); CL->Next = m_CookieList; m_CookieList = CL; }else { //--------------------------- // Update Cookie Value //--------------------------- delete(CL->Value); Len = strlen(CValue) + 1; CL->Value = new(char[Len]); strncpy(CL->Value, CValue, Len); } Updated = true; } if (Updated){ Len = 0; CL = m_CookieList; while (CL != NULL){ //--------------------------- // 防止缓冲区溢出错误 //--------------------------- if ((Len + strlen(CL->Name) + strlen(CL->Value) + 6) > KP_COOKIE_SIZE) break;#ifdef _DEBUG_ printf("Cookie: %s = %s\n", CL->Name, CL->Value);#endif if (Len == 0){ sprintf((m_Cookie + Len), "Cookie: %s=%s", CL->Name, CL->Value); }else { sprintf((m_Cookie + Len), "; %s=%s", CL->Name, CL->Value); } Len = strlen(m_Cookie); CL = CL->Next; } if (Len > 0){ strcat(m_Cookie, "\r\n"); }#ifdef _DEBUG_ printf("Cookie Updated:\n%s\nEnd Cookie Point: %p\n", m_Cookie, CL);#endif }}int Passport::GetReplyCode(){ char code; if (m_Buffer == NULL){ strcpy(m_ErrorText, "缓冲区丢失!"); return -1; } code = m_Buffer[9]; switch (code){ case '1': m_ReplyCode = 1; return 1; case '2': m_ReplyCode = 2; return 2; case '3': m_ReplyCode = 3; return 3; case '4': m_ReplyCode = 4; return 4; case '5': m_ReplyCode = 5; return 5; default: m_ReplyCode = 0; strcpy(m_ErrorText, "收到非HTTP协议应答!"); return 0; };}int Passport::GetMsg(char *Name, char *Msg){ char * Found = NULL; int Len; if ((m_Buffer == NULL) || (Msg == NULL)){ strcpy(m_ErrorText, "缓冲区丢失!"); return 1; } Found = strstr(m_Buffer, "\r\n\r\n"); if (Found == NULL){ Found = strstr(m_Buffer, "\n\n"); } if (Found == NULL){ strcpy(m_ErrorText, "HTTP数据包错误!"); return 1; } Found = strstr(Found, Name); if (Found == NULL){ return 2; } for (Len = 0; Len < 100; Len++){ if ((Found[Len] == '>') || (Found[Len] == '\0')) break; } if (Found[Len++] == '>'){ Found += Len; for (Len = 0; Len < 100; Len++){ if ((Found[Len] == '<') || (Found[Len] == '\0')) break; Msg[Len] = Found[Len]; } if (Len > 0){ Msg[Len] = '\0'; // add UTF-8 to ASCII code //############################################################# // Utf8toASCII(Msg, Msg, 256); // ##############################################################3 return 0; }else { return 2; } }else { return 2; }}void Passport::SetInternational(bool data){ m_International = data;}void Passport::SetConnectionTimeout(int TimeOut){ m_ConnectionTimeout = TimeOut;#ifdef _DEBUG_ printf("Connect Timout: %d\n", m_ConnectionTimeout);#endif }int Passport::EncodeData(char *Dsc, int Offset, char ch){ int i; i = Offset; switch (ch){ case '+': Dsc[i++] = '%'; Dsc[i++] = '2'; Dsc[i++] = 'B'; break; case '=': Dsc[i++] = '%'; Dsc[i++] = '3'; Dsc[i++] = 'D'; break; case '/': Dsc[i++] = '%'; Dsc[i++] = '2'; Dsc[i++] = 'F'; break; case '?': Dsc[i++] = '%'; Dsc[i++] = '3'; Dsc[i++] = 'F'; break; case '%': Dsc[i++] = '%'; Dsc[i++] = '2'; Dsc[i++] = '5'; break; default: Dsc[i++] = ch; } return i;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -