Ticket #838: patch-838.diff

File patch-838.diff, 6.1 KB (added by elektro-wolle@…, 11 years ago)

Patch to enable compare operators

  • src/http/modules/ngx_http_rewrite_module.c

    diff -r 18428f775b2c src/http/modules/ngx_http_rewrite_module.c
    a b  
    748748            return NGX_CONF_OK;
    749749        }
    750750
     751        if (len == 2 && p[0] == 'l' && p[1] == 't') {
     752
     753            if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
     754                return NGX_CONF_ERROR;
     755            }
     756
     757            code = ngx_http_script_start_code(cf->pool, &lcf->codes,
     758                                              sizeof(uintptr_t));
     759            if (code == NULL) {
     760                return NGX_CONF_ERROR;
     761            }
     762
     763            *code = ngx_http_script_lt_code;
     764            return NGX_CONF_OK;
     765        }     
     766        if (len == 2 && p[0] == 'l' && p[1] == 'e') {
     767
     768            if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
     769                return NGX_CONF_ERROR;
     770            }
     771
     772            code = ngx_http_script_start_code(cf->pool, &lcf->codes,
     773                                              sizeof(uintptr_t));
     774            if (code == NULL) {
     775                return NGX_CONF_ERROR;
     776            }
     777
     778            *code = ngx_http_script_le_code;
     779            return NGX_CONF_OK;
     780        }     
     781        if (len == 2 && p[0] == 'g' && p[1] == 't') {
     782
     783            if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
     784                return NGX_CONF_ERROR;
     785            }
     786
     787            code = ngx_http_script_start_code(cf->pool, &lcf->codes,
     788                                              sizeof(uintptr_t));
     789            if (code == NULL) {
     790                return NGX_CONF_ERROR;
     791            }
     792
     793            *code = ngx_http_script_gt_code;
     794            return NGX_CONF_OK;
     795        }     
     796        if (len == 2 && p[0] == 'g' && p[1] == 'e') {
     797
     798            if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
     799                return NGX_CONF_ERROR;
     800            }
     801
     802            code = ngx_http_script_start_code(cf->pool, &lcf->codes,
     803                                              sizeof(uintptr_t));
     804            if (code == NULL) {
     805                return NGX_CONF_ERROR;
     806            }
     807
     808            *code = ngx_http_script_ge_code;
     809            return NGX_CONF_OK;
     810        }     
     811     
    751812        if ((len == 1 && p[0] == '~')
    752813            || (len == 2 && p[0] == '~' && p[1] == '*')
    753814            || (len == 2 && p[0] == '!' && p[1] == '~')
  • src/http/ngx_http_script.c

    diff -r 18428f775b2c src/http/ngx_http_script.c
    a b  
    14661466    *res = ngx_http_variable_true_value;
    14671467}
    14681468
     1469void
     1470ngx_http_script_lt_code(ngx_http_script_engine_t *e)
     1471{
     1472    ngx_http_variable_value_t  *val, *res;
     1473
     1474    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1475                   "http script lt");
     1476
     1477    e->sp--;
     1478    val = e->sp;
     1479    res = e->sp - 1;
     1480
     1481    e->ip += sizeof(uintptr_t);
     1482
     1483    if (val->len >= res->len
     1484        && ngx_strncmp(val->data, res->data, res->len) > 0)
     1485    {
     1486        *res = ngx_http_variable_true_value;
     1487        return;
     1488    }
     1489
     1490    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1491                   "http script lt: no");
     1492
     1493    *res = ngx_http_variable_null_value;
     1494}
     1495
     1496void
     1497ngx_http_script_le_code(ngx_http_script_engine_t *e)
     1498{
     1499    ngx_http_variable_value_t  *val, *res;
     1500
     1501    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1502                   "http script le");
     1503
     1504    e->sp--;
     1505    val = e->sp;
     1506    res = e->sp - 1;
     1507
     1508    e->ip += sizeof(uintptr_t);
     1509
     1510    if (val->len >= res->len
     1511        && ngx_strncmp(val->data, res->data, res->len) >= 0)
     1512    {
     1513        *res = ngx_http_variable_true_value;
     1514        return;
     1515    }
     1516
     1517    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1518                   "http script le: no");
     1519
     1520    *res = ngx_http_variable_null_value;
     1521}
     1522
     1523void
     1524ngx_http_script_gt_code(ngx_http_script_engine_t *e)
     1525{
     1526    ngx_http_variable_value_t  *val, *res;
     1527
     1528    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1529                   "http script gt");
     1530
     1531    e->sp--;
     1532    val = e->sp;
     1533    res = e->sp - 1;
     1534
     1535    e->ip += sizeof(uintptr_t);
     1536
     1537    if (val->len <= res->len
     1538        && ngx_strncmp(val->data, res->data, res->len) < 0)
     1539    {
     1540        *res = ngx_http_variable_true_value;
     1541        return;
     1542    }
     1543
     1544    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1545                   "http script gt: no");
     1546
     1547    *res = ngx_http_variable_null_value;
     1548}
     1549
     1550void
     1551ngx_http_script_ge_code(ngx_http_script_engine_t *e)
     1552{
     1553    ngx_http_variable_value_t  *val, *res;
     1554
     1555    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1556                   "http script ge");
     1557
     1558    e->sp--;
     1559    val = e->sp;
     1560    res = e->sp - 1;
     1561
     1562    e->ip += sizeof(uintptr_t);
     1563
     1564    if (val->len <= res->len
     1565        && ngx_strncmp(val->data, res->data, res->len) <= 0)
     1566    {
     1567        *res = ngx_http_variable_true_value;
     1568        return;
     1569    }
     1570
     1571    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
     1572                   "http script ge: no");
     1573
     1574    *res = ngx_http_variable_null_value;
     1575}
     1576
    14691577
    14701578void
    14711579ngx_http_script_file_code(ngx_http_script_engine_t *e)
  • src/http/ngx_http_script.h

    diff -r 18428f775b2c src/http/ngx_http_script.h
    a b  
    245245void ngx_http_script_if_code(ngx_http_script_engine_t *e);
    246246void ngx_http_script_equal_code(ngx_http_script_engine_t *e);
    247247void ngx_http_script_not_equal_code(ngx_http_script_engine_t *e);
     248void ngx_http_script_lt_code(ngx_http_script_engine_t *e);
     249void ngx_http_script_le_code(ngx_http_script_engine_t *e);
     250void ngx_http_script_gt_code(ngx_http_script_engine_t *e);
     251void ngx_http_script_ge_code(ngx_http_script_engine_t *e);
    248252void ngx_http_script_file_code(ngx_http_script_engine_t *e);
    249253void ngx_http_script_complex_value_code(ngx_http_script_engine_t *e);
    250254void ngx_http_script_value_code(ngx_http_script_engine_t *e);