2018-09-07 17:27:23 +08:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <tfe_http.h>
|
2018-09-12 15:29:35 +08:00
|
|
|
#include <tfe_plugin.h>
|
2018-09-07 17:27:23 +08:00
|
|
|
|
2018-09-12 15:29:35 +08:00
|
|
|
struct tfe_http_half * tfe_http_request_create(int major_version, int method, const char * uri, const char * host)
|
2018-09-07 17:27:23 +08:00
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 15:29:35 +08:00
|
|
|
struct tfe_http_half * tfe_http_response_create(int major_version, int resp_code)
|
2018-09-07 17:27:23 +08:00
|
|
|
{
|
2018-09-12 15:29:35 +08:00
|
|
|
return NULL;
|
2018-09-07 17:27:23 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
struct http_frame_session_ctx
|
2018-09-07 17:27:23 +08:00
|
|
|
{
|
2018-09-17 15:44:44 +08:00
|
|
|
struct http_frame_plugin_status * plugin_status;
|
|
|
|
|
unsigned int nr_plugin_status;
|
|
|
|
|
|
|
|
|
|
struct tfe_plugin * calling_plugin;
|
|
|
|
|
struct http_frame_plugin_status * calling_plugin_status;
|
2018-09-12 15:29:35 +08:00
|
|
|
};
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
struct http_frame_plugin_status * http_frame_current_plugin_status(struct http_frame_session_ctx * ht_frame)
|
|
|
|
|
{
|
|
|
|
|
return ht_frame->calling_plugin_status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct http_frame_session_ctx * http_frame_raise_session_begin(const struct tfe_stream * stream,
|
2018-09-12 15:29:35 +08:00
|
|
|
struct tfe_http_session * ht_session, unsigned int thread_id)
|
|
|
|
|
{
|
2018-09-17 15:44:44 +08:00
|
|
|
struct http_frame_session_ctx * ht_frame = ALLOC(struct http_frame_session_ctx, 1);
|
|
|
|
|
ht_frame->nr_plugin_status = tfe_plugin_total_counts();
|
|
|
|
|
ht_frame->plugin_status = ALLOC(struct http_frame_plugin_status, ht_frame->nr_plugin_status);
|
2018-09-12 15:29:35 +08:00
|
|
|
|
|
|
|
|
unsigned int __for_each_iterator = 0;
|
|
|
|
|
unsigned int __plugin_id = 0;
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
struct tfe_plugin * plugin_info_iter;
|
2018-09-12 15:29:35 +08:00
|
|
|
TFE_PLUGIN_FOREACH(plugin_info_iter, &__for_each_iterator)
|
|
|
|
|
{
|
|
|
|
|
if (plugin_info_iter->on_session_begin == NULL) continue;
|
2018-09-17 15:44:44 +08:00
|
|
|
|
|
|
|
|
/* Calling ctx, in callback can fetch by calling frame_plugin_status_get_XXX */
|
|
|
|
|
ht_frame->calling_plugin = plugin_info_iter;
|
|
|
|
|
ht_frame->calling_plugin_status = &ht_frame->plugin_status[__plugin_id];
|
|
|
|
|
|
|
|
|
|
/* Call session begin */
|
|
|
|
|
void ** calling_pme = &ht_frame->calling_plugin_status->pme;
|
|
|
|
|
plugin_info_iter->on_session_begin(stream, ht_session, thread_id, calling_pme);
|
2018-09-12 15:29:35 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
/* Clear calling ctx */
|
|
|
|
|
ht_frame->calling_plugin = NULL;
|
|
|
|
|
ht_frame->calling_plugin_status = NULL;
|
|
|
|
|
return ht_frame;
|
2018-09-12 15:29:35 +08:00
|
|
|
};
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
void http_frame_raise_session_end(struct http_frame_session_ctx * ht_frame, struct tfe_stream * stream,
|
2018-09-12 15:29:35 +08:00
|
|
|
struct tfe_http_session * ht_session, unsigned int thread_id)
|
|
|
|
|
{
|
|
|
|
|
unsigned int __for_each_iterator = 0;
|
|
|
|
|
unsigned int __plugin_id = 0;
|
|
|
|
|
struct tfe_plugin * plugin_info_iter;
|
|
|
|
|
|
|
|
|
|
TFE_PLUGIN_FOREACH(plugin_info_iter, &__for_each_iterator)
|
|
|
|
|
{
|
|
|
|
|
if (plugin_info_iter->on_session_end == NULL) continue;
|
2018-09-17 15:44:44 +08:00
|
|
|
|
|
|
|
|
/* Calling ctx, in callback can fetch by calling frame_plugin_status_get_XXX */
|
|
|
|
|
ht_frame->calling_plugin = plugin_info_iter;
|
|
|
|
|
ht_frame->calling_plugin_status = &ht_frame->plugin_status[__plugin_id];
|
|
|
|
|
|
|
|
|
|
/* Call session end */
|
|
|
|
|
void ** calling_pme = &ht_frame->calling_plugin_status->pme;
|
|
|
|
|
plugin_info_iter->on_session_end(stream, ht_session, thread_id, calling_pme);
|
2018-09-12 15:29:35 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
ht_frame->calling_plugin = NULL;
|
|
|
|
|
ht_frame->calling_plugin_status = NULL;
|
|
|
|
|
|
|
|
|
|
free(ht_frame->plugin_status);
|
|
|
|
|
free(ht_frame);
|
2018-09-07 17:27:23 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
void http_frame_raise_event(struct http_frame_session_ctx * ht_frame,
|
2018-09-12 15:29:35 +08:00
|
|
|
const struct tfe_stream * stream, struct tfe_http_session * ht_session, enum tfe_http_event event,
|
|
|
|
|
const unsigned char * data, size_t datalen, unsigned int thread_id)
|
2018-09-07 17:27:23 +08:00
|
|
|
{
|
2018-09-12 15:29:35 +08:00
|
|
|
unsigned int __for_each_iterator = 0;
|
|
|
|
|
unsigned int __plugin_id = 0;
|
|
|
|
|
|
|
|
|
|
struct tfe_plugin * plugin_info_iter;
|
|
|
|
|
TFE_PLUGIN_FOREACH(plugin_info_iter, &__for_each_iterator)
|
|
|
|
|
{
|
2018-09-17 15:44:44 +08:00
|
|
|
if (plugin_info_iter->on_session_data == NULL) continue;
|
2018-09-12 15:29:35 +08:00
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
/* Calling ctx, in callback can fetch by calling frame_plugin_status_get_XXX */
|
|
|
|
|
ht_frame->calling_plugin = plugin_info_iter;
|
|
|
|
|
ht_frame->calling_plugin_status = &ht_frame->plugin_status[__plugin_id];
|
|
|
|
|
|
|
|
|
|
void ** calling_pme = &ht_frame->calling_plugin_status->pme;
|
|
|
|
|
plugin_info_iter->on_session_data(stream, ht_session, event, data, datalen, thread_id, calling_pme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ht_frame->calling_plugin = NULL;
|
|
|
|
|
ht_frame->calling_plugin_status = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void http_frame_currect_plugin_detach(struct http_frame_session_ctx * ht_frame)
|
|
|
|
|
{
|
|
|
|
|
ht_frame->calling_plugin_status->detached = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int http_frame_currect_plugin_preempt(struct http_frame_session_ctx * ht_frame)
|
|
|
|
|
{
|
|
|
|
|
for(unsigned int i = 0; i < ht_frame->nr_plugin_status; i++)
|
|
|
|
|
{
|
|
|
|
|
struct http_frame_plugin_status * __plugin_status = &ht_frame->plugin_status[i];
|
|
|
|
|
if (__plugin_status->preempt) return -1;
|
2018-09-12 15:29:35 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
assert(ht_frame->calling_plugin_status != NULL);
|
|
|
|
|
ht_frame->calling_plugin_status->preempt = 1;
|
|
|
|
|
return 0;
|
2018-09-07 17:27:23 +08:00
|
|
|
}
|