LCOV - code coverage report
Current view: top level - home/build/openresty-1.13.6.1/build/set-misc-nginx-module-0.31/src - ngx_http_set_hex.c (source / functions) Hit Total Coverage
Test: coverage ngix Lines: 0 25 0.0 %
Date: 2020-03-03 04:25:50 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #ifndef DDEBUG
       2             : #define DDEBUG 0
       3             : #endif
       4             : #include "ddebug.h"
       5             : 
       6             : #include <ndk.h>
       7             : #include "ngx_http_set_hex.h"
       8             : 
       9             : 
      10             : ngx_int_t
      11           0 : ngx_http_set_misc_set_decode_hex(ngx_http_request_t *r, ngx_str_t *res,
      12             :     ngx_http_variable_value_t *v)
      13             : {
      14             : 
      15             :     u_char      *p;
      16             :     ngx_int_t    n;
      17             :     ngx_uint_t   i;
      18             :     size_t       len;
      19             : 
      20           0 :     if (v->len % 2 != 0) {
      21           0 :         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
      22             :                       "set_decode_hex: invalid value");
      23           0 :         return NGX_ERROR;
      24             :     }
      25             : 
      26           0 :     p = v->data;
      27           0 :     len = v->len >> 1;
      28             : 
      29           0 :     res->data = ngx_palloc(r->pool, len);
      30           0 :     if (res->data == NULL) {
      31           0 :         return NGX_ERROR;
      32             :     }
      33             : 
      34           0 :     for (i = 0; i < len; i++) {
      35           0 :         n = ngx_hextoi(p, 2);
      36           0 :         if (n == NGX_ERROR || n > 255) {
      37           0 :             ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
      38             :                           "set_decode_hex: invalid value");
      39           0 :             return NGX_ERROR;
      40             :         }
      41             : 
      42           0 :         p += 2;
      43           0 :         res->data[i] = (u_char) n;
      44             :     }
      45             : 
      46           0 :     res->len = len;
      47           0 :     return NGX_OK;
      48             : }
      49             : 
      50             : 
      51             : ngx_int_t
      52           0 : ngx_http_set_misc_set_encode_hex(ngx_http_request_t *r, ngx_str_t *res,
      53             :     ngx_http_variable_value_t *v)
      54             : {
      55           0 :     res->len = v->len << 1;
      56           0 :     res->data = ngx_palloc(r->pool, res->len);
      57           0 :     if (res->data == NULL) {
      58           0 :         return NGX_ERROR;
      59             :     }
      60             : 
      61           0 :     ngx_hex_dump(res->data, v->data, v->len);
      62           0 :     return NGX_OK;
      63             : }

Generated by: LCOV version 1.13