bool HttpTools::_parseAuthorization(const LPSTR source, DWORD sourceSize, LPWSTR *userName, LPWSTR *password) { bool retVal = false; //Basic if(sourceSize > 6 && Str::_CompareA("Basic ", source, 6, 6) == 0) { LPSTR p = (LPSTR)source + 6; while(IS_SPACE_CHAR(*p))p++; //Just in case. Line 100% konachaetsya to zero. LPSTR decoded; SIZE_T decodedSize; if((decoded = (LPSTR)Crypt::_base64Decode(p, (SIZE_T)(source + sourceSize - p), &decodedSize)) != NULL) { if((p = Str::_findCharA(decoded, ':')) != NULL) { *userName = Str::_utf8ToUnicode(decoded, p - decoded); *password = Str::_utf8ToUnicode(p + 1, -1); retVal = true; } Mem::free(decoded); } } return retVal; }
static void mouse_do_cut(scr_stat *scp, int from, int to) { int blank; int i; int leadspaces; int p; int s; for (p = from, i = blank = leadspaces = 0; p <= to; ++p) { cut_buffer[i] = sc_vtb_getc(&scp->vtb, p); /* Be prepared that sc_vtb_getc() can return '\0' */ if (cut_buffer[i] == '\0') cut_buffer[i] = ' '; #ifdef SC_CUT_SPACES2TABS if (leadspaces != -1) { if (IS_SPACE_CHAR(cut_buffer[i])) { leadspaces++; /* Check that we are at tabstop position */ if ((p % scp->xsize) % 8 == 7) { i -= leadspaces - 1; cut_buffer[i] = '\t'; leadspaces = 0; } } else { leadspaces = -1; } } #endif /* SC_CUT_SPACES2TABS */ /* remember the position of the last non-space char */ if (!IS_BLANK_CHAR(cut_buffer[i])) blank = i + 1; /* the first space after the last non-space */ ++i; /* trim trailing blank when crossing lines */ if ((p % scp->xsize) == (scp->xsize - 1)) { cut_buffer[blank++] = '\r'; i = blank; leadspaces = 0; } } cut_buffer[i] = '\0'; /* remove the current marking */ s = spltty(); if (scp->mouse_cut_start <= scp->mouse_cut_end) { mark_for_update(scp, scp->mouse_cut_start); mark_for_update(scp, scp->mouse_cut_end); } else if (scp->mouse_cut_end >= 0) { mark_for_update(scp, scp->mouse_cut_end); mark_for_update(scp, scp->mouse_cut_start); } /* mark the new region */ scp->mouse_cut_start = from; scp->mouse_cut_end = to; mark_for_update(scp, from); mark_for_update(scp, to); splx(s); }
bool HttpTools::_compareTagNameA(const LPSTR tag, DWORD tagSize, const LPSTR string) { LPSTR pos = string; if(*pos == '<')pos++; if(*pos == '/')pos++; if(CWA(shlwapi, StrCmpNIA)(pos, tag, tagSize) == 0) { BYTE c = *(pos + tagSize); if(c == 0 || IS_SPACE_CHAR(c) || c == '>' || c == '/')return true; } return false; }
/* skip spaces to left */ static int skip_spc_left(scr_stat *scp, int p) { int c; int i; for (i = p-- % scp->xsize - 1; i >= 0; --i) { c = sc_vtb_getc(&scp->vtb, p); if (!IS_SPACE_CHAR(c)) break; --p; } return i; }
/* skip spaces to right */ static int skip_spc_right(scr_stat *scp, int p) { int c; int i; for (i = p % scp->xsize; i < scp->xsize; ++i) { c = sc_vtb_getc(&scp->vtb, p); if (!IS_SPACE_CHAR(c)) break; ++p; } return i; }
void c_string_trim_end(c_string *str) { if (str == NULL) { return; } char *pc = str->buf + str->len -1; while (IS_SPACE_CHAR(*pc)) { *pc = '\0'; --pc; --str->len; } }
/* copy marked region to the cut buffer */ static void mouse_cut(scr_stat *scp) { int start; int end; int from; int to; int c; int p; int s; int i; start = scp->mouse_cut_start; end = scp->mouse_cut_end; if (scp->mouse_pos >= start) { from = start; to = end = scp->mouse_pos; } else { from = end = scp->mouse_pos; to = start - 1; } p = to; for (i = p % scp->xsize; i < scp->xsize; ++i) { c = sc_vtb_getc(&scp->vtb, p); if (!IS_SPACE_CHAR(c)) break; ++p; } /* if there is nothing but blank chars, trim them, but mark towards eol */ if (i == scp->xsize) { if (end >= start) to = end = p - 1; else to = start = p; } mouse_do_cut(scp, from, to); s = spltty(); scp->mouse_cut_start = start; scp->mouse_cut_end = end; splx(s); }
void c_string_trim_start(c_string *str) { if (str == NULL) { return; } char *pc = NULL; for (pc =str->buf; IS_SPACE_CHAR(*pc); ++pc); if (pc != str->buf) { char *tmp = str->buf; while (*pc) { *tmp = *pc; ++tmp; ++pc; } *tmp = '\0'; } }
/* copy a word under the mouse pointer */ static void mouse_cut_word(scr_stat *scp) { int start; int end; int sol; int eol; int c; int i; int j; /* * Because we don't have locale information in the kernel, * we only distinguish space char and non-space chars. Punctuation * chars, symbols and other regular chars are all treated alike. */ if (scp->status & MOUSE_VISIBLE) { /* remove the current cut mark */ crit_enter(); if (scp->mouse_cut_start <= scp->mouse_cut_end) { mark_for_update(scp, scp->mouse_cut_start); mark_for_update(scp, scp->mouse_cut_end); } else if (scp->mouse_cut_end >= 0) { mark_for_update(scp, scp->mouse_cut_end); mark_for_update(scp, scp->mouse_cut_start); } scp->mouse_cut_start = scp->xsize*scp->ysize; scp->mouse_cut_end = -1; crit_exit(); sol = (scp->mouse_pos / scp->xsize) * scp->xsize; eol = sol + scp->xsize; c = sc_vtb_getc(&scp->vtb, scp->mouse_pos); if (IS_SPACE_CHAR(c)) { /* blank space */ for (j = scp->mouse_pos; j >= sol; --j) { c = sc_vtb_getc(&scp->vtb, j); if (!IS_SPACE_CHAR(c)) break; } start = ++j; for (j = scp->mouse_pos; j < eol; ++j) { c = sc_vtb_getc(&scp->vtb, j); if (!IS_SPACE_CHAR(c)) break; } end = j - 1; } else { /* non-space word */ for (j = scp->mouse_pos; j >= sol; --j) { c = sc_vtb_getc(&scp->vtb, j); if (IS_SPACE_CHAR(c)) break; } start = ++j; for (j = scp->mouse_pos; j < eol; ++j) { c = sc_vtb_getc(&scp->vtb, j); if (IS_SPACE_CHAR(c)) break; } end = j - 1; } /* copy the found word */ for (i = 0, j = start; j <= end; ++j) cut_buffer[i++] = sc_vtb_getc(&scp->vtb, j); cut_buffer[i] = '\0'; scp->status |= MOUSE_CUTTING; /* mark the region */ crit_enter(); scp->mouse_cut_start = start; scp->mouse_cut_end = end; mark_for_update(scp, start); mark_for_update(scp, end); crit_exit(); } }
/* copy marked region to the cut buffer */ static void mouse_cut(scr_stat *scp) { int start; int end; int from; int to; int blank; int c; int p; int i; start = scp->mouse_cut_start; if (scp->mouse_pos >= start) { from = start; to = end = scp->mouse_pos; } else { from = end = scp->mouse_pos; to = start - 1; } for (p = from, i = blank = 0; p <= to; ++p) { cut_buffer[i] = sc_vtb_getc(&scp->vtb, p); /* remember the position of the last non-space char */ if (!IS_SPACE_CHAR(cut_buffer[i++])) blank = i; /* the first space after the last non-space */ /* trim trailing blank when crossing lines */ if ((p % scp->xsize) == (scp->xsize - 1)) { cut_buffer[blank] = '\r'; i = blank + 1; } } cut_buffer[i] = '\0'; /* scan towards the end of the last line */ --p; for (i = p % scp->xsize; i < scp->xsize; ++i) { c = sc_vtb_getc(&scp->vtb, p); if (!IS_SPACE_CHAR(c)) break; ++p; } /* if there is nothing but blank chars, trim them, but mark towards eol */ if (i >= scp->xsize) { if (end >= start) to = end = p - 1; else to = start = p; cut_buffer[blank++] = '\r'; cut_buffer[blank] = '\0'; } /* remove the current marking */ crit_enter(); if (scp->mouse_cut_start <= scp->mouse_cut_end) { mark_for_update(scp, scp->mouse_cut_start); mark_for_update(scp, scp->mouse_cut_end); } else if (scp->mouse_cut_end >= 0) { mark_for_update(scp, scp->mouse_cut_end); mark_for_update(scp, scp->mouse_cut_start); } /* mark the new region */ scp->mouse_cut_start = start; scp->mouse_cut_end = end; mark_for_update(scp, from); mark_for_update(scp, to); crit_exit(); }
LPSTR HttpTools::_getMimeHeader(const void *mimeData, DWORD mimeSize, const LPSTR header, SIZE_T *size) { SIZE_T headerSize = ((DWORD_PTR)header > GMH_COUNT ? Str::_LengthA(header) : 0); LPSTR data = (LPSTR)mimeData; LPSTR dataEnd = data + mimeSize; *size = 0; while(data < dataEnd) { LPSTR cur = data; SIZE_T curSize = Str::_getCurrentStringSizeA(data, dataEnd, &data); //If an empty string. if(curSize == 0) { if((DWORD_PTR)header == GMH_DATA) { *size = (SIZE_T)(dataEnd - data); return data; } return NULL; //After a blank line is no longer headers. } //These data can be obtained only from the first row. if(cur == (LPSTR)mimeData && ((DWORD_PTR)header == GMH_HTTP_METHOD || (DWORD_PTR)header == GMH_HTTP_URI || (DWORD_PTR)header == GMH_REQUEST_HTTP_VERSION)) { //Ischim all the gaps. LPSTR spaces[2]; DWORD count = 0; dataEnd = cur + curSize; for(LPSTR p = cur; p < dataEnd; p++)if(IS_SPACE_CHAR(*p)) { if(count < 2)spaces[count] = p; count++; } if(count == 2) { if((DWORD_PTR)header == GMH_HTTP_METHOD)dataEnd = spaces[0]; else if((DWORD_PTR)header == GMH_HTTP_URI){cur = spaces[0] + 1; dataEnd = spaces[1];} else if((DWORD_PTR)header == GMH_REQUEST_HTTP_VERSION)cur = spaces[1] + 1; *size = (SIZE_T)(dataEnd - cur); return cur; } return NULL; } else if(curSize > headerSize && CWA(shlwapi, StrCmpNIA)(header, cur, headerSize) == 0 && cur[headerSize] == ':') { dataEnd = cur + curSize; cur = cur + headerSize + 1; while(IS_SPACE_CHAR(*cur))cur++; *size = (SIZE_T)(dataEnd - cur); return cur; } } return NULL; }