Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Nginx, Inc.
0004  * Copyright (C) Valentin V. Bartenev
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 #include <ngx_http.h>
0011 
0012 
0013 static u_char *ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix,
0014     ngx_uint_t value);
0015 
0016 
0017 u_char *
0018 ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, u_char *tmp,
0019     ngx_uint_t lower)
0020 {
0021     size_t  hlen;
0022 
0023     hlen = ngx_http_v2_huff_encode(src, len, tmp, lower);
0024 
0025     if (hlen > 0) {
0026         *dst = NGX_HTTP_V2_ENCODE_HUFF;
0027         dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), hlen);
0028         return ngx_cpymem(dst, tmp, hlen);
0029     }
0030 
0031     *dst = NGX_HTTP_V2_ENCODE_RAW;
0032     dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), len);
0033 
0034     if (lower) {
0035         ngx_strlow(dst, src, len);
0036         return dst + len;
0037     }
0038 
0039     return ngx_cpymem(dst, src, len);
0040 }
0041 
0042 
0043 static u_char *
0044 ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, ngx_uint_t value)
0045 {
0046     if (value < prefix) {
0047         *pos++ |= value;
0048         return pos;
0049     }
0050 
0051     *pos++ |= prefix;
0052     value -= prefix;
0053 
0054     while (value >= 128) {
0055         *pos++ = value % 128 + 128;
0056         value /= 128;
0057     }
0058 
0059     *pos++ = (u_char) value;
0060 
0061     return pos;
0062 }