Last active
July 10, 2016 23:15
-
-
Save rdeioris/d1ba5b143ce54a0d58233d835fe24653 to your computer and use it in GitHub Desktop.
uwsgi router_mkdir.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <uwsgi.h> | |
static int router_mkdir_func(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) { | |
char **subject = (char **) (((char *)(wsgi_req))+ur->subject); | |
uint16_t *subject_len = (uint16_t *) (((char *)(wsgi_req))+ur->subject_len); | |
struct uwsgi_buffer *ub = uwsgi_routing_translate(wsgi_req, ur, *subject, *subject_len, ur->data, ur->data_len); | |
if (!ub) return UWSGI_ROUTE_BREAK; | |
// note ub->buf is \0 terminated, so it is safe for mkdir() | |
// NOTE/TODO do what you want/need on error | |
mkdir(ub->buf, 0777); | |
uwsgi_buffer_destroy(ub); | |
return UWSGI_ROUTE_NEXT; | |
} | |
static int router_mkdir(struct uwsgi_route *ur, char *args) { | |
ur->func = router_mkdir_func; | |
ur->data = args; | |
ur->data_len = strlen(args); | |
return 0; | |
} | |
static void register_router_mkdir(void) { | |
uwsgi_register_router("mkdir", router_mkdir); | |
} | |
struct uwsgi_plugin router_mkdir_plugin = { | |
.name = "router_mkdir", | |
.on_load = register_router_mkdir, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment