#define __USE_LARGEFILE64 #include #include #include #include "apr_hash.h" #include "apr_strings.h" #include "ap_config.h" #include "ap_provider.h" #include "httpd.h" #include "http_core.h" #include "http_config.h" #include "http_log.h" #include "http_protocol.h" #include "http_request.h" #include "../lib/components/base/basicSettingsProvider.h" #include "mod_h264_streaming.h" /* ============================================================================== Our configuration prototype and declaration: ============================================================================== */ typedef struct { int enabled; /* Enable or disable our module */ const char *path; /* Some path to...something */ int typeOfAction; /* 1 means action A, 2 means action B and so on */ } example_config; static example_config config; static config_setting_t * m_Settings; /* ============================================================================== Our directive handlers: ============================================================================== */ /* Handler for the "exampleEnabled" directive */ const char *example_set_enabled(cmd_parms *cmd, void *cfg, const char *arg) { if(!strcasecmp(arg, "on")) config.enabled = 1; else config.enabled = 0; return NULL; } /* Handler for the "examplePath" directive */ const char *example_set_path(cmd_parms *cmd, void *cfg, const char *arg) { config.path = arg; return NULL; } /* Handler for the "exampleAction" directive */ /* Let's pretend this one takes one argument (file or db), and a second (deny or allow), */ /* and we store it in a bit-wise manner. */ const char *example_set_action(cmd_parms *cmd, void *cfg, const char *arg1, const char *arg2) { if(!strcasecmp(arg1, "file")) config.typeOfAction = 0x01; else config.typeOfAction = 0x02; if(!strcasecmp(arg2, "deny")) config.typeOfAction += 0x10; else config.typeOfAction += 0x20; return NULL; } typedef struct { const char *key; const char *value; } keyValuePair; keyValuePair *readPost(request_rec *r) { apr_array_header_t *pairs = NULL; apr_off_t len; apr_size_t size; int res; int i = 0; char *buffer; keyValuePair *kvp; res = ap_parse_form_data(r, NULL, &pairs, -1, HUGE_STRING_LEN); if (res != OK || !pairs) return NULL; /* Return NULL if we failed or if there are is no POST data */ kvp = apr_pcalloc(r->pool, sizeof(keyValuePair) * (pairs->nelts + 1)); while (pairs && !apr_is_empty_array(pairs)) { ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs); apr_brigade_length(pair->value, 1, &len); size = (apr_size_t) len; buffer = apr_palloc(r->pool, size + 1); apr_brigade_flatten(pair->value, buffer, &size); buffer[len] = 0; kvp[i].key = apr_pstrdup(r->pool, pair->name); kvp[i].value = buffer; i++; } return kvp; } /* ============================================================================== The directive structure for our name tag: ============================================================================== */ static const command_rec example_directives[] = { AP_INIT_TAKE1("exampleEnabled", example_set_enabled, NULL, RSRC_CONF, "Enable or disable mod_example"), AP_INIT_TAKE1("examplePath", example_set_path, NULL, RSRC_CONF, "The path to whatever"), AP_INIT_TAKE2("exampleAction", example_set_action, NULL, RSRC_CONF, "Special action value!"), { NULL } }; /* ============================================================================== Our module handler: ============================================================================== */ static int example_handler(request_rec *r) { if(!r->handler || strcmp(r->handler, "example-handler")) return(DECLINED); /*ap_set_content_type(r, "text/plain"); ap_rprintf(r, "Enabled: %u\n", config.enabled); ap_rprintf(r, "Path: %s\n", config.path); ap_rprintf(r, "TypeOfAction: %x\n", config.typeOfAction); keyValuePair *formData; formData = readPost(r); if (formData) { int i; for (i = 0; &formData[i]; i++) { if (formData[i].key && formData[i].value) { ap_rprintf(r, "%s = %s\n", formData[i].key, formData[i].value); } else if (formData[i].key) { ap_rprintf(r, "%s\n", formData[i].key); } else if (formData[i].value) { ap_rprintf(r, "= %s\n", formData[i].value); } else { break; }; }; } else { ap_rprintf(r, "No Post Data!\n"); }; const apr_array_header_t *fields; int i; apr_table_entry_t *e = 0; fields = apr_table_elts(r->headers_in); e = (apr_table_entry_t *) fields->elts; for(i = 0; i < fields->nelts; i++) { ap_rprintf(r, "%s: %s\n", e[i].key, e[i].val); }; return OK; */ //r->allowed |= (AP_METHOD_BIT << M_GET); //if (r->method_number != M_GET) //{ // return HTTP_METHOD_NOT_ALLOWED; //} return drive_h264_streaming(r); } /* ============================================================================== The hook registration function (also initializes the default config values): ============================================================================== */ static void register_hooks(apr_pool_t *pool) { config.enabled = 1; config.path = "/foo/bar"; config.typeOfAction = 3; m_Settings = basicSettingsProvider::getInstance()->getSubNode(NULL, "APACHE_MOD" ); basicSettingsProvider::getInstance()->validate(); ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST); } /* ============================================================================== Our module name tag: ============================================================================== */ #ifdef __cplusplus extern "C" { #endif module AP_MODULE_DECLARE_DATA example_module = { STANDARD20_MODULE_STUFF, NULL, /* Per-directory configuration handler */ NULL, /* Merge handler for per-directory configurations */ NULL, /* Per-server configuration handler */ NULL, /* Merge handler for per-server configurations */ example_directives, /* Any directives we may have for httpd */ register_hooks /* Our hook registering function */ }; #ifdef __cplusplus } /* extern C definitions */ #endif /* int main(){ printf("KOKO\n\n"); register_hooks( NULL ); return 0; } //*/