⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngx_string.c

📁 Nginx是一个高性能的HTTP和反向代理服务器
💻 C
📖 第 1 页 / 共 3 页
字号:
ngx_strncasecmp(u_char *s1, u_char *s2, size_t n){    ngx_uint_t  c1, c2;    while (n) {        c1 = (ngx_uint_t) *s1++;        c2 = (ngx_uint_t) *s2++;        c1  = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;        c2  = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;        if (c1 == c2) {            if (c1) {                n--;                continue;            }            return 0;        }        return c1 - c2;    }    return 0;}u_char *ngx_strnstr(u_char *s1, char *s2, size_t len){    u_char  c1, c2;    size_t  n;    c2 = *(u_char *) s2++;    n = ngx_strlen(s2);    do {        do {            if (len-- == 0) {                return NULL;            }            c1 = *s1++;            if (c1 == 0) {                return NULL;            }        } while (c1 != c2);        if (n > len) {            return NULL;        }    } while (ngx_strncmp(s1, (u_char *) s2, n) != 0);    return --s1;}/* * ngx_strstrn() and ngx_strcasestrn() are intended to search for static * substring with known length in null-terminated string. The argument n * must be length of the second substring - 1. */u_char *ngx_strstrn(u_char *s1, char *s2, size_t n){    u_char  c1, c2;    c2 = *(u_char *) s2++;    do {        do {            c1 = *s1++;            if (c1 == 0) {                return NULL;            }        } while (c1 != c2);    } while (ngx_strncmp(s1, (u_char *) s2, n) != 0);    return --s1;}u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n){    ngx_uint_t  c1, c2;    c2 = (ngx_uint_t) *s2++;    c2  = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;    do {        do {            c1 = (ngx_uint_t) *s1++;            if (c1 == 0) {                return NULL;            }            c1  = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;        } while (c1 != c2);    } while (ngx_strncasecmp(s1, (u_char *) s2, n) != 0);    return --s1;}ngx_int_tngx_rstrncmp(u_char *s1, u_char *s2, size_t n){    if (n == 0) {        return 0;    }    n--;    for ( ;; ) {        if (s1[n] != s2[n]) {            return s1[n] - s2[n];        }        if (n == 0) {            return 0;        }        n--;    }}ngx_int_tngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n){    u_char  c1, c2;    if (n == 0) {        return 0;    }    n--;    for ( ;; ) {        c1 = s1[n];        if (c1 >= 'a' && c1 <= 'z') {            c1 -= 'a' - 'A';        }        c2 = s2[n];        if (c2 >= 'a' && c2 <= 'z') {            c2 -= 'a' - 'A';        }        if (c1 != c2) {            return c1 - c2;        }        if (n == 0) {            return 0;        }        n--;    }}ngx_int_tngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2){    size_t     n;    ngx_int_t  m, z;    if (n1 <= n2) {        n = n1;        z = -1;    } else {        n = n2;        z = 1;    }    m = ngx_memcmp(s1, s2, n);    if (m || n1 == n2) {        return m;    }    return z;}ngx_int_tngx_atoi(u_char *line, size_t n){    ngx_int_t  value;    if (n == 0) {        return NGX_ERROR;    }    for (value = 0; n--; line++) {        if (*line < '0' || *line > '9') {            return NGX_ERROR;        }        value = value * 10 + (*line - '0');    }    if (value < 0) {        return NGX_ERROR;    } else {        return value;    }}ssize_tngx_atosz(u_char *line, size_t n){    ssize_t  value;    if (n == 0) {        return NGX_ERROR;    }    for (value = 0; n--; line++) {        if (*line < '0' || *line > '9') {            return NGX_ERROR;        }        value = value * 10 + (*line - '0');    }    if (value < 0) {        return NGX_ERROR;    } else {        return value;    }}off_tngx_atoof(u_char *line, size_t n){    off_t  value;    if (n == 0) {        return NGX_ERROR;    }    for (value = 0; n--; line++) {        if (*line < '0' || *line > '9') {            return NGX_ERROR;        }        value = value * 10 + (*line - '0');    }    if (value < 0) {        return NGX_ERROR;    } else {        return value;    }}time_tngx_atotm(u_char *line, size_t n){    time_t  value;    if (n == 0) {        return NGX_ERROR;    }    for (value = 0; n--; line++) {        if (*line < '0' || *line > '9') {            return NGX_ERROR;        }        value = value * 10 + (*line - '0');    }    if (value < 0) {        return NGX_ERROR;    } else {        return value;    }}ngx_int_tngx_hextoi(u_char *line, size_t n){    u_char     c, ch;    ngx_int_t  value;    if (n == 0) {        return NGX_ERROR;    }    for (value = 0; n--; line++) {        ch = *line;        if (ch >= '0' && ch <= '9') {            value = value * 16 + (ch - '0');            continue;        }        c = (u_char) (ch | 0x20);        if (c >= 'a' && c <= 'f') {            value = value * 16 + (c - 'a' + 10);            continue;        }        return NGX_ERROR;    }    if (value < 0) {        return NGX_ERROR;    } else {        return value;    }}u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len){    static u_char  hex[] = "0123456789abcdef";    while (len--) {        *dst++ = hex[*src >> 4];        *dst++ = hex[*src++ & 0xf];    }    return dst;}voidngx_encode_base64(ngx_str_t *dst, ngx_str_t *src){    u_char         *d, *s;    size_t          len;    static u_char   basis64[] =            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";    len = src->len;    s = src->data;    d = dst->data;    while (len > 2) {        *d++ = basis64[(s[0] >> 2) & 0x3f];        *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)];        *d++ = basis64[((s[1] & 0x0f) << 2) | (s[2] >> 6)];        *d++ = basis64[s[2] & 0x3f];        s += 3;        len -= 3;    }    if (len) {        *d++ = basis64[(s[0] >> 2) & 0x3f];        if (len == 1) {            *d++ = basis64[(s[0] & 3) << 4];            *d++ = '=';        } else {            *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)];            *d++ = basis64[(s[1] & 0x0f) << 2];        }        *d++ = '=';    }    dst->len = d - dst->data;}ngx_int_tngx_decode_base64(ngx_str_t *dst, ngx_str_t *src){    size_t          len;    u_char         *d, *s;    static u_char   basis64[] = {        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63,        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,        77,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77,        77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,        77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77    };    for (len = 0; len < src->len; len++) {        if (src->data[len] == '=') {            break;        }        if (basis64[src->data[len]] == 77) {            return NGX_ERROR;        }    }    if (len % 4 == 1) {        return NGX_ERROR;    }    s = src->data;    d = dst->data;    while (len > 3) {        *d++ = (u_char) (basis64[s[0]] << 2 | basis64[s[1]] >> 4);        *d++ = (u_char) (basis64[s[1]] << 4 | basis64[s[2]] >> 2);        *d++ = (u_char) (basis64[s[2]] << 6 | basis64[s[3]]);        s += 4;        len -= 4;    }    if (len > 1) {        *d++ = (u_char) (basis64[s[0]] << 2 | basis64[s[1]] >> 4);    }    if (len > 2) {        *d++ = (u_char) (basis64[s[1]] << 4 | basis64[s[2]] >> 2);    }    dst->len = d - dst->data;    return NGX_OK;}/* * ngx_utf_decode() decodes two and more bytes UTF sequences only * the return values: *    0x80 - 0x10ffff         valid character *    0x10ffff - 0xfffffffd   invalid sequence *    0xfffffffe              incomplete sequence *    0xffffffff              error */uint32_tngx_utf_decode(u_char **p, size_t n){    size_t    len;    uint32_t  u, i, valid;    u = **p;    if (u > 0xf0) {        u &= 0x07;        valid = 0xffff;        len = 3;    } else if (u > 0xe0) {        u &= 0x0f;        valid = 0x7ff;        len = 2;    } else if (u > 0xc0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -