You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
6.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #define __USE_LARGEFILE64
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <stdio.h>
  5. #include "apr_hash.h"
  6. #include "apr_strings.h"
  7. #include "ap_config.h"
  8. #include "ap_provider.h"
  9. #include "httpd.h"
  10. #include "http_core.h"
  11. #include "http_config.h"
  12. #include "http_log.h"
  13. #include "http_protocol.h"
  14. #include "http_request.h"
  15. #include "../lib/components/base/basicSettingsProvider.h"
  16. #include "mod_h264_streaming.h"
  17. /*
  18. ==============================================================================
  19. Our configuration prototype and declaration:
  20. ==============================================================================
  21. */
  22. typedef struct {
  23. int enabled; /* Enable or disable our module */
  24. const char *path; /* Some path to...something */
  25. int typeOfAction; /* 1 means action A, 2 means action B and so on */
  26. } example_config;
  27. static example_config config;
  28. static config_setting_t * m_Settings;
  29. /*
  30. ==============================================================================
  31. Our directive handlers:
  32. ==============================================================================
  33. */
  34. /* Handler for the "exampleEnabled" directive */
  35. const char *example_set_enabled(cmd_parms *cmd, void *cfg, const char *arg)
  36. {
  37. if(!strcasecmp(arg, "on")) config.enabled = 1;
  38. else config.enabled = 0;
  39. return NULL;
  40. }
  41. /* Handler for the "examplePath" directive */
  42. const char *example_set_path(cmd_parms *cmd, void *cfg, const char *arg)
  43. {
  44. config.path = arg;
  45. return NULL;
  46. }
  47. /* Handler for the "exampleAction" directive */
  48. /* Let's pretend this one takes one argument (file or db), and a second (deny or allow), */
  49. /* and we store it in a bit-wise manner. */
  50. const char *example_set_action(cmd_parms *cmd, void *cfg, const char *arg1, const char *arg2)
  51. {
  52. if(!strcasecmp(arg1, "file")) config.typeOfAction = 0x01;
  53. else config.typeOfAction = 0x02;
  54. if(!strcasecmp(arg2, "deny")) config.typeOfAction += 0x10;
  55. else config.typeOfAction += 0x20;
  56. return NULL;
  57. }
  58. typedef struct {
  59. const char *key;
  60. const char *value;
  61. } keyValuePair;
  62. keyValuePair *readPost(request_rec *r) {
  63. apr_array_header_t *pairs = NULL;
  64. apr_off_t len;
  65. apr_size_t size;
  66. int res;
  67. int i = 0;
  68. char *buffer;
  69. keyValuePair *kvp;
  70. res = ap_parse_form_data(r, NULL, &pairs, -1, HUGE_STRING_LEN);
  71. if (res != OK || !pairs) return NULL; /* Return NULL if we failed or if there are is no POST data */
  72. kvp = apr_pcalloc(r->pool, sizeof(keyValuePair) * (pairs->nelts + 1));
  73. while (pairs && !apr_is_empty_array(pairs)) {
  74. ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
  75. apr_brigade_length(pair->value, 1, &len);
  76. size = (apr_size_t) len;
  77. buffer = apr_palloc(r->pool, size + 1);
  78. apr_brigade_flatten(pair->value, buffer, &size);
  79. buffer[len] = 0;
  80. kvp[i].key = apr_pstrdup(r->pool, pair->name);
  81. kvp[i].value = buffer;
  82. i++;
  83. }
  84. return kvp;
  85. }
  86. /*
  87. ==============================================================================
  88. The directive structure for our name tag:
  89. ==============================================================================
  90. */
  91. static const command_rec example_directives[] =
  92. {
  93. AP_INIT_TAKE1("exampleEnabled", example_set_enabled, NULL, RSRC_CONF, "Enable or disable mod_example"),
  94. AP_INIT_TAKE1("examplePath", example_set_path, NULL, RSRC_CONF, "The path to whatever"),
  95. AP_INIT_TAKE2("exampleAction", example_set_action, NULL, RSRC_CONF, "Special action value!"),
  96. { NULL }
  97. };
  98. /*
  99. ==============================================================================
  100. Our module handler:
  101. ==============================================================================
  102. */
  103. static int example_handler(request_rec *r)
  104. {
  105. if(!r->handler || strcmp(r->handler, "example-handler")) return(DECLINED);
  106. /*ap_set_content_type(r, "text/plain");
  107. ap_rprintf(r, "Enabled: %u\n", config.enabled);
  108. ap_rprintf(r, "Path: %s\n", config.path);
  109. ap_rprintf(r, "TypeOfAction: %x\n", config.typeOfAction);
  110. keyValuePair *formData;
  111. formData = readPost(r);
  112. if (formData) {
  113. int i;
  114. for (i = 0; &formData[i]; i++) {
  115. if (formData[i].key && formData[i].value) {
  116. ap_rprintf(r, "%s = %s\n", formData[i].key, formData[i].value);
  117. } else if (formData[i].key) {
  118. ap_rprintf(r, "%s\n", formData[i].key);
  119. } else if (formData[i].value) {
  120. ap_rprintf(r, "= %s\n", formData[i].value);
  121. } else {
  122. break;
  123. };
  124. };
  125. } else {
  126. ap_rprintf(r, "No Post Data!\n");
  127. };
  128. const apr_array_header_t *fields;
  129. int i;
  130. apr_table_entry_t *e = 0;
  131. fields = apr_table_elts(r->headers_in);
  132. e = (apr_table_entry_t *) fields->elts;
  133. for(i = 0; i < fields->nelts; i++) {
  134. ap_rprintf(r, "%s: %s\n", e[i].key, e[i].val);
  135. };
  136. return OK;
  137. */
  138. //r->allowed |= (AP_METHOD_BIT << M_GET);
  139. //if (r->method_number != M_GET)
  140. //{
  141. // return HTTP_METHOD_NOT_ALLOWED;
  142. //}
  143. return drive_h264_streaming(r);
  144. }
  145. /*
  146. ==============================================================================
  147. The hook registration function (also initializes the default config values):
  148. ==============================================================================
  149. */
  150. static void register_hooks(apr_pool_t *pool)
  151. {
  152. config.enabled = 1;
  153. config.path = "/foo/bar";
  154. config.typeOfAction = 3;
  155. m_Settings = basicSettingsProvider::getInstance()->getSubNode(NULL, "APACHE_MOD" );
  156. basicSettingsProvider::getInstance()->validate();
  157. ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_LAST);
  158. }
  159. /*
  160. ==============================================================================
  161. Our module name tag:
  162. ==============================================================================
  163. */
  164. #ifdef __cplusplus
  165. extern "C" {
  166. #endif
  167. module AP_MODULE_DECLARE_DATA example_module =
  168. {
  169. STANDARD20_MODULE_STUFF,
  170. NULL, /* Per-directory configuration handler */
  171. NULL, /* Merge handler for per-directory configurations */
  172. NULL, /* Per-server configuration handler */
  173. NULL, /* Merge handler for per-server configurations */
  174. example_directives, /* Any directives we may have for httpd */
  175. register_hooks /* Our hook registering function */
  176. };
  177. #ifdef __cplusplus
  178. } /* extern C definitions */
  179. #endif
  180. /*
  181. int main(){
  182. printf("KOKO\n\n");
  183. register_hooks( NULL );
  184. return 0;
  185. }
  186. //*/