예제 #1
0
파일: nyara.c 프로젝트: fsword/nyara
void Init_nyara() {
  u8_encoding = rb_utf8_encoding();
  set_fd_limit(20000);

  nyara = rb_define_module("Nyara");
# include "inc/version.inc"
  rb_const_set(nyara, rb_intern("VERSION"), rb_enc_str_new(NYARA_VERSION, strlen(NYARA_VERSION), u8_encoding));

  // utils: hashes
  Init_hashes(nyara);

  // utils: method map
  volatile VALUE method_map = rb_class_new_instance(0, NULL, nyara_param_hash_class);
  rb_const_set(nyara, rb_intern("HTTP_METHODS"), method_map);
  VALUE tmp_key = Qnil;
# define METHOD_STR2NUM(n, name, string) \
    tmp_key = rb_enc_str_new(#string, strlen(#string), u8_encoding);\
    OBJ_FREEZE(tmp_key);\
    rb_hash_aset(method_map, tmp_key, INT2FIX(n));
  HTTP_METHOD_MAP(METHOD_STR2NUM);
# undef METHOD_STR2NUM
  OBJ_FREEZE(method_map);

  // utils: status codes
  volatile VALUE status_map = rb_hash_new();
  rb_const_set(nyara, rb_intern("HTTP_STATUS_CODES"), status_map);
  VALUE tmp_value = Qnil;
# define STATUS_DESC(status, desc) \
    tmp_value = rb_enc_str_new(desc, strlen(desc), u8_encoding);\
    OBJ_FREEZE(tmp_value);\
    rb_hash_aset(status_map, INT2FIX(status), tmp_value);
  HTTP_STATUS_CODES(STATUS_DESC);
# undef STATUS_DESC
  OBJ_FREEZE(status_map);

  VALUE ext = rb_define_module_under(nyara, "Ext");
  rb_define_singleton_method(ext, "rdtsc_start", ext_rdtsc_start, 0);
  rb_define_singleton_method(ext, "rdtsc", ext_rdtsc, 0);

  Init_accept(ext);
  Init_mime(ext);
  Init_request(nyara, ext);
  Init_request_parse(nyara, ext);
  Init_test_response(nyara);
  Init_event(ext);
  Init_route(nyara, ext);
  Init_url_encoded(ext);
}
예제 #2
0
파일: http.c 프로젝트: netdava/tang
 */

#include "http.h"
#undef http_reply

#include <errno.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

static const char *METHOD_NAMES[] = {
#define XX(num, name, string) [num] = # string,
HTTP_METHOD_MAP(XX)
#undef XX
    NULL
};

static int
on_url(http_parser *parser, const char *at, size_t length)
{
    struct http_state *state = parser->data;

    if (state->req.status == 0) {
        if (strlen(state->req.path) + length >= sizeof(state->req.path))
            state->req.status = HTTP_STATUS_URI_TOO_LONG;
        else
            strncat(state->req.path, at, length);
    }