Skip to content

Commit

Permalink
added uri parse function
Browse files Browse the repository at this point in the history
  • Loading branch information
yzprofile committed Nov 25, 2012
1 parent 62662b6 commit 2e45400
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 13 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ Context: `loc`

This directive set the interface location where you can update nginx config.Restfull interface to Themis.



## install: ##

./configure --add-module=/path/to/themis --add-module=/path/to/themis/modules/xxx_module
make
make install
13 changes: 8 additions & 5 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ THEMIS_CORE_DIR="$ngx_addon_dir/core"

CORE_INCS="$CORE_INCS $ngx_addon_dir $THEMIS_CORE_DIR"

NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$THEMIS_CORE_DIR/ngx_themis_log.h \
$THEMIS_CORE_DIR/ngx_themis.h \
$THEMIS_CORE_DIR/ngx_themis_channel.h"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$THEMIS_CORE_DIR/ngx_themis_log.h \
$THEMIS_CORE_DIR/ngx_themis.h \
$THEMIS_CORE_DIR/ngx_themis_channel.h \
$THEMIS_CORE_DIR/ngx_http_themis_interface.h"

NGX_ADDON_SRCS="$NGX_ADDON_SRCS $THEMIS_CORE_DIR/ngx_themis_channel.c"

HTTP_MODULES="$HTTP_MODULES ngx_http_themis_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $THEMIS_CORE_DIR/ngx_http_themis_module.c"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS
$THEMIS_CORE_DIR/ngx_http_themis_module.c \
$THEMIS_CORE_DIR/ngx_http_themis_interface.c"
63 changes: 63 additions & 0 deletions core/ngx_http_themis_interface.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <ngx_themis.h>


ngx_array_t *
ngx_http_themis_parse_uri(ngx_http_request_t *r)
{
u_char *p, *last, *end;
ngx_str_t *str;
ngx_array_t *array;

array = ngx_array_create(r->pool, 8, sizeof(ngx_str_t));
if (array == NULL) {
return NULL;
}

p = r->uri.data + 1;
last = r->uri.data + r->uri.len;

end = p;
while(p < last) {
end = ngx_strlchr(p, last, '/');
str = ngx_array_push(array);

if (str == NULL) {
return NULL;
}

if (end) {
str->data = p;
str->len = end - p;

} else {
str->data = p;
str->len = last - p;

}

p += str->len + 1;
}

return array;
}


ngx_int_t
ngx_http_themis_module_parse_cmd(ngx_http_request_t *r, ngx_array_t *parms)
{
ngx_str_t name, module, cmd, *value;

value = parms->elts;

name = value[0];
module = value[1];
cmd = value[2];

ngx_log_themis_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"name: %V, module: %V, cmoomad: %V",
&name, &module, &cmd);

/* TODO */

return NGX_OK;
}
26 changes: 26 additions & 0 deletions core/ngx_http_themis_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _NGX_THEMIS_INTERFACE_H_INCLUDE_
#define _NGX_THEMIS_INTERFACE_H_INCLUDE_


#include <ngx_config.h>
#include <ngx_core.h>


static ngx_inline ngx_int_t
ngx_http_themis_uri_reserved_word(ngx_str_t *str)
{
if (ngx_strncasecmp(str->data, (u_char *) "themis", str->len) == 0) {
return NGX_OK;
}

return NGX_DECLINED;
}


ngx_array_t *ngx_http_themis_parse_uri(ngx_http_request_t *r);
ngx_int_t ngx_http_themis_module_parse_cmd(ngx_http_request_t *r,
ngx_array_t *parms);



#endif
30 changes: 26 additions & 4 deletions core/ngx_http_themis_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ ngx_themis_conf_set_config(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_http_themis_main_conf_t *tmcf;

value = cf->args->elts;
if (ngx_strncasecmp(value[1].data, (u_char *) "themis", value[1].len)
== 0)
{
if (ngx_http_themis_uri_reserved_word(&value[1]) == NGX_OK) {
return "\"themis\" is not allowed be a parameter";
}

Expand Down Expand Up @@ -549,9 +547,33 @@ static ngx_int_t
ngx_http_themis_interface_handler(ngx_http_request_t *r)
{
/*
uri: app/module/command
uri: name/module/command
themis/...
*/

ngx_str_t *value;
ngx_array_t *parms;

parms = ngx_http_themis_parse_uri(r);
if (parms == NULL) {
goto failed;
}

value = parms->elts;
if (ngx_http_themis_uri_reserved_word(&value[0]) == NGX_OK) {
/* reserved */
goto failed;
}

if (parms->nelts < 3) {
goto failed;
}

if (ngx_http_themis_module_parse_cmd(r, parms) != NGX_OK) {
goto failed;
}

failed:

return NGX_DONE;
}
1 change: 1 addition & 0 deletions core/ngx_themis.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ngx_http.h>
#include <ngx_themis_log.h>
#include <ngx_themis_channel.h>
#include <ngx_http_themis_interface.h>


#define NGX_THEMIS_MODULE 0x53494d54 /* TMIS */
Expand Down
8 changes: 4 additions & 4 deletions modules/access_mate/ngx_themis_access_mate_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ ngx_themis_module_t ngx_themis_access_mate_ctx = {


static ngx_command_t ngx_themis_access_commands[] = {

{ ngx_string("add"),
NGX_THEMIS_CONF|NGX_CONF_TAKE2,
ngx_themis_access_add,
NGX_THEMIS_COMMAND,
0,
NGX_HTTP_POST,
NULL },

{ ngx_string("status"),
NGX_THEMIS_CONF|NGX_CONF_TAKE2,
NGX_THEMIS_CONF|NGX_CONF_NOARGS,
ngx_themis_access_status,
NGX_THEMIS_REQUEST,
0,
NGX_HTTP_GET,
NULL },

ngx_null_command
Expand Down Expand Up @@ -115,7 +116,6 @@ ngx_themis_access_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}



static ngx_int_t
ngx_themis_access_mate_update_config(ngx_cycle_t *cycle, void *config)
{
Expand Down

0 comments on commit 2e45400

Please sign in to comment.