result_t HttpMessage::set_protocol(const char *newVal) { if (qstrcmp(newVal, "HTTP/", 5) || !qisdigit(newVal[5]) || newVal[6] != '.' || !qisdigit(newVal[7]) || newVal[8]) return CHECK_ERROR(Runtime::setError("HttpRequest: bad protocol version.")); m_keepAlive = ((newVal[5] - '0') * 10 + newVal[7] - '0') > 10; m_protocol = newVal; return 0; }
result_t HttpMessage::set_protocol(exlib::string newVal) { const char* c_str = newVal.c_str(); if (qstrcmp(c_str, "HTTP/", 5) || !qisdigit(c_str[5]) || c_str[6] != '.' || !qisdigit(c_str[7]) || c_str[8]) return CHECK_ERROR(Runtime::setError("HttpRequest: bad protocol version.")); m_keepAlive = ((c_str[5] - '0') * 10 + c_str[7] - '0') > 10; m_protocol = newVal; return 0; }
//-------------------------------------------------------------------------- // procedure for get_ref_addr int check_special_label(char buf[MAXSTR], register int len) { if( (unsigned)len >= sizeof("met000_end")-1 && (*(uint32*)buf & 0xFFFFFF) == ('m'|('e'<<8)|('t'<<16))) { switch ( *(uint32*)&buf[len -= 4] ) { case ('_'|('e'<<8)|('n'<<16)|('d'<<24)): break; case ('e'|('g'<<8)|('i'<<16)|('n'<<24)): if( (unsigned)len >= sizeof("met000_begin")-1 - 4 && *(ushort*)&buf[len -= 2] == ('_'|('b'<<8))) break; //PASS THRU default: len |= -1; // as flag break; } if ( (unsigned)len <= sizeof("met00000")-1 ) { uint32 off = curSeg.CodeSize; if ( buf[len+1] == 'b' ) off &= 0; register unsigned n = 0, j = sizeof("met")-1; for( ; ; ) { if ( !qisdigit((uchar)buf[j]) ) break; n = n*10 + (buf[j] - '0'); if ( ++j == len ) { if ( n >= 0x10000 || (ushort)n != curSeg.id.Number ) break; return((int)off); } } } } return(-1); }
void Url::parseHost(const char*& url, exlib::string& hostname, exlib::string& port) { const char* p1 = url; const char* p2 = NULL; char ch; if (*p1 == '[') { p1++; while ((ch = *p1) && (qisxdigit(ch) || ch == ':' || ch == '.')) p1++; if (ch == ']') ch = *++p1; else url++; } else { while ((ch = *p1) && (qisascii(ch) || qisdigit(ch) || ch == '.' || ch == '_' || ch == '-' || ch < 0)) p1++; } if (ch == ':') { p2 = p1 + 1; while ((ch = *p2) && qisdigit(ch)) p2++; } if (*url == '[') hostname.assign(url + 1, p1 - url - 2); else hostname.assign(url, p1 - url); if (hostname.length() > 0) { qstrlwr(&hostname[0]); punycode_base::toASCII(hostname, hostname); } if (p2) port.assign(p1 + 1, p2 - p1 - 1); else port.clear(); url = p2 ? p2 : p1; }
static int32_t command(AsyncState* pState, int32_t n) { asyncReadFrom* pThis = (asyncReadFrom*)pState; result_t hr; if (pThis->m_strLine.length() < 12 || pThis->m_strLine[8] != ' ' || !qisdigit(pThis->m_strLine[9]) || !qisdigit(pThis->m_strLine[10]) || !qisdigit(pThis->m_strLine[11]) || (pThis->m_strLine.length() > 12 && qisdigit(pThis->m_strLine[12]))) return CHECK_ERROR(Runtime::setError("HttpResponse: bad protocol: " + pThis->m_strLine)); pThis->m_pThis->set_status(atoi(pThis->m_strLine.c_str() + 8)); pThis->m_strLine.resize(8); hr = pThis->m_pThis->set_protocol(pThis->m_strLine); if (hr < 0) return hr; pThis->done(); return pThis->m_pThis->m_message->readFrom(pThis->m_stm, pThis); }
static int32_t recv(AsyncState *pState, int32_t n) { asyncSmtp *pThis = (asyncSmtp *) pState; std::string &strLine = pThis->m_strLine; if (&pThis->m_retVal != &strLine) { if (pThis->m_retVal.length()) pThis->m_retVal.append("\r\n", 2); pThis->m_retVal.append(strLine); } if (qisdigit(strLine[0]) && qisdigit(strLine[1]) && qisdigit(strLine[2]) && strLine[3] == ' ') { if (strLine[0] == '5') return CHECK_ERROR(Runtime::setError(strLine)); return pThis->recv_ok(); } return pThis->m_stmBuffered->readLine(SMTP_MAX_LINE, strLine, pThis); }
void Url::parseProtocol(const char*& url) { const char* p = url; char ch; while ((ch = *p) && (qisascii(ch) || qisdigit(ch) || ch == '.' || ch == '+' || ch == '-')) p++; if (ch == ':') { p++; exlib::string str(url, p - url); set_protocol(str); url = p; } }
void out(const char *s, FILE *stream) { wstring ws = utf8to16String(s); wchar *ptr = &ws[0]; wchar *ptr2; while (ptr2 = (wchar *) qstrchr(ptr, L'\x1b')) { if (ptr2[1] == '[') { ptr2[0] = 0; fputws(ptr, stream); fflush(stream); ptr2 += 2; while (true) { if (ptr2[0] == 'm') { m_Now = m_wAttr; m_wLight = m_wAttr & FOREGROUND_INTENSITY; SetConsoleTextAttribute(m_handle, m_Now); ptr2 ++; break; } if (qisdigit(ptr2[0])) { if (ptr2[1] == 'm') { if (ptr2[0] == '0') { m_Now = m_wAttr; m_wLight = m_wAttr & FOREGROUND_INTENSITY; SetConsoleTextAttribute(m_handle, m_Now); } ptr2 += 2; break; } WORD mask, val; WORD light = m_wLight; if (ptr2[1] == ';') { if (ptr2[0] == '0') m_wLight = light = 0; else if (ptr2[0] == '1') m_wLight = light = FOREGROUND_INTENSITY; ptr2 += 2; } if (ptr2[0] == '3') { mask = 0xf0; ptr2 ++; } else if (ptr2[0] == '4') { mask = 0x0f; ptr2 ++; } else if (ptr2[0] == '9') { mask = 0xf0; light |= FOREGROUND_INTENSITY; ptr2 ++; } else if (ptr2[0] == '1' && ptr2[1] == '0') { mask = 0x0f; light |= FOREGROUND_INTENSITY << 4; ptr2 += 2; } else break; if (!qisdigit(ptr2[0])) break; val = ptr2[0] - '0'; if (val != 8) { if (val == 9) { val = (m_wAttr & 0x0f) | (m_Now & 0xf0); m_Now = val | light; SetConsoleTextAttribute(m_handle, m_Now); } else { val = (val & 2) | ((val & 1) ? 4 : 0) | ((val & 4) ? 1 : 0); if (mask == 0x0f) val <<= 4; m_Now = (m_Now & mask) | val | light; SetConsoleTextAttribute(m_handle, m_Now); } } ptr2 ++; if (ptr2[0] == 'm') { ptr2 ++; break; } } } } ptr = ptr2; } fputws(ptr, stream); fflush(stream); }
void out(exlib::string& s) { static HANDLE s_console; if (!m_tty) { fwrite(s.c_str(), 1, s.length(), stdout); return; } if (!m_handle) { if (!s_console) { AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); s_console = GetStdHandle(STD_OUTPUT_HANDLE); } m_handle = s_console; m_Now = m_wAttr = 0x7; m_wLight = m_wAttr & FOREGROUND_INTENSITY; } exlib::wstring ws = utf8to16String(s); exlib::wchar* ptr = &ws[0]; exlib::wchar* pend = ptr + ws.length(); exlib::wchar* ptr2; while (ptr2 = (exlib::wchar*)qstrchr(ptr, L'\x1b')) { if (ptr2[1] == '[') { WriteConsole(ptr, ptr2 - ptr); ptr2 += 2; while (true) { if (ptr2[0] == 'm') { m_Now = m_wAttr; m_wLight = m_wAttr & FOREGROUND_INTENSITY; SetConsoleTextAttribute(m_handle, m_Now); ptr2++; break; } if (qisdigit(ptr2[0])) { if (ptr2[1] == 'm') { if (ptr2[0] == '0') { m_Now = m_wAttr; m_wLight = m_wAttr & FOREGROUND_INTENSITY; SetConsoleTextAttribute(m_handle, m_Now); } ptr2 += 2; break; } WORD mask, val; WORD light = m_wLight; if (ptr2[1] == ';') { if (ptr2[0] == '0') m_wLight = light = 0; else if (ptr2[0] == '1') m_wLight = light = FOREGROUND_INTENSITY; ptr2 += 2; } if (ptr2[0] == '3') { mask = 0xf0; ptr2++; } else if (ptr2[0] == '4') { mask = 0x0f; ptr2++; } else if (ptr2[0] == '9') { mask = 0xf0; light |= FOREGROUND_INTENSITY; ptr2++; } else if (ptr2[0] == '1' && ptr2[1] == '0') { mask = 0x0f; light |= FOREGROUND_INTENSITY << 4; ptr2 += 2; } else break; if (!qisdigit(ptr2[0])) break; val = ptr2[0] - '0'; if (val != 8) { if (val == 9) { val = (m_wAttr & 0x0f) | (m_Now & 0xf0); m_Now = val | light; SetConsoleTextAttribute(m_handle, m_Now); } else { val = (val & 2) | ((val & 1) ? 4 : 0) | ((val & 4) ? 1 : 0); if (mask == 0x0f) val <<= 4; m_Now = (m_Now & mask) | val | light; SetConsoleTextAttribute(m_handle, m_Now); } } ptr2++; if (ptr2[0] == 'm') { ptr2++; break; } } } } ptr = ptr2; } WriteConsole(ptr, pend - ptr); }
void out(exlib::string& s) { exlib::wstring ws = utf8to16String(s); exlib::wchar *ptr = &ws[0]; exlib::wchar *pend = ptr + ws.length(); exlib::wchar *ptr2; DWORD dwWrite; while (ptr2 = (exlib::wchar *) qstrchr(ptr, L'\x1b')) { if (ptr2[1] == '[') { WriteConsoleW(m_handle, ptr, (DWORD)(ptr2 - ptr), &dwWrite, NULL); ptr2 += 2; while (true) { if (ptr2[0] == 'm') { m_Now = m_wAttr; m_wLight = m_wAttr & FOREGROUND_INTENSITY; SetConsoleTextAttribute(m_handle, m_Now); ptr2 ++; break; } if (qisdigit(ptr2[0])) { if (ptr2[1] == 'm') { if (ptr2[0] == '0') { m_Now = m_wAttr; m_wLight = m_wAttr & FOREGROUND_INTENSITY; SetConsoleTextAttribute(m_handle, m_Now); } ptr2 += 2; break; } WORD mask, val; WORD light = m_wLight; if (ptr2[1] == ';') { if (ptr2[0] == '0') m_wLight = light = 0; else if (ptr2[0] == '1') m_wLight = light = FOREGROUND_INTENSITY; ptr2 += 2; } if (ptr2[0] == '3') { mask = 0xf0; ptr2 ++; } else if (ptr2[0] == '4') { mask = 0x0f; ptr2 ++; } else if (ptr2[0] == '9') { mask = 0xf0; light |= FOREGROUND_INTENSITY; ptr2 ++; } else if (ptr2[0] == '1' && ptr2[1] == '0') { mask = 0x0f; light |= FOREGROUND_INTENSITY << 4; ptr2 += 2; } else break; if (!qisdigit(ptr2[0])) break; val = ptr2[0] - '0'; if (val != 8) { if (val == 9) { val = (m_wAttr & 0x0f) | (m_Now & 0xf0); m_Now = val | light; SetConsoleTextAttribute(m_handle, m_Now); } else { val = (val & 2) | ((val & 1) ? 4 : 0) | ((val & 4) ? 1 : 0); if (mask == 0x0f) val <<= 4; m_Now = (m_Now & mask) | val | light; SetConsoleTextAttribute(m_handle, m_Now); } } ptr2 ++; if (ptr2[0] == 'm') { ptr2 ++; break; } } } } ptr = ptr2; } WriteConsoleW(m_handle, ptr, (DWORD)(pend - ptr), &dwWrite, NULL); }