├── .gitignore ├── Makefile ├── README.md ├── csas.c ├── csas.h ├── example-engine.c ├── example-engine.h ├── include └── evhtp │ ├── evhtp.h │ ├── evthr.h │ ├── htparse.h │ ├── oniggnu.h │ ├── onigposix.h │ └── oniguruma.h ├── inmemory-engine.c ├── inmemory-engine.h ├── leveldb-engine.c ├── leveldb-engine.h ├── lib └── placeholder ├── libevhtp ├── .gitignore ├── CMakeLists.txt ├── CMakeModules │ ├── BaseConfig.cmake │ └── FindLibEvent.cmake ├── ChangeLog ├── Doxyfile ├── LICENSE ├── README.markdown ├── build │ └── placeholder ├── compat │ └── sys │ │ ├── queue.h.in │ │ └── tree.h.in ├── contrib │ ├── ab_wsesscache.README │ ├── ab_wsesscache.diff │ ├── git_changelog.py │ ├── make_release.sh │ ├── perftest.sh │ └── release_prep.sh ├── evhtp.c ├── evhtp.h ├── evthr │ ├── Makefile │ ├── README │ ├── evthr.c │ ├── evthr.h │ └── test.c ├── examples │ └── thread_design.c ├── htparse │ ├── Makefile │ ├── htparse.c │ ├── htparse.h │ └── test.c ├── oniguruma │ ├── AUTHORS │ ├── CMakeLists.txt │ ├── COPYING │ ├── HISTORY │ ├── INSTALL │ ├── Makefile.am │ ├── Makefile.in │ ├── README │ ├── README.ja │ ├── config.h.in │ ├── enc │ │ ├── ascii.c │ │ ├── big5.c │ │ ├── cp1251.c │ │ ├── euc_jp.c │ │ ├── euc_kr.c │ │ ├── euc_tw.c │ │ ├── gb18030.c │ │ ├── iso8859_1.c │ │ ├── iso8859_10.c │ │ ├── iso8859_11.c │ │ ├── iso8859_13.c │ │ ├── iso8859_14.c │ │ ├── iso8859_15.c │ │ ├── iso8859_16.c │ │ ├── iso8859_2.c │ │ ├── iso8859_3.c │ │ ├── iso8859_4.c │ │ ├── iso8859_5.c │ │ ├── iso8859_6.c │ │ ├── iso8859_7.c │ │ ├── iso8859_8.c │ │ ├── iso8859_9.c │ │ ├── koi8.c │ │ ├── koi8_r.c │ │ ├── mktable.c │ │ ├── sjis.c │ │ ├── unicode.c │ │ ├── utf16_be.c │ │ ├── utf16_le.c │ │ ├── utf32_be.c │ │ ├── utf32_le.c │ │ └── utf8.c │ ├── onig-config.in │ ├── oniggnu.h │ ├── onigposix.h │ ├── oniguruma.h │ ├── regcomp.c │ ├── regenc.c │ ├── regenc.h │ ├── regerror.c │ ├── regexec.c │ ├── regext.c │ ├── reggnu.c │ ├── regint.h │ ├── regparse.c │ ├── regparse.h │ ├── regposerr.c │ ├── regposix.c │ ├── regsyntax.c │ ├── regtrav.c │ ├── regversion.c │ ├── sample │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── crnl.c │ │ ├── encode.c │ │ ├── listcap.c │ │ ├── names.c │ │ ├── posix.c │ │ ├── simple.c │ │ ├── sql.c │ │ └── syntax.c │ ├── st.c │ ├── st.h │ ├── testc.c │ ├── testu.c │ └── win32 │ │ ├── Makefile │ │ ├── config.h │ │ └── testc.c ├── test.c ├── test_basic.c └── test_vhost.c ├── server.c ├── sqlite-engine.c ├── sqlite-engine.h ├── t.c └── uthash.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all:server t 2 | 3 | CC=gcc 4 | CFLAGS=-g -std=c99 -Wall -Wno-unused -I/usr/local/include/leveldb/ -I./include/ 5 | LDFALGS=-lpthread\ 6 | -L/usr/local/lib/ -lleveldb -levent\ 7 | -L./lib/ -levhtp 8 | 9 | server:server.o csas.o\ 10 | inmemory-engine.o\ 11 | leveldb-engine.o\ 12 | sqlite-engine.o\ 13 | example-engine.o 14 | $(CC) -o $@ $^ $(LDFALGS) 15 | 16 | t:t.o csas.o\ 17 | inmemory-engine.o\ 18 | leveldb-engine.o\ 19 | sqlite-engine.o\ 20 | example-engine.o 21 | $(CC) -o $@ $^ $(LDFALGS) 22 | 23 | server.o:server.c 24 | $(CC) -o $@ -c $^ $(CFLAGS) 25 | 26 | t.o:t.c 27 | $(CC) -o $@ -c $^ $(CFLAGS) 28 | 29 | csas.o:csas.c 30 | $(CC) -o $@ -c $^ $(CFLAGS) 31 | 32 | inmemory-engine.o:inmemory-engine.c 33 | $(CC) $(CFLAGS) -o $@ -c $^ 34 | 35 | leveldb-engine.o:leveldb-engine.c 36 | $(CC) $(CFLAGS) -o $@ -c $^ 37 | 38 | sqlite-engine.o:sqlite-engine.c 39 | $(CC) $(CFLAGS) -o $@ -c $^ 40 | 41 | example-engine.o:example-engine.c 42 | $(CC) -o $@ -c $^ 43 | 44 | 45 | .PHONY:clean 46 | 47 | clean: 48 | rm server t server.o t.o csas.o\ 49 | inmemory-engine.o\ 50 | leveldb-engine.o\ 51 | sqlite-engine.o\ 52 | example-engine.o 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | tinydb 2 | ====== 3 | 4 | Tinydb is a tiny nosql database supporting pluggable storage engine. It aims to provide a simple but workable nosql database server, 5 | Tinydb's core implemention (Common Storage Abstract Service: csas.h and csas.c) only cost about 200 sloc, it now have a RESTful server 6 | based on libevent2, a persistent storage engine based on google's leveldb and a in-memory storage engine based on uthash(http://uthash.sourceforge.net/). 7 | If you want to take a deep look at its implemention detail, here is the URL(in Chinese)(http://www.cnblogs.com/haippy/archive/2012/11/24/2786404.html) 8 | 9 | install 10 | ======= 11 | First of all you have to install libevent2 and leveldb ,then compile libevhtp: 12 | 13 | > $:cd libevhtp/build 14 | 15 | > $:cmake ../. 16 | 17 | > $:make 18 | 19 | if libevhtp successfull compiled, you will get a static library in libevhtp/build name "libevhtp.a", move it to tinydb/lib/. 20 | 21 | Next all you have to do is comiple tinydb, this is easy and you only need to "make" in the directory, since tinydb supports pluggable storage engine, 22 | if you want to implement your storage engine, you will need to fill three function in your engine: put, get, delete, the example engine shows you how 23 | to do this job.But you may have to take a look at engine-leveldb.h/engine-leveldb.c if you want to make you engine a little more flexible. 24 | 25 | storage engine 26 | ============== 27 | tinydb supports two simple storage engine: leveldb-based persistent storage engine and uthash(http://uthash.sourceforge.net/) based in-memory 28 | engine, sqlite based engine will be implemented very soon, and what's more you have the chance to implement your own storage engine, 29 | it's awsome right?, just to keep it simple and beautiful. 30 | 31 | How to make it run ? 32 | ==================== 33 | After you compiled tinydb there is an executable file named "server", just run it in command line with no arguments: 34 | > $: ./server 35 | 36 | Open your browser and type something in the URL box, magic will happen here. 37 | 38 | Commands 39 | ======== 40 | Tinydb supports only 3 commands: set, get, delete, to keep its simplicity. 41 | 42 | SET 43 | > http:127.0.0.1:8088/set?key=hello&value=world 44 | 45 | > {"err": "OK","msg":"Set key successfully."} 46 | 47 | GET 48 | > http:127.0.0.1:8088/get?key=hello 49 | 50 | > {"key": "hello","val":"world"} 51 | 52 | DELETE 53 | > http:127.0.0.1:8088/delete?key=hello 54 | 55 | > {"err": "OK","msg":"Delete key successfully."} 56 | 57 | Bugs 58 | ===== 59 | Tinydb is tiny project worked in my free time but bugs are inevitable, if you have found some bugs please contact haipingf AT gmail DOT com. 60 | I'm happy to hear your voice. :-) 61 | -------------------------------------------------------------------------------- /csas.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: csas.c 5 | * 6 | * Description: common storage abstract service. 7 | * 8 | * Created: 11/24/2012 03:16:38 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | #include 16 | #include 17 | #include "csas.h" 18 | 19 | csas_context_t * csas_init(engine_base_t *engine) 20 | { 21 | csas_context_t *context = 22 | (csas_context_t *)malloc(sizeof(csas_context_t)); 23 | 24 | context->engine = engine; 25 | context->next = NULL; 26 | return context; 27 | } 28 | 29 | void csas_destory(csas_context_t *context) 30 | { 31 | assert(context != NULL); 32 | 33 | if (context->engine != NULL) { 34 | free(context->engine); 35 | } 36 | free(context); 37 | 38 | } 39 | 40 | int csas_put(csas_context_t *context, 41 | const char *key, unsigned int key_len, 42 | const char *value, unsigned int value_len) 43 | { 44 | int ret = -1; 45 | ret = context->engine->engine_ops->put(context->engine, 46 | key, key_len, value, value_len); 47 | return ret; 48 | } 49 | 50 | char * csas_get(csas_context_t *context, 51 | const char *key, unsigned int key_len, 52 | unsigned int *value_len) 53 | { 54 | char *retstr = NULL; 55 | retstr = context->engine->engine_ops->get(context->engine, 56 | key, key_len, value_len); 57 | return retstr; 58 | } 59 | 60 | int csas_delete(csas_context_t *context, 61 | const char *key, unsigned int key_len) 62 | { 63 | int ret = -1; 64 | ret = context->engine->engine_ops->delete(context->engine, 65 | key, key_len); 66 | return ret; 67 | } 68 | -------------------------------------------------------------------------------- /csas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: csas.h 5 | * 6 | * Description: common storage abstract service. 7 | * 8 | * Created: 11/24/2012 03:16:19 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | #ifndef CSAS_H 16 | #define CSAS_H 17 | 18 | typedef struct engine_base_s_ engine_base_t; 19 | typedef struct engine_operation_s_ engine_operation_t; 20 | typedef struct csas_context_s_ csas_context_t; 21 | 22 | struct csas_context_s_ { 23 | csas_context_t *next; 24 | engine_base_t *engine; 25 | /* other stuff here... */ 26 | }; 27 | 28 | struct engine_base_s_ { 29 | char *name; 30 | unsigned int version; 31 | engine_operation_t *engine_ops; 32 | /* more stuff about storage engine base here... */ 33 | }; 34 | 35 | struct engine_operation_s_ { 36 | int (*put)(engine_base_t *engine, 37 | const char *key, unsigned int key_len, 38 | const char *value, unsigned int value_len); 39 | 40 | char * (*get)(engine_base_t *engine, 41 | const char *key, unsigned int key_len, 42 | unsigned int *value_len); 43 | 44 | int (*delete)(engine_base_t *engine, 45 | const char *key, unsigned int key_len); 46 | 47 | int (*unsupported_operation)(engine_base_t *engine); 48 | }; 49 | 50 | csas_context_t * csas_init(engine_base_t *engine); 51 | 52 | void csas_destory(csas_context_t *context); 53 | 54 | int csas_put(csas_context_t *context, 55 | const char *key, unsigned int key_len, 56 | const char *value, unsigned int value_len); 57 | 58 | char * csas_get(csas_context_t *context, 59 | const char *key, unsigned int key_len, 60 | unsigned int *value_len); 61 | 62 | int csas_delete(csas_context_t *context, 63 | const char *key, unsigned int key_len); 64 | 65 | #endif /* CSAS_H */ 66 | -------------------------------------------------------------------------------- /example-engine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: example-engine.c 5 | * 6 | * Description: example storage engine. 7 | * 8 | * Created: 11/24/2012 03:49:34 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "example-engine.h" 21 | 22 | static int put(engine_base_t *engine, 23 | const char *key, unsigned int key_len, 24 | const char *value, unsigned int value_len) 25 | { 26 | printf("hook call to example put.\n"); 27 | return 0; 28 | } 29 | 30 | static char * get(engine_base_t *engine, 31 | const char *key, unsigned int key_len, 32 | unsigned int *value_len) 33 | { 34 | printf("hook call to example engine get.\n"); 35 | return NULL; 36 | } 37 | 38 | static int delete(engine_base_t *engine, 39 | const char *key, unsigned int key_len) 40 | { 41 | printf("hook call to example engine delete.\n"); 42 | return 0; 43 | } 44 | 45 | engine_base_t * engine_example_init(void) 46 | { 47 | engine_base_t *engine = (engine_base_t *) malloc(sizeof(engine_base_t)); 48 | engine_operation_t *engine_ops = (engine_operation_t *) 49 | malloc(sizeof(engine_operation_t)); 50 | 51 | const char *engine_name = "example engine v0.1"; 52 | unsigned int engine_name_len = strlen(engine_name); 53 | unsigned int version = 0x1; 54 | 55 | engine->name = malloc(sizeof(char) * (engine_name_len + 1)); 56 | memset(engine->name, 0, (engine_name_len + 1)); 57 | strncpy(engine->name, engine_name, engine_name_len); 58 | engine->version = version; 59 | 60 | engine_ops->put = put; 61 | engine_ops->get = get; 62 | engine_ops->delete = delete; 63 | 64 | engine->engine_ops = engine_ops; 65 | } 66 | -------------------------------------------------------------------------------- /example-engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: example-engine.h 5 | * 6 | * Description: example storage engine 7 | * 8 | * Created: 11/24/2012 03:49:23 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #ifndef EXAMPLE_ENGINE_H 17 | #define EXAMPLE_ENGINE_H 18 | #include "csas.h" 19 | 20 | extern engine_base_t * engine_example_init(); 21 | 22 | #endif /* EXAMPLE_ENGINE_H */ 23 | -------------------------------------------------------------------------------- /include/evhtp/evthr.h: -------------------------------------------------------------------------------- 1 | #ifndef _GNU_SOURCE 2 | #define _GNU_SOURCE 1 3 | #endif 4 | #ifndef __EVTHR_H__ 5 | #define __EVTHR_H__ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | enum evthr_res { 18 | EVTHR_RES_OK = 0, 19 | EVTHR_RES_BACKLOG, 20 | EVTHR_RES_RETRY, 21 | EVTHR_RES_NOCB, 22 | EVTHR_RES_FATAL 23 | }; 24 | 25 | struct evthr_pool; 26 | struct evthr; 27 | 28 | typedef struct event_base evbase_t; 29 | typedef struct event ev_t; 30 | 31 | typedef struct evthr_pool evthr_pool_t; 32 | typedef struct evthr evthr_t; 33 | typedef enum evthr_res evthr_res; 34 | 35 | typedef void (*evthr_cb)(evthr_t * thr, void * cmd_arg, void * shared); 36 | typedef void (*evthr_init_cb)(evthr_t * thr, void * shared); 37 | 38 | evthr_t * evthr_new(evthr_init_cb init_cb, void * arg); 39 | evbase_t * evthr_get_base(evthr_t * thr); 40 | void evthr_set_aux(evthr_t * thr, void * aux); 41 | void * evthr_get_aux(evthr_t * thr); 42 | int evthr_start(evthr_t * evthr); 43 | evthr_res evthr_stop(evthr_t * evthr); 44 | evthr_res evthr_defer(evthr_t * evthr, evthr_cb cb, void * arg); 45 | void evthr_free(evthr_t * evthr); 46 | void evthr_inc_backlog(evthr_t * evthr); 47 | void evthr_dec_backlog(evthr_t * evthr); 48 | int evthr_get_backlog(evthr_t * evthr); 49 | void evthr_set_max_backlog(evthr_t * evthr, int max); 50 | 51 | evthr_pool_t * evthr_pool_new(int nthreads, evthr_init_cb init_cb, void * shared); 52 | int evthr_pool_start(evthr_pool_t * pool); 53 | evthr_res evthr_pool_stop(evthr_pool_t * pool); 54 | evthr_res evthr_pool_defer(evthr_pool_t * pool, evthr_cb cb, void * arg); 55 | void evthr_pool_free(evthr_pool_t * pool); 56 | void evthr_pool_set_max_backlog(evthr_pool_t * evthr, int max); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __EVTHR_H__ */ 63 | 64 | -------------------------------------------------------------------------------- /include/evhtp/htparse.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTPARSE_H__ 2 | #define __HTPARSE_H__ 3 | 4 | struct htparser; 5 | 6 | enum htp_type { 7 | htp_type_request = 0, 8 | htp_type_response 9 | }; 10 | 11 | enum htp_scheme { 12 | htp_scheme_none = 0, 13 | htp_scheme_ftp, 14 | htp_scheme_http, 15 | htp_scheme_https, 16 | htp_scheme_nfs, 17 | htp_scheme_unknown 18 | }; 19 | 20 | enum htp_method { 21 | htp_method_GET = 0, 22 | htp_method_HEAD, 23 | htp_method_POST, 24 | htp_method_PUT, 25 | htp_method_DELETE, 26 | htp_method_MKCOL, 27 | htp_method_COPY, 28 | htp_method_MOVE, 29 | htp_method_OPTIONS, 30 | htp_method_PROPFIND, 31 | htp_method_PROPPATCH, 32 | htp_method_LOCK, 33 | htp_method_UNLOCK, 34 | htp_method_TRACE, 35 | htp_method_UNKNOWN 36 | }; 37 | 38 | enum htpparse_error { 39 | htparse_error_none = 0, 40 | htparse_error_too_big, 41 | htparse_error_inval_method, 42 | htparse_error_inval_reqline, 43 | htparse_error_inval_schema, 44 | htparse_error_inval_proto, 45 | htparse_error_inval_ver, 46 | htparse_error_inval_hdr, 47 | htparse_error_inval_chunk_sz, 48 | htparse_error_inval_chunk, 49 | htparse_error_inval_state, 50 | htparse_error_user, 51 | htparse_error_status, 52 | htparse_error_generic 53 | }; 54 | 55 | typedef struct htparser htparser; 56 | typedef struct htparse_hooks htparse_hooks; 57 | 58 | typedef enum htp_scheme htp_scheme; 59 | typedef enum htp_method htp_method; 60 | typedef enum htp_type htp_type; 61 | typedef enum htpparse_error htpparse_error; 62 | 63 | typedef int (*htparse_hook)(htparser *); 64 | typedef int (*htparse_data_hook)(htparser *, const char *, size_t); 65 | 66 | 67 | struct htparse_hooks { 68 | htparse_hook on_msg_begin; 69 | htparse_data_hook method; 70 | htparse_data_hook scheme; /* called if scheme is found */ 71 | htparse_data_hook host; /* called if a host was in the request scheme */ 72 | htparse_data_hook port; /* called if a port was in the request scheme */ 73 | htparse_data_hook path; /* only the path of the uri */ 74 | htparse_data_hook args; /* only the arguments of the uri */ 75 | htparse_data_hook uri; /* the entire uri including path/args */ 76 | htparse_hook on_hdrs_begin; 77 | htparse_data_hook hdr_key; 78 | htparse_data_hook hdr_val; 79 | htparse_data_hook hostname; 80 | htparse_hook on_hdrs_complete; 81 | htparse_hook on_new_chunk; /* called after parsed chunk octet */ 82 | htparse_hook on_chunk_complete; /* called after single parsed chunk */ 83 | htparse_hook on_chunks_complete; /* called after all parsed chunks processed */ 84 | htparse_data_hook body; 85 | htparse_hook on_msg_complete; 86 | }; 87 | 88 | 89 | size_t htparser_run(htparser *, htparse_hooks *, const char *, size_t); 90 | int htparser_should_keep_alive(htparser * p); 91 | htp_scheme htparser_get_scheme(htparser *); 92 | htp_method htparser_get_method(htparser *); 93 | const char * htparser_get_methodstr(htparser *); 94 | void htparser_set_major(htparser *, unsigned char); 95 | void htparser_set_minor(htparser *, unsigned char); 96 | unsigned char htparser_get_major(htparser *); 97 | unsigned char htparser_get_minor(htparser *); 98 | unsigned char htparser_get_multipart(htparser *); 99 | unsigned int htparser_get_status(htparser *); 100 | uint64_t htparser_get_content_length(htparser *); 101 | uint64_t htparser_get_total_bytes_read(htparser *); 102 | htpparse_error htparser_get_error(htparser *); 103 | const char * htparser_get_strerror(htparser *); 104 | void * htparser_get_userdata(htparser *); 105 | void htparser_set_userdata(htparser *, void *); 106 | void htparser_init(htparser *, htp_type); 107 | htparser * htparser_new(void); 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /include/evhtp/oniggnu.h: -------------------------------------------------------------------------------- 1 | #ifndef ONIGGNU_H 2 | #define ONIGGNU_H 3 | /********************************************************************** 4 | oniggnu.h - Oniguruma (regular expression library) 5 | **********************************************************************/ 6 | /*- 7 | * Copyright (c) 2002-2005 K.Kosako 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include "oniguruma.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #define RE_MBCTYPE_ASCII 0 39 | #define RE_MBCTYPE_EUC 1 40 | #define RE_MBCTYPE_SJIS 2 41 | #define RE_MBCTYPE_UTF8 3 42 | 43 | /* GNU regex options */ 44 | #ifndef RE_NREGS 45 | #define RE_NREGS ONIG_NREGION 46 | #endif 47 | 48 | #define RE_OPTION_IGNORECASE ONIG_OPTION_IGNORECASE 49 | #define RE_OPTION_EXTENDED ONIG_OPTION_EXTEND 50 | #define RE_OPTION_MULTILINE ONIG_OPTION_MULTILINE 51 | #define RE_OPTION_SINGLELINE ONIG_OPTION_SINGLELINE 52 | #define RE_OPTION_LONGEST ONIG_OPTION_FIND_LONGEST 53 | #define RE_OPTION_POSIXLINE (RE_OPTION_MULTILINE|RE_OPTION_SINGLELINE) 54 | #define RE_OPTION_FIND_NOT_EMPTY ONIG_OPTION_FIND_NOT_EMPTY 55 | #define RE_OPTION_NEGATE_SINGLELINE ONIG_OPTION_NEGATE_SINGLELINE 56 | #define RE_OPTION_DONT_CAPTURE_GROUP ONIG_OPTION_DONT_CAPTURE_GROUP 57 | #define RE_OPTION_CAPTURE_GROUP ONIG_OPTION_CAPTURE_GROUP 58 | 59 | 60 | ONIG_EXTERN 61 | void re_mbcinit P_((int)); 62 | ONIG_EXTERN 63 | int re_compile_pattern P_((const char*, int, struct re_pattern_buffer*, char* err_buf)); 64 | ONIG_EXTERN 65 | int re_recompile_pattern P_((const char*, int, struct re_pattern_buffer*, char* err_buf)); 66 | ONIG_EXTERN 67 | void re_free_pattern P_((struct re_pattern_buffer*)); 68 | ONIG_EXTERN 69 | int re_adjust_startpos P_((struct re_pattern_buffer*, const char*, int, int, int)); 70 | ONIG_EXTERN 71 | int re_search P_((struct re_pattern_buffer*, const char*, int, int, int, struct re_registers*)); 72 | ONIG_EXTERN 73 | int re_match P_((struct re_pattern_buffer*, const char *, int, int, struct re_registers*)); 74 | ONIG_EXTERN 75 | void re_set_casetable P_((const char*)); 76 | ONIG_EXTERN 77 | void re_free_registers P_((struct re_registers*)); 78 | ONIG_EXTERN 79 | int re_alloc_pattern P_((struct re_pattern_buffer**)); /* added */ 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* ONIGGNU_H */ 86 | -------------------------------------------------------------------------------- /include/evhtp/onigposix.h: -------------------------------------------------------------------------------- 1 | #ifndef ONIGPOSIX_H 2 | #define ONIGPOSIX_H 3 | /********************************************************************** 4 | onigposix.h - Oniguruma (regular expression library) 5 | **********************************************************************/ 6 | /*- 7 | * Copyright (c) 2002-2005 K.Kosako 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* options */ 38 | #define REG_ICASE (1<<0) 39 | #define REG_NEWLINE (1<<1) 40 | #define REG_NOTBOL (1<<2) 41 | #define REG_NOTEOL (1<<3) 42 | #define REG_EXTENDED (1<<4) /* if not setted, Basic Onigular Expression */ 43 | #define REG_NOSUB (1<<5) 44 | 45 | /* POSIX error codes */ 46 | #define REG_NOMATCH 1 47 | #define REG_BADPAT 2 48 | #define REG_ECOLLATE 3 49 | #define REG_ECTYPE 4 50 | #define REG_EESCAPE 5 51 | #define REG_ESUBREG 6 52 | #define REG_EBRACK 7 53 | #define REG_EPAREN 8 54 | #define REG_EBRACE 9 55 | #define REG_BADBR 10 56 | #define REG_ERANGE 11 57 | #define REG_ESPACE 12 58 | #define REG_BADRPT 13 59 | 60 | /* extended error codes */ 61 | #define REG_EONIG_INTERNAL 14 62 | #define REG_EONIG_BADWC 15 63 | #define REG_EONIG_BADARG 16 64 | #define REG_EONIG_THREAD 17 65 | 66 | /* character encodings (for reg_set_encoding()) */ 67 | #define REG_POSIX_ENCODING_ASCII 0 68 | #define REG_POSIX_ENCODING_EUC_JP 1 69 | #define REG_POSIX_ENCODING_SJIS 2 70 | #define REG_POSIX_ENCODING_UTF8 3 71 | #define REG_POSIX_ENCODING_UTF16_BE 4 72 | #define REG_POSIX_ENCODING_UTF16_LE 5 73 | 74 | 75 | typedef int regoff_t; 76 | 77 | typedef struct { 78 | regoff_t rm_so; 79 | regoff_t rm_eo; 80 | } regmatch_t; 81 | 82 | /* POSIX regex_t */ 83 | typedef struct { 84 | void* onig; /* Oniguruma regex_t* */ 85 | size_t re_nsub; 86 | int comp_options; 87 | } regex_t; 88 | 89 | 90 | #ifndef P_ 91 | #if defined(__STDC__) || defined(_WIN32) 92 | # define P_(args) args 93 | #else 94 | # define P_(args) () 95 | #endif 96 | #endif 97 | 98 | #ifndef ONIG_EXTERN 99 | #if defined(_WIN32) && !defined(__GNUC__) 100 | #if defined(EXPORT) 101 | #define ONIG_EXTERN extern __declspec(dllexport) 102 | #else 103 | #define ONIG_EXTERN extern __declspec(dllimport) 104 | #endif 105 | #endif 106 | #endif 107 | 108 | #ifndef ONIG_EXTERN 109 | #define ONIG_EXTERN extern 110 | #endif 111 | 112 | #ifndef ONIGURUMA_H 113 | typedef unsigned int OnigOptionType; 114 | 115 | /* syntax */ 116 | typedef struct { 117 | unsigned int op; 118 | unsigned int op2; 119 | unsigned int behavior; 120 | OnigOptionType options; /* default option */ 121 | } OnigSyntaxType; 122 | 123 | ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic; 124 | ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended; 125 | ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs; 126 | ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep; 127 | ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex; 128 | ONIG_EXTERN OnigSyntaxType OnigSyntaxJava; 129 | ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl; 130 | ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby; 131 | 132 | /* predefined syntaxes (see regsyntax.c) */ 133 | #define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic) 134 | #define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended) 135 | #define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs) 136 | #define ONIG_SYNTAX_GREP (&OnigSyntaxGrep) 137 | #define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex) 138 | #define ONIG_SYNTAX_JAVA (&OnigSyntaxJava) 139 | #define ONIG_SYNTAX_PERL (&OnigSyntaxPerl) 140 | #define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby) 141 | /* default syntax */ 142 | #define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax 143 | 144 | ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax; 145 | 146 | ONIG_EXTERN int onig_set_default_syntax P_((OnigSyntaxType* syntax)); 147 | ONIG_EXTERN void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from)); 148 | ONIG_EXTERN const char* onig_version P_((void)); 149 | ONIG_EXTERN const char* onig_copyright P_((void)); 150 | 151 | #endif /* ONIGURUMA_H */ 152 | 153 | 154 | ONIG_EXTERN int regcomp P_((regex_t* reg, const char* pat, int options)); 155 | ONIG_EXTERN int regexec P_((regex_t* reg, const char* str, size_t nmatch, regmatch_t* matches, int options)); 156 | ONIG_EXTERN void regfree P_((regex_t* reg)); 157 | ONIG_EXTERN size_t regerror P_((int code, const regex_t* reg, char* buf, size_t size)); 158 | 159 | /* extended API */ 160 | ONIG_EXTERN void reg_set_encoding P_((int enc)); 161 | ONIG_EXTERN int reg_name_to_group_numbers P_((regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums)); 162 | ONIG_EXTERN int reg_foreach_name P_((regex_t* reg, int (*func)(const unsigned char*, const unsigned char*,int,int*,regex_t*,void*), void* arg)); 163 | ONIG_EXTERN int reg_number_of_names P_((regex_t* reg)); 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /* ONIGPOSIX_H */ 170 | -------------------------------------------------------------------------------- /inmemory-engine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: inmemory-engine.c 5 | * 6 | * Description: inmemory storage engine. 7 | * 8 | * Created: 11/24/2012 03:49:34 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "inmemory-engine.h" 21 | 22 | static int 23 | put(engine_base_t *engine, 24 | const char *key, unsigned int key_len, 25 | const char *value, unsigned int value_len) 26 | { 27 | inmemory_instance_t *tmp = NULL; 28 | engine_inmemory_t *engine_inmemory = (engine_inmemory_t *)engine; 29 | 30 | HASH_FIND_STR(engine_inmemory->instance, key, tmp); 31 | if (tmp == NULL) { 32 | tmp = (inmemory_instance_t *)malloc(sizeof(inmemory_instance_t)); 33 | if (tmp == NULL) { 34 | fprintf(stderr, "put key-value pair failed due to out of memory.\n"); 35 | return -1; 36 | } 37 | tmp->key = (char *)malloc(sizeof(char) * (key_len + 1)); 38 | memset(tmp->key, 0, (key_len + 1)); 39 | strncpy(tmp->key, key, key_len); 40 | tmp->value = (char *)malloc(sizeof(char) * (value_len + 1)); 41 | memset(tmp->value, 0, (value_len + 1)); 42 | strncpy(tmp->value, value, value_len); 43 | HASH_ADD_KEYPTR(hh, engine_inmemory->instance, tmp->key, strlen(tmp->key), tmp); 44 | } 45 | return 0; 46 | } 47 | 48 | static char * 49 | get(engine_base_t *engine, 50 | const char *key, unsigned int key_len, 51 | unsigned int *value_len) 52 | { 53 | char* value; 54 | inmemory_instance_t *tmp = NULL; 55 | engine_inmemory_t *engine_inmemory = (engine_inmemory_t *)engine; 56 | 57 | HASH_FIND_STR(engine_inmemory->instance, key, tmp); 58 | if (tmp == NULL) { 59 | *value_len = 0; 60 | return NULL; 61 | } else { 62 | int tmpval_len = strlen(tmp->value); 63 | value = (char *)malloc(sizeof(char) * (tmpval_len + 1)); 64 | memset(value, 0, (tmpval_len + 1)); 65 | strncpy(value, tmp->value, tmpval_len); 66 | *value_len = tmpval_len; 67 | } 68 | 69 | return value; 70 | } 71 | 72 | static int 73 | delete(engine_base_t *engine, 74 | const char *key, unsigned int key_len) 75 | { 76 | inmemory_instance_t *tmp = NULL; 77 | engine_inmemory_t *engine_inmemory = (engine_inmemory_t *)engine; 78 | 79 | HASH_FIND_STR(engine_inmemory->instance, key, tmp); 80 | if (tmp == NULL) { 81 | return 0; 82 | } else { 83 | HASH_DEL(engine_inmemory->instance, tmp); 84 | if (tmp->key != NULL) free(tmp->key); 85 | if (tmp->value != NULL) free(tmp->value); 86 | } 87 | return 0; 88 | } 89 | 90 | engine_inmemory_t * engine_inmemory_init(void) 91 | { 92 | engine_inmemory_t *engine = (engine_inmemory_t *) 93 | malloc(sizeof(engine_inmemory_t)); 94 | 95 | engine->instance = NULL; 96 | 97 | engine_operation_t *engine_ops = (engine_operation_t *) 98 | malloc(sizeof(engine_operation_t)); 99 | 100 | const char *engine_name = "inmemory engine v0.1"; 101 | unsigned int engine_name_len = strlen(engine_name); 102 | unsigned int version = 0x1; 103 | engine->base.name = malloc(sizeof(char) * (engine_name_len + 1)); 104 | memset(engine->base.name, 0, (engine_name_len + 1)); 105 | strncpy(engine->base.name, engine_name, engine_name_len); 106 | engine->base.version = version; 107 | 108 | engine_ops->put = put; 109 | engine_ops->get = get; 110 | engine_ops->delete = delete; 111 | 112 | engine->base.engine_ops = engine_ops; 113 | 114 | return engine; 115 | } 116 | -------------------------------------------------------------------------------- /inmemory-engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: inmemory-engine.h 5 | * 6 | * Description: inmemory storage engine 7 | * 8 | * Created: 11/24/2012 03:49:23 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #ifndef INMEMORY_ENGINE_H 17 | #define INMEMORY_ENGINE_H 18 | #include 19 | #include 20 | #include 21 | 22 | #include "uthash.h" 23 | #include "csas.h" 24 | 25 | typedef struct engine_inmemory_s_ engine_inmemory_t; 26 | typedef struct inmemory_instance_s_ inmemory_instance_t; 27 | 28 | struct inmemory_instance_s_ { 29 | char *key; 30 | char *value; 31 | UT_hash_handle hh; 32 | }; 33 | 34 | struct engine_inmemory_s_ { 35 | /* engine base goes here, it MUST be a struct object, 36 | * and NOT a struct pointer. 37 | * */ 38 | engine_base_t base; 39 | 40 | inmemory_instance_t *instance; 41 | }; 42 | 43 | extern engine_inmemory_t * engine_inmemory_init(); 44 | 45 | #endif /* INMEMORY_ENGINE_H */ 46 | -------------------------------------------------------------------------------- /leveldb-engine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: leveldb-engine.c 5 | * 6 | * Description: leveldb storage engine. 7 | * 8 | * Created: 11/24/2012 03:49:34 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "leveldb-engine.h" 21 | 22 | static char *dbname = "/tmp/leveldb"; 23 | 24 | static int 25 | put(engine_base_t *engine, 26 | const char *key, unsigned int key_len, 27 | const char *value, unsigned int value_len) 28 | { 29 | engine_leveldb_t *engine_leveldb = (engine_leveldb_t *)engine; 30 | leveldb_instance_t *instance = engine_leveldb->instance; 31 | leveldb_put(instance->db, instance->woptions, 32 | key, key_len, value, value_len, &(instance->err)); 33 | return 0; 34 | } 35 | 36 | static char * 37 | get(engine_base_t *engine, 38 | const char *key, unsigned int key_len, 39 | unsigned int *value_len) 40 | { 41 | char* value; 42 | engine_leveldb_t *engine_leveldb = (engine_leveldb_t *)engine; 43 | leveldb_instance_t *instance = engine_leveldb->instance; 44 | value = leveldb_get(instance->db, instance->roptions, 45 | key, key_len, value_len, &(instance->err)); 46 | return value; 47 | } 48 | 49 | static int 50 | delete(engine_base_t *engine, 51 | const char *key, unsigned int key_len) 52 | { 53 | engine_leveldb_t *engine_leveldb = (engine_leveldb_t *)engine; 54 | leveldb_instance_t *instance = engine_leveldb->instance; 55 | leveldb_delete(instance->db, instance->woptions, key, key_len, &(instance->err)); 56 | return 0; 57 | } 58 | 59 | static engine_leveldb_config_t * 60 | engine_leveldb_config_init(void) 61 | { 62 | engine_leveldb_config_t *config = (engine_leveldb_config_t *) 63 | malloc(sizeof(engine_leveldb_config_t)); 64 | 65 | unsigned int dbname_len = strlen(dbname); 66 | config->dbname = (char *)malloc(sizeof(char) * (dbname_len + 1)); 67 | memset(config->dbname, 0, (dbname_len + 1)); 68 | strncpy(config->dbname, dbname, dbname_len); 69 | 70 | config->lru_cache_size = 65536; 71 | config->create_if_missing = true; 72 | config->error_if_exist = false; 73 | config->write_buffer_size = 65536; 74 | config->paranoid_checks = true; 75 | config->max_open_files = 32; 76 | config->block_size = 1024; 77 | config->block_restart_interval = 8; 78 | config->compression_support = false; 79 | config->verify_checksums = false; 80 | config->fill_cache = false; 81 | config->sync = false; 82 | 83 | return config; 84 | 85 | } 86 | 87 | static leveldb_instance_t * 88 | leveldb_instance_init(engine_leveldb_config_t *config) 89 | { 90 | leveldb_instance_t *instance = (leveldb_instance_t *) 91 | malloc(sizeof(leveldb_instance_t)); 92 | 93 | instance->comparator = NULL; 94 | instance->env = leveldb_create_default_env(); 95 | instance->cache = leveldb_cache_create_lru(config->lru_cache_size); 96 | instance->filterpolicy = NULL; 97 | instance->iterator = NULL; 98 | instance->logger = NULL; 99 | instance->snapshot = NULL; 100 | instance->writebatch = NULL; 101 | instance->options = leveldb_options_create(); 102 | leveldb_options_set_error_if_exists(instance->options, config->error_if_exist); 103 | leveldb_options_set_create_if_missing(instance->options, config->create_if_missing); 104 | leveldb_options_set_cache(instance->options, instance->cache); 105 | leveldb_options_set_env(instance->options, instance->env); 106 | leveldb_options_set_info_log(instance->options, NULL); 107 | leveldb_options_set_write_buffer_size(instance->options, config->write_buffer_size); 108 | leveldb_options_set_paranoid_checks(instance->options, config->paranoid_checks); 109 | leveldb_options_set_max_open_files(instance->options, 10); 110 | leveldb_options_set_block_size(instance->options, 1024); 111 | leveldb_options_set_block_restart_interval(instance->options, 8); 112 | leveldb_options_set_compression(instance->options, leveldb_no_compression); 113 | 114 | instance->roptions = leveldb_readoptions_create(); 115 | leveldb_readoptions_set_verify_checksums(instance->roptions, config->verify_checksums); 116 | leveldb_readoptions_set_fill_cache(instance->roptions, config->fill_cache); 117 | 118 | instance->woptions = leveldb_writeoptions_create(); 119 | leveldb_writeoptions_set_sync(instance->woptions, config->sync); 120 | 121 | instance->db = leveldb_open(instance->options, config->dbname, &(instance->err)); 122 | 123 | return instance; 124 | 125 | } 126 | 127 | engine_leveldb_t * engine_leveldb_init() 128 | { 129 | engine_leveldb_t *engine = (engine_leveldb_t *) 130 | malloc(sizeof(engine_leveldb_t)); 131 | 132 | engine_leveldb_config_t *config = engine_leveldb_config_init(); 133 | leveldb_instance_t * instance = leveldb_instance_init(config); 134 | 135 | engine->config = config; 136 | engine->instance = instance; 137 | 138 | engine_operation_t *engine_ops = (engine_operation_t *) 139 | malloc(sizeof(engine_operation_t)); 140 | 141 | const char *engine_name = "leveldb engine v0.1"; 142 | unsigned int engine_name_len = strlen(engine_name); 143 | unsigned int version = 0x1; 144 | engine->base.name = malloc(sizeof(char) * (engine_name_len + 1)); 145 | memset(engine->base.name, 0, (engine_name_len + 1)); 146 | strncpy(engine->base.name, engine_name, engine_name_len); 147 | engine->base.version = version; 148 | 149 | engine_ops->put = put; 150 | engine_ops->get = get; 151 | engine_ops->delete = delete; 152 | 153 | engine->base.engine_ops = engine_ops; 154 | 155 | return engine; 156 | } 157 | -------------------------------------------------------------------------------- /leveldb-engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: leveldb-engine.h 5 | * 6 | * Description: leveldb storage engine 7 | * 8 | * Created: 11/24/2012 03:49:23 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #ifndef LEVELDB_ENGINE_H 17 | #define LEVELDB_ENGINE_H 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include "csas.h" 24 | 25 | typedef struct engine_leveldb_s_ engine_leveldb_t; 26 | typedef struct engine_leveldb_config_s_ engine_leveldb_config_t; 27 | typedef struct leveldb_instance_s_ leveldb_instance_t; 28 | 29 | struct engine_leveldb_config_s_ { 30 | char *dbname; /** default database name.*/ 31 | unsigned int lru_cache_size; /** leveldb's lru cache size */ 32 | bool create_if_missing; /** create database if it doesn't exist. */ 33 | bool error_if_exist; /** open database throws an error if exist. */ 34 | unsigned int write_buffer_size; /** leveldb's write buffer size */ 35 | bool paranoid_checks; /**paranoid checks */ 36 | unsigned int max_open_files; /** max open files */ 37 | unsigned block_size; /** block size */ 38 | unsigned int block_restart_interval; /*block restart interval */ 39 | /** compression support, 0: no compression, 1: snappy compression.*/ 40 | bool compression_support; 41 | bool verify_checksums; /** set true to verify checksums when read. */ 42 | bool fill_cache; /** set true if want to fill cache. */ 43 | bool sync; /** set true to enable sync when write. */ 44 | }; 45 | 46 | struct leveldb_instance_s_ { 47 | /* leveldb instance. */ 48 | leveldb_t *db; 49 | leveldb_cache_t *cache; 50 | leveldb_comparator_t *comparator; 51 | leveldb_env_t *env; 52 | leveldb_filterpolicy_t *filterpolicy; 53 | leveldb_iterator_t *iterator; 54 | leveldb_logger_t *logger; 55 | leveldb_options_t *options; 56 | leveldb_readoptions_t *roptions; 57 | leveldb_snapshot_t *snapshot; 58 | leveldb_writebatch_t *writebatch; 59 | leveldb_writeoptions_t *woptions; 60 | 61 | char *err; 62 | }; 63 | 64 | struct engine_leveldb_s_ { 65 | /* engine base goes here, it MUST be a struct object, 66 | * and NOT a struct pointer. 67 | * */ 68 | engine_base_t base; 69 | 70 | leveldb_instance_t *instance; 71 | engine_leveldb_config_t *config; 72 | }; 73 | 74 | extern engine_leveldb_t * engine_leveldb_init(); 75 | 76 | #endif /* LEVELDB_ENGINE_H */ 77 | -------------------------------------------------------------------------------- /lib/placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forhappy/tinydb/26e382fc11ba3c273ef49b56d38c92732beb674d/lib/placeholder -------------------------------------------------------------------------------- /libevhtp/.gitignore: -------------------------------------------------------------------------------- 1 | # cmake manages these; they shouldn't go in version control 2 | 3 | /CMakeCache.txt 4 | /CMakeFiles/** 5 | /Makefile 6 | /cmake_install.cmake 7 | 8 | # generated .h files 9 | 10 | /compat/sys/tree.h 11 | /oniguruma/config.h 12 | 13 | # compiled files 14 | 15 | /libevhtp.a 16 | /test 17 | /test_basic 18 | /test_vhost 19 | 20 | -------------------------------------------------------------------------------- /libevhtp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(reason) 3 | 4 | set(PROJECT_MAJOR_VERSION 1) 5 | set(PROJECT_MINOR_VERSION 1) 6 | set(PROJECT_PATCH_VERSION 7) 7 | 8 | set (PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION}.${PROJECT_PATCH_VERSION}) 9 | set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules) 10 | 11 | INCLUDE (CheckFunctionExists) 12 | INCLUDE (CheckIncludeFiles) 13 | INCLUDE (CheckTypeSize) 14 | 15 | CHECK_FUNCTION_EXISTS(alloca C_ALLOCA) 16 | CHECK_FUNCTION_EXISTS(memcmp HAVE_MEMCMP) 17 | CHECK_FUNCTION_EXISTS(strndup HAVE_STRNDUP) 18 | CHECK_FUNCTION_EXISTS(strnlen HAVE_STRNLEN) 19 | 20 | CHECK_INCLUDE_FILES(alloca.h HAVE_ALLOCA_H) 21 | CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H) 22 | CHECK_INCLUDE_FILES(string.h HAVE_STRING_H) 23 | CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H) 24 | CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H) 25 | CHECK_INCLUDE_FILES(sys/times.h HAVE_SYS_TIMES_H) 26 | CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H) 27 | CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H) 28 | CHECK_INCLUDE_FILES(stdarg.h HAVE_STDARG_PROTOTYPES) 29 | CHECK_INCLUDE_FILES(sys/tree.h HAVE_SYS_TREE) 30 | CHECK_INCLUDE_FILES(sys/queue.h HAVE_SYS_QUEUE) 31 | CHECK_INCLUDE_FILES(sys/un.h HAVE_SYS_UN) 32 | 33 | CHECK_TYPE_SIZE("int" SIZEOF_INT) 34 | CHECK_TYPE_SIZE("long" SIZEOF_LONG) 35 | CHECK_TYPE_SIZE("short" SIZEOF_SHORT) 36 | 37 | if (NOT HAVE_SYS_TREE) 38 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/compat/sys/tree.h.in ${CMAKE_CURRENT_BINARY_DIR}/compat/sys/tree.h) 39 | endif(NOT HAVE_SYS_TREE) 40 | 41 | if (NOT HAVE_SYS_QUEUE) 42 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/compat/sys/queue.h.in ${CMAKE_CURRENT_BINARY_DIR}/compat/sys/queue.h) 43 | endif(NOT HAVE_SYS_QUEUE) 44 | 45 | if (NOT HAVE_STRNDUP) 46 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_STRNDUP") 47 | endif(NOT HAVE_STRNDUP) 48 | 49 | if (NOT HAVE_STRNLEN) 50 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_STRNLEN") 51 | endif(NOT HAVE_STRNLEN) 52 | 53 | if (NOT HAVE_SYS_UN) 54 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_SYS_UN") 55 | endif(NOT HAVE_SYS_UN) 56 | 57 | OPTION(EVHTP_DISABLE_SSL "Disable ssl support" ON) 58 | OPTION(EVHTP_DISABLE_EVTHR "Disable evthread support" OFF) 59 | OPTION(EVHTP_DIABLE_REGEX "Disable regex support" OFF) 60 | 61 | # -DEVHTP_USE_DEFER_ACCEPT:STRING=ON 62 | OPTION(EVHTP_USE_DEFER_ACCEPT "Enable TCP_DEFER_ACCEPT" OFF) 63 | 64 | if (EVHTP_USE_DEFER_ACCEPT) 65 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_DEFER_ACCEPT") 66 | endif(EVHTP_USE_DEFER_ACCEPT) 67 | 68 | SET(CMAKE_INCLUDE_CURRENT_DIR ON) 69 | 70 | include(BaseConfig) 71 | 72 | message("Build Type: ${CMAKE_BUILD_TYPE}") 73 | message("Std CFLAGS: ${CMAKE_C_FLAGS}") 74 | message("Dbg CFLAGS: ${CMAKE_C_FLAGS_DEBUG}") 75 | message("Rel CFLAGS: ${CMAKE_C_FLAGS_RELEASE}") 76 | 77 | find_package(LibEvent REQUIRED) 78 | find_package(OpenSSL) 79 | find_path(LIBEVENT_INCLUDE_DIR event2/event.h REQUIRED) 80 | 81 | if (NOT OPENSSL_FOUND) 82 | message("Diabling SSL") 83 | set (EVHTP_DISABLE_SSL ON) 84 | set (OPENSSL_CRYPTO_LIBRARY "") 85 | set (OPENSSL_INCLUDE_DIR "") 86 | set (OPENSSL_LIBRARIES "") 87 | set (LIBEVENT_OPENSSL_LIBRARY "") 88 | endif() 89 | 90 | 91 | if (NOT EVHTP_DISABLE_REGEX) 92 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/oniguruma/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/oniguruma/config.h) 93 | set(ONIG_SOURCES 94 | oniguruma/regerror.c 95 | oniguruma/regparse.c 96 | oniguruma/regext.c 97 | oniguruma/regcomp.c 98 | oniguruma/regexec.c 99 | oniguruma/reggnu.c 100 | oniguruma/regenc.c 101 | oniguruma/regsyntax.c 102 | oniguruma/regtrav.c 103 | oniguruma/regversion.c 104 | oniguruma/st.c 105 | oniguruma/regposix.c 106 | oniguruma/regposerr.c 107 | oniguruma/enc/unicode.c 108 | oniguruma/enc/ascii.c 109 | oniguruma/enc/utf8.c 110 | oniguruma/enc/utf16_be.c 111 | oniguruma/enc/utf16_le.c 112 | oniguruma/enc/utf32_be.c 113 | oniguruma/enc/utf32_le.c 114 | oniguruma/enc/euc_jp.c 115 | oniguruma/enc/sjis.c 116 | oniguruma/enc/iso8859_1.c 117 | oniguruma/enc/iso8859_2.c 118 | oniguruma/enc/iso8859_3.c 119 | oniguruma/enc/iso8859_4.c 120 | oniguruma/enc/iso8859_5.c 121 | oniguruma/enc/iso8859_6.c 122 | oniguruma/enc/iso8859_7.c 123 | oniguruma/enc/iso8859_8.c 124 | oniguruma/enc/iso8859_9.c 125 | oniguruma/enc/iso8859_10.c 126 | oniguruma/enc/iso8859_11.c 127 | oniguruma/enc/iso8859_13.c 128 | oniguruma/enc/iso8859_14.c 129 | oniguruma/enc/iso8859_15.c 130 | oniguruma/enc/iso8859_16.c 131 | oniguruma/enc/euc_tw.c 132 | oniguruma/enc/euc_kr.c 133 | oniguruma/enc/big5.c 134 | oniguruma/enc/gb18030.c 135 | oniguruma/enc/koi8_r.c 136 | oniguruma/enc/cp1251.c) 137 | else() 138 | set(ONIG_SOURCES "") 139 | endif() 140 | 141 | 142 | include_directories( 143 | ${CMAKE_CURRENT_BINARY_DIR}/compat 144 | ${CMAKE_CURRENT_SOURCE_DIR}/htparse 145 | ${CMAKE_CURRENT_BINARY_DIR}/oniguruma 146 | ${CMAKE_CURRENT_SOURCE_DIR}/oniguruma 147 | ${CMAKE_CURRENT_SOURCE_DIR} 148 | ${CMAKE_CURRENT_SOURCE_DIR}/evthr 149 | ${OPENSSL_INCLUDE_DIR} 150 | ${LIBEVENT_INCLUDE_DIR} 151 | ) 152 | 153 | set(LIBEVHTP_EXTERNAL_LIBS 154 | ${LIBEVENT_LIBRARY} 155 | ${LIBEVENT_PTHREADS_LIBRARY} 156 | ${LIBEVENT_OPENSSL_LIBRARY} 157 | ${OPENSSL_LIBRARIES}) 158 | 159 | if (NOT ${LIBEVENT_PTHREADS_FOUND}) 160 | set(EVHTP_DISABLE_EVTHR 1) 161 | endif(NOT ${LIBEVENT_PTHREADS_FOUND}) 162 | 163 | if (NOT ${LIBEVENT_OPENSSL_FOUND}) 164 | set (EVHTP_DISABLE_SSL 1) 165 | endif(NOT ${LIBEVENT_OPENSSL_FOUND}) 166 | 167 | set(LIBEVHTP_SOURCES evhtp.c htparse/htparse.c) 168 | 169 | if (NOT EVHTP_DISABLE_EVTHR) 170 | set (LIBEVHTP_EXTERNAL_LIBS ${LIBEVHTP_EXTERNAL_LIBS} pthread) 171 | set (LIBEVHTP_SOURCES ${LIBEVHTP_SOURCES} evthr/evthr.c) 172 | endif(NOT EVHTP_DISABLE_EVTHR) 173 | 174 | if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug") 175 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG") 176 | endif (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug") 177 | 178 | if (EVHTP_DISABLE_SSL) 179 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEVHTP_DISABLE_SSL") 180 | endif() 181 | 182 | add_library(libevhtp STATIC ${LIBEVHTP_SOURCES} ${ONIG_SOURCES}) 183 | set_target_properties(libevhtp PROPERTIES OUTPUT_NAME "evhtp") 184 | 185 | install (TARGETS libevhtp DESTINATION lib) 186 | install (FILES evhtp.h DESTINATION include) 187 | install (FILES htparse/htparse.h DESTINATION include) 188 | install (FILES evthr/evthr.h DESTINATION include) 189 | install (FILES oniguruma/onigposix.h DESTINATION include) 190 | 191 | find_library (LIB_DL dl) 192 | set (SYS_LIBS ${LIB_DL}) 193 | 194 | if (NOT APPLE) 195 | find_library (LIB_RT rt) 196 | set (SYS_LIBS ${SYS_LIBS} ${LIB_RT}) 197 | endif() 198 | 199 | add_executable(test test.c) 200 | target_link_libraries(test libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS}) 201 | 202 | add_executable(test_basic test_basic.c) 203 | target_link_libraries(test_basic libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS}) 204 | 205 | add_executable(test_vhost test_vhost.c) 206 | target_link_libraries(test_vhost libevhtp ${LIBEVHTP_EXTERNAL_LIBS} ${SYS_LIBS}) 207 | -------------------------------------------------------------------------------- /libevhtp/CMakeModules/BaseConfig.cmake: -------------------------------------------------------------------------------- 1 | if (CMAKE_COMPILER_IS_GNUCC) 2 | 3 | set(RSN_BASE_C_FLAGS "-Wall -fno-strict-aliasing") 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${RSN_BASE_C_FLAGS} -DPROJECT_VERSION=\"${PROJECT_VERSION}\"") 5 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${RSN_BASE_C_FLAGS} -ggdb") 6 | set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RSN_BASE_C_FLAGS}") 7 | 8 | if(APPLE) 9 | # Newer versions of OSX will spew a bunch of warnings about deprecated ssl functions, 10 | # this should be addressed at some point in time, but for now, just ignore them. 11 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -Wno-deprecated-declarations") 12 | elseif(UNIX) 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112") 14 | endif(APPLE) 15 | 16 | endif(CMAKE_COMPILER_IS_GNUCC) 17 | 18 | if (EVHTP_DISABLE_EVTHR) 19 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEVHTP_DISABLE_EVTHR") 20 | endif(EVHTP_DISABLE_EVTHR) 21 | 22 | if (EVHTP_DISABLE_SSL) 23 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEVHTP_DISABLE_SSL") 24 | endif(EVHTP_DISABLE_SSL) 25 | 26 | if (NOT CMAKE_BUILD_TYPE) 27 | set(CMAKE_BUILD_TYPE Release) 28 | endif(NOT CMAKE_BUILD_TYPE) 29 | -------------------------------------------------------------------------------- /libevhtp/CMakeModules/FindLibEvent.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the LibEvent config processing library 2 | # Once done this will define 3 | # 4 | # LIBEVENT_FOUND - System has LibEvent 5 | # LIBEVENT_INCLUDE_DIR - the LibEvent include directory 6 | # LIBEVENT_LIBRARIES 0 The libraries needed to use LibEvent 7 | 8 | FIND_PATH(LIBEVENT_INCLUDE_DIR NAMES event.h) 9 | FIND_LIBRARY(LIBEVENT_LIBRARY NAMES event) 10 | FIND_LIBRARY(LIBEVENT_CORE_LIBRARY NAMES event_core) 11 | FIND_LIBRARY(LIBEVENT_PTHREADS_LIBRARY NAMES event_pthreads) 12 | FIND_LIBRARY(LIBEVENT_EXTRA_LIBRARY NAMES event_extra) 13 | FIND_LIBRARY(LIBEVENT_OPENSSL_LIBRARY NAMES event_openssl) 14 | 15 | 16 | INCLUDE(FindPackageHandleStandardArgs) 17 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibEvent DEFAULT_MSG LIBEVENT_LIBRARY LIBEVENT_INCLUDE_DIR) 18 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibEventPthreads DEFAULT_MSG LIBEVENT_PTHREADS_LIBRARY LIBEVENT_INCLUDE_DIR) 19 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibEventCore DEFAULT_MSG LIBEVENT_CORE_LIBRARY LIBEVENT_INCLUDE_DIR) 20 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibEventExtra DEFAULT_MSG LIBEVENT_EXTRA_LIBRARY LIBEVENT_INCLUDE_DIR) 21 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibEventOpenssl DEFAULT_MSG LIBEVENT_OPENSSL_LIBRARY LIBEVENT_INCLUDE_DIR) 22 | 23 | MARK_AS_ADVANCED(LIBEVENT_INCLUDE_DIR LIBEVENT_LIBRARY LIBEVENT_PTHREADS_LIBRARY LIBEVENT_OPENSSL_LIBRARY LIBEVENT_CORE_LIBRARY LIBEVENT_EXTRA_LIBRARY) 24 | -------------------------------------------------------------------------------- /libevhtp/LICENSE: -------------------------------------------------------------------------------- 1 | Libevhtp is available for use under the following license, commonly known 2 | as the 3-clause (or "modified") BSD license: 3 | 4 | ============================== 5 | Copyright (c) 2010-2011 Mark Ellzey 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | ============================== 29 | 30 | Portions of Libevhtp are based on works by others, also made available by them 31 | under the three-clause BSD license above. The functions include: 32 | 33 | evhtp.c: _evhtp_glob_match(): 34 | Copyright (c) 2006-2009, Salvatore Sanfilippo 35 | -------------------------------------------------------------------------------- /libevhtp/README.markdown: -------------------------------------------------------------------------------- 1 | # Libevhtp 2 | ***** 3 | 4 | This document describes details on using the evhtp API. This document is 5 | probably not very awesome, it's best to look at test.c to see advanced usage. 6 | 7 | ## Required Dependencies 8 | * [gcc](http://gcc.gnu.org/) 9 | * [Libevent2](http://libevent.org) 10 | 11 | ## Optional Dependencies 12 | * [OpenSSL](http://openssl.org) 13 | * pthreads 14 | 15 | ## Overview 16 | *** 17 | 18 | Libevhtp was created as a replacement API for Libevent's current HTTP API. The reality of libevent's http interface is that it was created as a JIT server, meaning the developer never thought of it being used for creating a full-fledged HTTP service. Infact I am under the impression that the libevent http API was designed almost as an example of what you can do with libevent. It's not Apache in a box, but more and more developers are attempting to use it as so. 19 | 20 | ### Libevent's HTTP pitfalls 21 | *** 22 | 23 | * It was not designed to be a fully functional HTTP server. 24 | * The code is messy, abstractions are almost non-existent, and feature-creep has made long-term maintainability very hard. 25 | * The parsing code is slow and requires data to be buffered before a full parse can be completed. This results in extranious memory usage and lots of string comparison functions. 26 | * There is no method for a user to access various parts of the request processing cycle. For example if the "Content-Length" header has a value of 50000, your callback is not executed until all 50000 bytes have been read. 27 | * Setting callback URI's do exact matches; meaning if you set a callback for "/foo/", requests for "/foo/bar/" are ignored. 28 | * Creating an HTTPS server is hard, it requires a bunch of work to be done on the underlying bufferevents. 29 | * As far as I know, streaming data back to a client is hard, if not impossible without messing with underlying bufferevents. 30 | * It's confusing to work with, this is probably due to the lack of proper documentation. 31 | 32 | Libevhtp attempts to address these problems along with a wide variety of cool mechanisms allowing a developer to have complete control over your server operations. This is not to say the API cannot be used in a very simplistic manner - a developer can easily create a backwards compatible version of libevent's HTTP server to libevhtp. 33 | 34 | ### A bit about the architecture of libevhtp 35 | *** 36 | 37 | #### Bootstrapping 38 | 39 | 1. Create a parent evhtp_t structure. 40 | 2. Assign callbacks to the parent for specific URIs or posix-regex based URI's 41 | 3. Optionally assign per-connection hooks (see hooks) to the callbacks. 42 | 4. Optionally assign pre-accept and post-accept callbacks for incoming connections. 43 | 5. Optionally enable built-in threadpool for connection handling (lock-free, and non-blocking). 44 | 6. Optionally morph your server to HTTPS. 45 | 7. Start the evhtp listener. 46 | 47 | #### Request handling. 48 | 49 | 1. Optionally deal with pre-accept and post-accept callbacks if they exist, allowing for a connection to be rejected if the function deems it as unacceptable. 50 | 2. Optionally assign per-request hooks (see hooks) for a request (the most optimal place for setting these hooks is on a post-accept callback). 51 | 3. Deal with either per-connection or per-request hook callbacks if they exist. 52 | 4. Once the request has been fully processed, inform evhtp to send a reply. 53 | 54 | ##### A very basic example with no optional conditions. 55 | 56 | #include 57 | #include 58 | 59 | void 60 | testcb(evhtp_request_t * req, void * a) { 61 | evbuffer_add_reference(req->buffer_out, "foobar", 6, NULL, NULL); 62 | evhtp_send_reply(req, EVHTP_RES_OK); 63 | } 64 | 65 | int 66 | main(int argc, char ** argv) { 67 | evbase_t * evbase = event_base_new(); 68 | evhtp_t * htp = evhtp_new(evbase, NULL); 69 | 70 | evhtp_set_cb(htp, "/test", testcb, NULL); 71 | evhtp_bind_socket(htp, "0.0.0.0", 8080, 1024); 72 | event_base_loop(evbase, 0); 73 | return 0; 74 | } 75 | 76 | 77 | ## Is evhtp thread-safe? 78 | 79 | For simple usage with evhtp_use_threads(), yes. But for more extreme cases: 80 | sorta, you are bound to the thread mechanisms of libevent itself. 81 | 82 | But with proper design around libevhtp, thread issues can be out-of-sight, 83 | out-of-mind. 84 | 85 | What do you mean by this "proper design" statement? 86 | 87 | Refer to the code in ./examples/thread_design.c. The comments go into great detail 88 | of the hows and whys for proper design using libevhtp's threading model. 89 | 90 | This example uses redis, mainly because most people who have asked me "is evhtp 91 | thread-safe" were attempting to *other things* before sending a response to a 92 | request. And on more than one occasion, those *other things* were communicating 93 | with redis. 94 | -------------------------------------------------------------------------------- /libevhtp/build/placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forhappy/tinydb/26e382fc11ba3c273ef49b56d38c92732beb674d/libevhtp/build/placeholder -------------------------------------------------------------------------------- /libevhtp/contrib/ab_wsesscache.README: -------------------------------------------------------------------------------- 1 | Patches Apache Bench to support the ability to read in a client session-id file. 2 | 3 | Usage: 4 | openssl s_client -connect your_server:your_port -sess_out -ssl3 5 | ab [opts] -I 6 | -------------------------------------------------------------------------------- /libevhtp/contrib/ab_wsesscache.diff: -------------------------------------------------------------------------------- 1 | --- support/ab.c 2010-07-12 05:26:29.000000000 -0400 2 | +++ support/ab.c 2011-06-21 15:29:21.961972191 -0400 3 | @@ -340,6 +340,7 @@ 4 | char *ssl_cipher = NULL; 5 | char *ssl_info = NULL; 6 | BIO *bio_out,*bio_err; 7 | +char * sess_in = NULL; 8 | #endif 9 | 10 | apr_time_t start, lasttime, stoptime; 11 | @@ -1195,6 +1196,28 @@ 12 | ERR_print_errors(bio_err); 13 | exit(1); 14 | } 15 | + 16 | + if (sess_in != NULL) { 17 | + SSL_SESSION * sess; 18 | + BIO * sidfile; 19 | + 20 | + if (!(sidfile = BIO_new_file(sess_in, "r"))) { 21 | + fprintf(stderr, "error opening session file %s\n", sess_in); 22 | + ERR_print_errors_fp(stderr); 23 | + exit(1); 24 | + } 25 | + 26 | + if (!(sess = PEM_read_bio_SSL_SESSION(sidfile, NULL, 0, NULL))) { 27 | + fprintf(stderr, "error reading session file %s\n", sess_in); 28 | + ERR_print_errors_fp(stderr); 29 | + exit(1); 30 | + } 31 | + 32 | + BIO_free(sidfile); 33 | + SSL_set_session(c->ssl, sess); 34 | + SSL_SESSION_free(sess); 35 | + } 36 | + 37 | ssl_rand_seed(); 38 | apr_os_sock_get(&fd, c->aprsock); 39 | bio = BIO_new_socket(fd, BIO_NOCLOSE); 40 | @@ -1875,6 +1898,7 @@ 41 | #ifdef USE_SSL 42 | fprintf(stderr, " -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)\n"); 43 | fprintf(stderr, " -f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)\n"); 44 | + fprintf(stderr, " -I in_file Specify file to read SSL session from\n"); 45 | #endif 46 | exit(EINVAL); 47 | } 48 | @@ -2040,7 +2064,7 @@ 49 | apr_getopt_init(&opt, cntxt, argc, argv); 50 | while ((status = apr_getopt(opt, "n:c:t:b:T:p:u:v:rkVhwix:y:z:C:H:P:A:g:X:de:Sq" 51 | #ifdef USE_SSL 52 | - "Z:f:" 53 | + "Z:f:I:" 54 | #endif 55 | ,&c, &optarg)) == APR_SUCCESS) { 56 | switch (c) { 57 | @@ -2215,6 +2239,9 @@ 58 | meth = TLSv1_client_method(); 59 | } 60 | break; 61 | + case 'I': 62 | + sess_in = strdup(optarg); 63 | + break; 64 | #endif 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /libevhtp/contrib/git_changelog.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2008 Marcus D. Hanwell 3 | # Modifications by Mark Ellzey 4 | # Distributed under the terms of the GNU General Public License v2 or later 5 | 6 | import string, re, os, sys 7 | 8 | # Execute git log with the desired command line options. 9 | old_tag = sys.argv[1] 10 | new_tag = sys.argv[2] 11 | 12 | fin = os.popen('git log --summary --stat --no-merges --date=short %s..%s' % (old_tag, new_tag), 'r') 13 | 14 | os.system("mv ChangeLog bak.ChangeLog") 15 | 16 | # Create a ChangeLog file in the current directory. 17 | fout = open('ChangeLog', 'w') 18 | 19 | # Set up the loop variables in order to locate the blocks we want 20 | authorFound = False 21 | dateFound = False 22 | messageFound = False 23 | filesFound = False 24 | message = "" 25 | messageNL = False 26 | files = "" 27 | prevAuthorLine = "" 28 | 29 | fout.write("v%s\n" % new_tag) 30 | fout.write("=====================================\n") 31 | 32 | # The main part of the loop 33 | for line in fin: 34 | # The commit line marks the start of a new commit object. 35 | if string.find(line, 'commit') >= 0: 36 | # Start all over again... 37 | authorFound = False 38 | dateFound = False 39 | messageFound = False 40 | messageNL = False 41 | message = "" 42 | filesFound = False 43 | files = "" 44 | continue 45 | # Match the author line and extract the part we want 46 | elif re.match('Author:', line) >=0: 47 | authorList = re.split(': ', line, 1) 48 | author = authorList[1] 49 | author = author[0:len(author)-1] 50 | authorFound = True 51 | # Match the date line 52 | elif re.match('Date:', line) >= 0: 53 | dateList = re.split(': ', line, 1) 54 | date = dateList[1] 55 | date = date[0:len(date)-1] 56 | dateFound = True 57 | # The svn-id lines are ignored 58 | elif re.match(' git-svn-id:', line) >= 0: 59 | continue 60 | # The sign off line is ignored too 61 | elif re.search('Signed-off-by', line) >= 0: 62 | continue 63 | # Extract the actual commit message for this commit 64 | elif authorFound & dateFound & messageFound == False: 65 | # Find the commit message if we can 66 | if len(line) == 1: 67 | if messageNL: 68 | messageFound = True 69 | else: 70 | messageNL = True 71 | elif len(line) == 4: 72 | messageFound = True 73 | else: 74 | if len(message) == 0: 75 | message = message + line.strip() 76 | else: 77 | message = message + " " + line.strip() 78 | # If this line is hit all of the files have been stored for this commit 79 | elif re.search('files changed', line) >= 0: 80 | filesFound = True 81 | continue 82 | # Collect the files for this commit. FIXME: Still need to add +/- to files 83 | elif authorFound & dateFound & messageFound: 84 | fileList = re.split(' \| ', line, 2) 85 | if len(fileList) > 1: 86 | if len(files) > 0: 87 | files = files + ", " + fileList[0].strip() 88 | else: 89 | files = fileList[0].strip() 90 | # All of the parts of the commit have been found - write out the entry 91 | if authorFound & dateFound & messageFound & filesFound: 92 | # First the author line, only outputted if it is the first for that 93 | # author on this day 94 | authorLine = date + " " + author 95 | if len(prevAuthorLine) == 0: 96 | fout.write(authorLine + "\n") 97 | elif authorLine == prevAuthorLine: 98 | pass 99 | else: 100 | fout.write("\n" + authorLine + "\n") 101 | 102 | # Assemble the actual commit message line(s) and limit the line length 103 | # to 80 characters. 104 | commitLine = "* " + files + ": " + message 105 | i = 0 106 | commit = "" 107 | while i < len(commitLine): 108 | if len(commitLine) < i + 78: 109 | commit = commit + "\n " + commitLine[i:len(commitLine)] 110 | break 111 | index = commitLine.rfind(' ', i, i+78) 112 | if index > i: 113 | commit = commit + "\n " + commitLine[i:index] 114 | i = index+1 115 | else: 116 | commit = commit + "\n " + commitLine[i:78] 117 | i = i+79 118 | 119 | # Write out the commit line 120 | fout.write(commit + "\n") 121 | 122 | #Now reset all the variables ready for a new commit block. 123 | authorFound = False 124 | dateFound = False 125 | messageFound = False 126 | messageNL = False 127 | message = "" 128 | filesFound = False 129 | files = "" 130 | prevAuthorLine = authorLine 131 | 132 | fout.write("\n\n") 133 | # Close the input and output lines now that we are finished. 134 | fin.close() 135 | fout.close() 136 | 137 | os.system("cat bak.ChangeLog >> ChangeLog") 138 | os.system("rm bak.ChangeLog") 139 | -------------------------------------------------------------------------------- /libevhtp/contrib/make_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mv ChangeLog bak.ChangeLog 4 | 5 | rev_list=`git rev-list --tags --max-count=1..HEAD` 6 | tag_desc=`git describe --tags $rev_list` 7 | cur_desc=`git flow release | awk '{print $2}'` 8 | 9 | echo v$cur_desc > ChangeLog 10 | git log --no-merges --reverse --pretty='format: o %s (%h %an)' $tag_desc..HEAD >> ChangeLog 11 | echo "" >> ChangeLog 12 | echo "" >> ChangeLog 13 | 14 | cat bak.ChangeLog >> ChangeLog 15 | -------------------------------------------------------------------------------- /libevhtp/contrib/perftest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" -ne 5 ] 4 | then 5 | echo "usage " 6 | exit 1 7 | fi 8 | 9 | host=$1 10 | port=$2 11 | uri=$3 12 | conns=$4 13 | calls=$5 14 | 15 | echo "Running ($conns connections | $calls requests each)" 16 | 17 | #httperf --ssl --server=$host --port=$port --uri=$uri --rate=1e+06 --send-buffer=4096 --recv-buffer=16384 --wsess=$conns,$calls,0 18 | #httperf --print-reply header --add-header "Accept-Encoding: gzip,deflate,sdch\n" --server=$host --port=$port --uri=$uri --rate=1e+06 --send-buffer=4096 --recv-buffer=16384 --wsess=$conns,$calls,0 19 | httperf --server=$host --port=$port --uri=$uri --rate=1e+06 --send-buffer=4096 --recv-buffer=16384 --wsess=$conns,$calls,0 20 | -------------------------------------------------------------------------------- /libevhtp/contrib/release_prep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This shouldn't be used by anyone but me...kthx 3 | 4 | rm -rf libhtparse/ 5 | rm -rf evthr/ 6 | rm -rf oniguruma/ 7 | 8 | rm -rf build/libhtparse-latest* 9 | rm -rf build/libevthr-latest* 10 | rm -rf build/oniguruma-latest* 11 | 12 | cd build && wget http://ackers.net/packages/libhtparse-latest.tar http://ackers.net/packages/libevthr-latest.tar http://ackers.net/packages/oniguruma-latest.tar 13 | cd .. 14 | 15 | httparser_dirname=`tar --to-stdout -tf build/libhtparse-latest.tar 2>&1 | head -n 1` 16 | libevthr_dirname=`tar --to-stdout -tf build/libevthr-latest.tar 2>&1 | head -n 1` 17 | oniguruma_dirname=`tar --to-stdout -tf build/oniguruma-latest.tar 2>&1 | head -n 1` 18 | 19 | tar -xf build/libhtparse-latest.tar 20 | tar -xf build/libevthr-latest.tar 21 | tar -xf build/oniguruma-latest.tar 22 | 23 | mv $httparser_dirname libhtparse 24 | mv $libevthr_dirname evthr 25 | mv $oniguruma_dirname oniguruma 26 | 27 | rm -rf build/libhtparse-latest* 28 | rm -rf build/libevthr-latest* 29 | rm -rf build/oniguruma-latest* 30 | -------------------------------------------------------------------------------- /libevhtp/evthr/Makefile: -------------------------------------------------------------------------------- 1 | SRC = evthr.c 2 | OUT = libevthr.a 3 | OBJ = $(SRC:.c=.o) 4 | INCLUDES = -I. 5 | CFLAGS += -Wall -Wextra -ggdb 6 | LDFLAGS += -ggdb 7 | CC = gcc 8 | 9 | .SUFFIXES: .c 10 | 11 | default: $(OUT) 12 | 13 | .c.o: 14 | $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ 15 | 16 | $(OUT): $(OBJ) 17 | ar rcs $(OUT) $(OBJ) 18 | 19 | test: $(OUT) test.c 20 | $(CC) $(INCLUDES) $(CFLAGS) test.c -o test $(OUT) -levent -levent_pthreads -lpthread 21 | 22 | clean: 23 | rm -f $(OBJ) $(OUT) test 24 | 25 | -------------------------------------------------------------------------------- /libevhtp/evthr/README: -------------------------------------------------------------------------------- 1 | Libevthr is an API which manages threads and thread-pools in an event based 2 | manner. This API requires libevent with threading support. 3 | 4 | Libevthr works a bit differently than most thread management systems. Instead of 5 | conditional signalling and some type of pre-thread queue, Libevthr uses a 6 | deferral type mechanism. That is, a thread is always running, abstracted to a 7 | point where you "defer" your function *into* a thread. 8 | 9 | For example you can start up a single thread with a backlog of 10 (a backlog 10 | being the max number of outstanding callbacks to run within the thread), and 11 | execute a function you would like to run inside the thread one or many times. 12 | The act of deferrals is non-blocking. 13 | 14 | Example Code for evthrs: 15 | 16 | evthr_t * thr = evthr_new(10, NULL); 17 | 18 | if (evthr_start(thr) < 0) { 19 | exit(1); 20 | } 21 | 22 | evthr_defer(thr, my_cb_1, NULL); 23 | evthr_defer(thr, my_cb_2, NULL); 24 | evthr_defer(thr, my_cb_3, NULL); 25 | 26 | sleep(n_seconds); 27 | 28 | evthr_stop(thr); 29 | 30 | Libevthr also has the ability to create pools using the same methods that a 31 | single evthr has. For example, if you would like to create 10 threads, each 32 | with a backlog of 5: 33 | 34 | evthr_pool_t * thr_pool = evthr_pool_new(10, 5, NULL); 35 | 36 | if (evthr_pool_start(thr_pool) < 0) { 37 | exit(1); 38 | } 39 | 40 | evthr_pool_defer(thr_pool, my_cb_1, NULL); 41 | evthr_pool_defer(thr_pool, my_cb_2, NULL); 42 | evthr_pool_defer(thr_pool, my_cb_3, NULL); 43 | 44 | Your callback functions which you defer must be of type "evthr_cb", or 45 | "void cb_name(void * arg, void * shared)". In this case, the "arg" variable is 46 | the data you passed as the third argument to either evthr_pool_defer, or 47 | evthr_defer. The "shared" variable is the data that was either the second 48 | variable in evthr_new(), or the third variable in evthr_pool_new(). 49 | 50 | The gist of this is to allow a global dataset, along with deferred specific 51 | data. 52 | 53 | See test.c for a quick example. 54 | -------------------------------------------------------------------------------- /libevhtp/evthr/evthr.h: -------------------------------------------------------------------------------- 1 | #ifndef _GNU_SOURCE 2 | #define _GNU_SOURCE 1 3 | #endif 4 | #ifndef __EVTHR_H__ 5 | #define __EVTHR_H__ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | enum evthr_res { 18 | EVTHR_RES_OK = 0, 19 | EVTHR_RES_BACKLOG, 20 | EVTHR_RES_RETRY, 21 | EVTHR_RES_NOCB, 22 | EVTHR_RES_FATAL 23 | }; 24 | 25 | struct evthr_pool; 26 | struct evthr; 27 | 28 | typedef struct event_base evbase_t; 29 | typedef struct event ev_t; 30 | 31 | typedef struct evthr_pool evthr_pool_t; 32 | typedef struct evthr evthr_t; 33 | typedef enum evthr_res evthr_res; 34 | 35 | typedef void (*evthr_cb)(evthr_t * thr, void * cmd_arg, void * shared); 36 | typedef void (*evthr_init_cb)(evthr_t * thr, void * shared); 37 | 38 | evthr_t * evthr_new(evthr_init_cb init_cb, void * arg); 39 | evbase_t * evthr_get_base(evthr_t * thr); 40 | void evthr_set_aux(evthr_t * thr, void * aux); 41 | void * evthr_get_aux(evthr_t * thr); 42 | int evthr_start(evthr_t * evthr); 43 | evthr_res evthr_stop(evthr_t * evthr); 44 | evthr_res evthr_defer(evthr_t * evthr, evthr_cb cb, void * arg); 45 | void evthr_free(evthr_t * evthr); 46 | void evthr_inc_backlog(evthr_t * evthr); 47 | void evthr_dec_backlog(evthr_t * evthr); 48 | int evthr_get_backlog(evthr_t * evthr); 49 | void evthr_set_max_backlog(evthr_t * evthr, int max); 50 | 51 | evthr_pool_t * evthr_pool_new(int nthreads, evthr_init_cb init_cb, void * shared); 52 | int evthr_pool_start(evthr_pool_t * pool); 53 | evthr_res evthr_pool_stop(evthr_pool_t * pool); 54 | evthr_res evthr_pool_defer(evthr_pool_t * pool, evthr_cb cb, void * arg); 55 | void evthr_pool_free(evthr_pool_t * pool); 56 | void evthr_pool_set_max_backlog(evthr_pool_t * evthr, int max); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* __EVTHR_H__ */ 63 | 64 | -------------------------------------------------------------------------------- /libevhtp/evthr/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void 10 | _test_cb_1(evthr_t * thr, void * cmdarg, void * shared) { 11 | printf("START _test_cb_1 (%u)\n", (unsigned int)pthread_self()); 12 | sleep(1); 13 | printf("END _test_cb_1 (%u)\n", (unsigned int)pthread_self()); 14 | } 15 | 16 | int 17 | main(int argc, char ** argv) { 18 | evthr_pool_t * pool = NULL; 19 | int i = 0; 20 | 21 | pool = evthr_pool_new(8, NULL, NULL); 22 | 23 | evthr_pool_start(pool); 24 | 25 | while (1) { 26 | if (i++ >= 5) { 27 | break; 28 | } 29 | 30 | printf("Iter %d\n", i); 31 | 32 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 33 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 34 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 35 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 36 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 37 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 38 | 39 | sleep(2); 40 | } 41 | 42 | evthr_pool_stop(pool); 43 | evthr_pool_free(pool); 44 | 45 | pool = evthr_pool_new(2, NULL, NULL); 46 | i = 0; 47 | 48 | evthr_pool_set_max_backlog(pool, 1); 49 | evthr_pool_start(pool); 50 | 51 | while (1) { 52 | if (i++ >= 5) { 53 | break; 54 | } 55 | 56 | printf("Iter %d\n", i); 57 | 58 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 59 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 60 | printf("%d\n", evthr_pool_defer(pool, _test_cb_1, "derp")); 61 | } 62 | 63 | evthr_pool_stop(pool); 64 | evthr_pool_free(pool); 65 | 66 | return 0; 67 | } /* main */ 68 | 69 | -------------------------------------------------------------------------------- /libevhtp/htparse/Makefile: -------------------------------------------------------------------------------- 1 | SRC = htparse.c 2 | OUT = libhtparse.a 3 | OBJ = $(SRC:.c=.o) 4 | INCLUDES = -I. 5 | CFLAGS += -ggdb -Wall -Wextra 6 | LDFLAGS += 7 | CC = gcc 8 | 9 | .SUFFIXES: .c 10 | 11 | default: $(OUT) 12 | 13 | .c.o: 14 | $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@ 15 | 16 | $(OUT): $(OBJ) 17 | ar rcs $(OUT) $(OBJ) 18 | 19 | test: $(OUT) test.c 20 | $(CC) $(INCLUDES) $(CFLAGS) test.c -o test $(OUT) 21 | 22 | overflow: $(OUT) overflow.c 23 | $(CC) $(INCLUDES) $(CFLAGS) overflow.c -o overflow $(OUT) 24 | 25 | clean: 26 | rm -f $(OBJ) $(OUT) test 27 | -------------------------------------------------------------------------------- /libevhtp/htparse/htparse.h: -------------------------------------------------------------------------------- 1 | #ifndef __HTPARSE_H__ 2 | #define __HTPARSE_H__ 3 | 4 | struct htparser; 5 | 6 | enum htp_type { 7 | htp_type_request = 0, 8 | htp_type_response 9 | }; 10 | 11 | enum htp_scheme { 12 | htp_scheme_none = 0, 13 | htp_scheme_ftp, 14 | htp_scheme_http, 15 | htp_scheme_https, 16 | htp_scheme_nfs, 17 | htp_scheme_unknown 18 | }; 19 | 20 | enum htp_method { 21 | htp_method_GET = 0, 22 | htp_method_HEAD, 23 | htp_method_POST, 24 | htp_method_PUT, 25 | htp_method_DELETE, 26 | htp_method_MKCOL, 27 | htp_method_COPY, 28 | htp_method_MOVE, 29 | htp_method_OPTIONS, 30 | htp_method_PROPFIND, 31 | htp_method_PROPPATCH, 32 | htp_method_LOCK, 33 | htp_method_UNLOCK, 34 | htp_method_TRACE, 35 | htp_method_UNKNOWN 36 | }; 37 | 38 | enum htpparse_error { 39 | htparse_error_none = 0, 40 | htparse_error_too_big, 41 | htparse_error_inval_method, 42 | htparse_error_inval_reqline, 43 | htparse_error_inval_schema, 44 | htparse_error_inval_proto, 45 | htparse_error_inval_ver, 46 | htparse_error_inval_hdr, 47 | htparse_error_inval_chunk_sz, 48 | htparse_error_inval_chunk, 49 | htparse_error_inval_state, 50 | htparse_error_user, 51 | htparse_error_status, 52 | htparse_error_generic 53 | }; 54 | 55 | typedef struct htparser htparser; 56 | typedef struct htparse_hooks htparse_hooks; 57 | 58 | typedef enum htp_scheme htp_scheme; 59 | typedef enum htp_method htp_method; 60 | typedef enum htp_type htp_type; 61 | typedef enum htpparse_error htpparse_error; 62 | 63 | typedef int (*htparse_hook)(htparser *); 64 | typedef int (*htparse_data_hook)(htparser *, const char *, size_t); 65 | 66 | 67 | struct htparse_hooks { 68 | htparse_hook on_msg_begin; 69 | htparse_data_hook method; 70 | htparse_data_hook scheme; /* called if scheme is found */ 71 | htparse_data_hook host; /* called if a host was in the request scheme */ 72 | htparse_data_hook port; /* called if a port was in the request scheme */ 73 | htparse_data_hook path; /* only the path of the uri */ 74 | htparse_data_hook args; /* only the arguments of the uri */ 75 | htparse_data_hook uri; /* the entire uri including path/args */ 76 | htparse_hook on_hdrs_begin; 77 | htparse_data_hook hdr_key; 78 | htparse_data_hook hdr_val; 79 | htparse_data_hook hostname; 80 | htparse_hook on_hdrs_complete; 81 | htparse_hook on_new_chunk; /* called after parsed chunk octet */ 82 | htparse_hook on_chunk_complete; /* called after single parsed chunk */ 83 | htparse_hook on_chunks_complete; /* called after all parsed chunks processed */ 84 | htparse_data_hook body; 85 | htparse_hook on_msg_complete; 86 | }; 87 | 88 | 89 | size_t htparser_run(htparser *, htparse_hooks *, const char *, size_t); 90 | int htparser_should_keep_alive(htparser * p); 91 | htp_scheme htparser_get_scheme(htparser *); 92 | htp_method htparser_get_method(htparser *); 93 | const char * htparser_get_methodstr(htparser *); 94 | void htparser_set_major(htparser *, unsigned char); 95 | void htparser_set_minor(htparser *, unsigned char); 96 | unsigned char htparser_get_major(htparser *); 97 | unsigned char htparser_get_minor(htparser *); 98 | unsigned char htparser_get_multipart(htparser *); 99 | unsigned int htparser_get_status(htparser *); 100 | uint64_t htparser_get_content_length(htparser *); 101 | uint64_t htparser_get_total_bytes_read(htparser *); 102 | htpparse_error htparser_get_error(htparser *); 103 | const char * htparser_get_strerror(htparser *); 104 | void * htparser_get_userdata(htparser *); 105 | void htparser_set_userdata(htparser *, void *); 106 | void htparser_init(htparser *, htp_type); 107 | htparser * htparser_new(void); 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/AUTHORS: -------------------------------------------------------------------------------- 1 | sndgk393 AT ybb DOT ne DOT jp (K.Kosako) 2 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 2 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 3 | 4 | INCLUDE (CheckFunctionExists) 5 | INCLUDE (CheckIncludeFiles) 6 | INCLUDE (CheckTypeSize) 7 | 8 | CHECK_FUNCTION_EXISTS(alloca C_ALLOCA) 9 | CHECK_FUNCTION_EXISTS(memcmp HAVE_MEMCMP) 10 | 11 | CHECK_INCLUDE_FILES(alloca.h HAVE_ALLOCA_H) 12 | CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H) 13 | CHECK_INCLUDE_FILES(string.h HAVE_STRING_H) 14 | CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H) 15 | CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H) 16 | CHECK_INCLUDE_FILES(sys/times.h HAVE_SYS_TIMES_H) 17 | CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H) 18 | CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H) 19 | CHECK_INCLUDE_FILES(stdarg.h HAVE_STDARG_PROTOTYPES) 20 | 21 | CHECK_TYPE_SIZE("int" SIZEOF_INT) 22 | CHECK_TYPE_SIZE("long" SIZEOF_LONG) 23 | CHECK_TYPE_SIZE("short" SIZEOF_SHORT) 24 | 25 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) 26 | 27 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 28 | 29 | set(SOURCES regint.h regparse.h regenc.h st.h 30 | regerror.c regparse.c regext.c regcomp.c regexec.c reggnu.c 31 | regenc.c regsyntax.c regtrav.c regversion.c st.c 32 | regposix.c regposerr.c 33 | enc/unicode.c enc/ascii.c enc/utf8.c 34 | enc/utf16_be.c enc/utf16_le.c 35 | enc/utf32_be.c enc/utf32_le.c 36 | enc/euc_jp.c enc/sjis.c enc/iso8859_1.c 37 | enc/iso8859_2.c enc/iso8859_3.c 38 | enc/iso8859_4.c enc/iso8859_5.c 39 | enc/iso8859_6.c enc/iso8859_7.c 40 | enc/iso8859_8.c enc/iso8859_9.c 41 | enc/iso8859_10.c enc/iso8859_11.c 42 | enc/iso8859_13.c enc/iso8859_14.c 43 | enc/iso8859_15.c enc/iso8859_16.c 44 | enc/euc_tw.c enc/euc_kr.c enc/big5.c 45 | enc/gb18030.c enc/koi8_r.c enc/cp1251.c) 46 | 47 | 48 | add_library(libonig STATIC ${SOURCES}) 49 | set_target_properties(libonig PROPERTIES OUTPUT_NAME "libonig") 50 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/COPYING: -------------------------------------------------------------------------------- 1 | Oniguruma LICENSE 2 | ----------------- 3 | 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Makefile.am for Oniguruma 2 | encdir = $(top_srcdir)/enc 3 | sampledir = $(top_srcdir)/sample 4 | libname = libonig.la 5 | 6 | #AM_CFLAGS = -DNOT_RUBY 7 | AM_CFLAGS = 8 | INCLUDES = -I$(top_srcdir) -I$(includedir) 9 | 10 | SUBDIRS = . sample 11 | 12 | include_HEADERS = oniguruma.h oniggnu.h onigposix.h 13 | lib_LTLIBRARIES = $(libname) 14 | 15 | libonig_la_SOURCES = regint.h regparse.h regenc.h st.h \ 16 | regerror.c regparse.c regext.c regcomp.c regexec.c reggnu.c \ 17 | regenc.c regsyntax.c regtrav.c regversion.c st.c \ 18 | regposix.c regposerr.c \ 19 | $(encdir)/unicode.c $(encdir)/ascii.c $(encdir)/utf8.c \ 20 | $(encdir)/utf16_be.c $(encdir)/utf16_le.c \ 21 | $(encdir)/utf32_be.c $(encdir)/utf32_le.c \ 22 | $(encdir)/euc_jp.c $(encdir)/sjis.c $(encdir)/iso8859_1.c \ 23 | $(encdir)/iso8859_2.c $(encdir)/iso8859_3.c \ 24 | $(encdir)/iso8859_4.c $(encdir)/iso8859_5.c \ 25 | $(encdir)/iso8859_6.c $(encdir)/iso8859_7.c \ 26 | $(encdir)/iso8859_8.c $(encdir)/iso8859_9.c \ 27 | $(encdir)/iso8859_10.c $(encdir)/iso8859_11.c \ 28 | $(encdir)/iso8859_13.c $(encdir)/iso8859_14.c \ 29 | $(encdir)/iso8859_15.c $(encdir)/iso8859_16.c \ 30 | $(encdir)/euc_tw.c $(encdir)/euc_kr.c $(encdir)/big5.c \ 31 | $(encdir)/gb18030.c $(encdir)/koi8_r.c $(encdir)/cp1251.c 32 | 33 | libonig_la_LDFLAGS = -version-info $(LTVERSION) 34 | 35 | EXTRA_DIST = HISTORY README.ja index.html index_ja.html \ 36 | doc/API doc/API.ja doc/RE doc/RE.ja doc/FAQ doc/FAQ.ja \ 37 | win32/Makefile win32/config.h win32/testc.c \ 38 | $(encdir)/koi8.c $(encdir)/mktable.c \ 39 | $(sampledir)/encode.c $(sampledir)/listcap.c $(sampledir)/names.c \ 40 | $(sampledir)/posix.c $(sampledir)/simple.c $(sampledir)/sql.c \ 41 | $(sampledir)/syntax.c 42 | 43 | bin_SCRIPTS = onig-config 44 | 45 | onig-config: onig-config.in 46 | 47 | dll: 48 | $(CXX) -shared -Wl,--output-def,libonig.def -o libonig.dll *.o \ 49 | $(LIBS) 50 | strip libonig.dll 51 | 52 | # Ruby TEST 53 | rtest: 54 | $(RUBYDIR)/ruby -w -Ke $(srcdir)/test.rb 55 | 56 | # character-types-table source generator 57 | mktable: $(encdir)/mktable.c $(srcdir)/regenc.h 58 | $(CC) -I$(top_srcdir) -o mktable $(encdir)/mktable.c 59 | 60 | 61 | # TEST 62 | TESTS = testc testp testcu 63 | 64 | check_PROGRAMS = testc testp testcu 65 | 66 | atest: testc testp testcu 67 | @echo "[Oniguruma API, ASCII/EUC-JP check]" 68 | @$(top_builddir)/testc | grep RESULT 69 | @echo "[POSIX API, ASCII/EUC-JP check]" 70 | @$(top_builddir)/testp | grep RESULT 71 | @echo "[Oniguruma API, UTF-16 check]" 72 | @$(top_builddir)/testcu | grep RESULT 73 | 74 | testc_SOURCES = testc.c 75 | testc_LDADD = libonig.la 76 | 77 | testp_SOURCES = testc.c 78 | testp_LDADD = libonig.la 79 | testp_CFLAGS = -DPOSIX_TEST 80 | 81 | testcu_SOURCES = testu.c 82 | testcu_LDADD = libonig.la 83 | 84 | 85 | #testc.c: $(srcdir)/test.rb $(srcdir)/testconv.rb 86 | # ruby -Ke $(srcdir)/testconv.rb < $(srcdir)/test.rb > $@ 87 | 88 | #testu.c: $(srcdir)/test.rb $(srcdir)/testconvu.rb 89 | # ruby -Ke $(srcdir)/testconvu.rb $(srcdir)/test.rb > $@ 90 | 91 | #win32/testc.c: $(srcdir)/test.rb $(srcdir)/testconv.rb 92 | # ruby -Ke $(srcdir)/testconv.rb -win < $(srcdir)/test.rb | nkf -cs > $@ 93 | 94 | ## END OF FILE 95 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/README: -------------------------------------------------------------------------------- 1 | README 2007/05/31 2 | 3 | Oniguruma ---- (C) K.Kosako 4 | 5 | http://www.geocities.jp/kosako3/oniguruma/ 6 | 7 | Oniguruma is a regular expressions library. 8 | The characteristics of this library is that different character encoding 9 | for every regular expression object can be specified. 10 | 11 | Supported character encodings: 12 | 13 | ASCII, UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE, 14 | EUC-JP, EUC-TW, EUC-KR, EUC-CN, 15 | Shift_JIS, Big5, GB18030, KOI8-R, CP1251, 16 | ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, 17 | ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-10, 18 | ISO-8859-11, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16 19 | 20 | * GB18030: contributed by KUBO Takehiro 21 | * CP1251: contributed by Byte 22 | ------------------------------------------------------------ 23 | 24 | License 25 | 26 | BSD license. 27 | 28 | 29 | Install 30 | 31 | Case 1: Unix and Cygwin platform 32 | 33 | 1. ./configure 34 | 2. make 35 | 3. make install 36 | 37 | * uninstall 38 | 39 | make uninstall 40 | 41 | * test (ASCII/EUC-JP) 42 | 43 | make atest 44 | 45 | * configuration check 46 | 47 | onig-config --cflags 48 | onig-config --libs 49 | onig-config --prefix 50 | onig-config --exec-prefix 51 | 52 | 53 | 54 | Case 2: Win32 platform (VC++) 55 | 56 | 1. copy win32\Makefile Makefile 57 | 2. copy win32\config.h config.h 58 | 3. nmake 59 | 60 | onig_s.lib: static link library 61 | onig.dll: dynamic link library 62 | 63 | * test (ASCII/Shift_JIS) 64 | 4. copy win32\testc.c testc.c 65 | 5. nmake ctest 66 | 67 | 68 | 69 | Regular Expressions 70 | 71 | See doc/RE (or doc/RE.ja for Japanese). 72 | 73 | 74 | Usage 75 | 76 | Include oniguruma.h in your program. (Oniguruma API) 77 | See doc/API for Oniguruma API. 78 | 79 | If you want to disable UChar type (== unsigned char) definition 80 | in oniguruma.h, define ONIG_ESCAPE_UCHAR_COLLISION and then 81 | include oniguruma.h. 82 | 83 | If you want to disable regex_t type definition in oniguruma.h, 84 | define ONIG_ESCAPE_REGEX_T_COLLISION and then include oniguruma.h. 85 | 86 | Example of the compiling/linking command line in Unix or Cygwin, 87 | (prefix == /usr/local case) 88 | 89 | cc sample.c -L/usr/local/lib -lonig 90 | 91 | 92 | If you want to use static link library(onig_s.lib) in Win32, 93 | add option -DONIG_EXTERN=extern to C compiler. 94 | 95 | 96 | 97 | Sample Programs 98 | 99 | sample/simple.c example of the minimum (Oniguruma API) 100 | sample/names.c example of the named group callback. 101 | sample/encode.c example of some encodings. 102 | sample/listcap.c example of the capture history. 103 | sample/posix.c POSIX API sample. 104 | sample/sql.c example of the variable meta characters. 105 | (SQL-like pattern matching) 106 | 107 | Test Programs 108 | sample/syntax.c Perl, Java and ASIS syntax test. 109 | sample/crnl.c --enable-crnl-as-line-terminator test 110 | 111 | 112 | Source Files 113 | 114 | oniguruma.h Oniguruma API header file. (public) 115 | onig-config.in configuration check program template. 116 | 117 | regenc.h character encodings framework header file. 118 | regint.h internal definitions 119 | regparse.h internal definitions for regparse.c and regcomp.c 120 | regcomp.c compiling and optimization functions 121 | regenc.c character encodings framework. 122 | regerror.c error message function 123 | regext.c extended API functions. (deluxe version API) 124 | regexec.c search and match functions 125 | regparse.c parsing functions. 126 | regsyntax.c pattern syntax functions and built-in syntax definitions. 127 | regtrav.c capture history tree data traverse functions. 128 | regversion.c version info function. 129 | st.h hash table functions header file 130 | st.c hash table functions 131 | 132 | oniggnu.h GNU regex API header file. (public) 133 | reggnu.c GNU regex API functions 134 | 135 | onigposix.h POSIX API header file. (public) 136 | regposerr.c POSIX error message function. 137 | regposix.c POSIX API functions. 138 | 139 | enc/mktable.c character type table generator. 140 | enc/ascii.c ASCII encoding. 141 | enc/euc_jp.c EUC-JP encoding. 142 | enc/euc_tw.c EUC-TW encoding. 143 | enc/euc_kr.c EUC-KR, EUC-CN encoding. 144 | enc/sjis.c Shift_JIS encoding. 145 | enc/big5.c Big5 encoding. 146 | enc/gb18030.c GB18030 encoding. 147 | enc/koi8.c KOI8 encoding. 148 | enc/koi8_r.c KOI8-R encoding. 149 | enc/cp1251.c CP1251 encoding. 150 | enc/iso8859_1.c ISO-8859-1 encoding. (Latin-1) 151 | enc/iso8859_2.c ISO-8859-2 encoding. (Latin-2) 152 | enc/iso8859_3.c ISO-8859-3 encoding. (Latin-3) 153 | enc/iso8859_4.c ISO-8859-4 encoding. (Latin-4) 154 | enc/iso8859_5.c ISO-8859-5 encoding. (Cyrillic) 155 | enc/iso8859_6.c ISO-8859-6 encoding. (Arabic) 156 | enc/iso8859_7.c ISO-8859-7 encoding. (Greek) 157 | enc/iso8859_8.c ISO-8859-8 encoding. (Hebrew) 158 | enc/iso8859_9.c ISO-8859-9 encoding. (Latin-5 or Turkish) 159 | enc/iso8859_10.c ISO-8859-10 encoding. (Latin-6 or Nordic) 160 | enc/iso8859_11.c ISO-8859-11 encoding. (Thai) 161 | enc/iso8859_13.c ISO-8859-13 encoding. (Latin-7 or Baltic Rim) 162 | enc/iso8859_14.c ISO-8859-14 encoding. (Latin-8 or Celtic) 163 | enc/iso8859_15.c ISO-8859-15 encoding. (Latin-9 or West European with Euro) 164 | enc/iso8859_16.c ISO-8859-16 encoding. 165 | (Latin-10 or South-Eastern European with Euro) 166 | enc/utf8.c UTF-8 encoding. 167 | enc/utf16_be.c UTF-16BE encoding. 168 | enc/utf16_le.c UTF-16LE encoding. 169 | enc/utf32_be.c UTF-32BE encoding. 170 | enc/utf32_le.c UTF-32LE encoding. 171 | enc/unicode.c Unicode information data. 172 | 173 | win32/Makefile Makefile for Win32 (VC++) 174 | win32/config.h config.h for Win32 175 | 176 | 177 | 178 | ToDo 179 | 180 | ? case fold flag: Katakana <-> Hiragana. 181 | ? add ONIG_OPTION_NOTBOS/NOTEOS. (\A, \z, \Z) 182 | ?? \X (== \PM\pM*) 183 | ?? implement syntax behavior ONIG_SYN_CONTEXT_INDEP_ANCHORS. 184 | ?? transmission stopper. (return ONIG_STOP from match_at()) 185 | 186 | and I'm thankful to Akinori MUSHA. 187 | 188 | 189 | Mail Address: K.Kosako 190 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/README.ja: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forhappy/tinydb/26e382fc11ba3c273ef49b56d38c92732beb674d/libevhtp/oniguruma/README.ja -------------------------------------------------------------------------------- /libevhtp/oniguruma/config.h.in: -------------------------------------------------------------------------------- 1 | #cmakedefine CRAY_STACKSEG_END 1 2 | #cmakedefine C_ALLOCA 1 3 | #cmakedefine HAVE_ALLOCA 1 4 | #cmakedefine HAVE_ALLOCA_H 1 5 | #cmakedefine HAVE_DLFCN_H 1 6 | #cmakedefine HAVE_INTTYPES_H 1 7 | #cmakedefine HAVE_MEMORY_H 1 8 | #cmakedefine HAVE_PROTOTYPES 1 9 | #cmakedefine HAVE_STDARG_PROTOTYPES 1 10 | #cmakedefine HAVE_STDINT_H 1 11 | #cmakedefine HAVE_STDLIB_H 1 12 | #cmakedefine HAVE_STRINGS_H 1 13 | #cmakedefine HAVE_STRING_H 1 14 | #cmakedefine HAVE_SYS_STAT_H 1 15 | #cmakedefine HAVE_SYS_TIMES_H 1 16 | #cmakedefine HAVE_SYS_TIME_H 1 17 | #cmakedefine HAVE_SYS_TYPES_H 1 18 | #cmakedefine HAVE_UNISTD_H 1 19 | #cmakedefine LT_OBJDIR 1 20 | #cmakedefine PACKAGE 1 21 | #cmakedefine PACKAGE_BUGREPORT 1 22 | #cmakedefine PACKAGE_NAME 1 23 | #cmakedefine PACKAGE_STRING 1 24 | #cmakedefine PACKAGE_TARNAME 1 25 | #cmakedefine PACKAGE_VERSION 1 26 | #cmakedefine SIZEOF_INT 1 27 | #cmakedefine SIZEOF_LONG 1 28 | #cmakedefine SIZEOF_SHORT 1 29 | #cmakedefine STACK_DIRECTION 1 30 | #cmakedefine STDC_HEADERS 1 31 | #cmakedefine TIME_WITH_SYS_TIME 1 32 | #cmakedefine USE_COMBINATION_EXPLOSION_CHECK 1 33 | #cmakedefine USE_CRNL_AS_LINE_TERMINATOR 1 34 | #cmakedefine VERSION 1 35 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/ascii.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | ascii.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2006 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static int 33 | ascii_is_code_ctype(OnigCodePoint code, unsigned int ctype) 34 | { 35 | if (code < 128) 36 | return ONIGENC_IS_ASCII_CODE_CTYPE(code, ctype); 37 | else 38 | return FALSE; 39 | } 40 | 41 | OnigEncodingType OnigEncodingASCII = { 42 | onigenc_single_byte_mbc_enc_len, 43 | "US-ASCII", /* name */ 44 | 1, /* max byte length */ 45 | 1, /* min byte length */ 46 | onigenc_is_mbc_newline_0x0a, 47 | onigenc_single_byte_mbc_to_code, 48 | onigenc_single_byte_code_to_mbclen, 49 | onigenc_single_byte_code_to_mbc, 50 | onigenc_ascii_mbc_case_fold, 51 | onigenc_ascii_apply_all_case_fold, 52 | onigenc_ascii_get_case_fold_codes_by_str, 53 | onigenc_minimum_property_name_to_ctype, 54 | ascii_is_code_ctype, 55 | onigenc_not_support_get_ctype_code_range, 56 | onigenc_single_byte_left_adjust_char_head, 57 | onigenc_always_true_is_allowed_reverse_match 58 | }; 59 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/big5.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | big5.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static const int EncLen_BIG5[] = { 33 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 34 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 35 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 36 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 38 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 39 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 40 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 41 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 42 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 43 | 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 44 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 45 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 46 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 47 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 48 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 49 | }; 50 | 51 | static int 52 | big5_mbc_enc_len(const UChar* p) 53 | { 54 | return EncLen_BIG5[*p]; 55 | } 56 | 57 | static OnigCodePoint 58 | big5_mbc_to_code(const UChar* p, const UChar* end) 59 | { 60 | return onigenc_mbn_mbc_to_code(ONIG_ENCODING_BIG5, p, end); 61 | } 62 | 63 | static int 64 | big5_code_to_mbc(OnigCodePoint code, UChar *buf) 65 | { 66 | return onigenc_mb2_code_to_mbc(ONIG_ENCODING_BIG5, code, buf); 67 | } 68 | 69 | static int 70 | big5_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end, 71 | UChar* lower) 72 | { 73 | return onigenc_mbn_mbc_case_fold(ONIG_ENCODING_BIG5, flag, 74 | pp, end, lower); 75 | } 76 | 77 | #if 0 78 | static int 79 | big5_is_mbc_ambiguous(OnigCaseFoldType flag, 80 | const UChar** pp, const UChar* end) 81 | { 82 | return onigenc_mbn_is_mbc_ambiguous(ONIG_ENCODING_BIG5, flag, pp, end); 83 | } 84 | #endif 85 | 86 | static int 87 | big5_is_code_ctype(OnigCodePoint code, unsigned int ctype) 88 | { 89 | return onigenc_mb2_is_code_ctype(ONIG_ENCODING_BIG5, code, ctype); 90 | } 91 | 92 | static const char BIG5_CAN_BE_TRAIL_TABLE[256] = { 93 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 94 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 98 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 99 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 101 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 102 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 103 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 104 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 105 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 106 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 107 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 108 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 109 | }; 110 | 111 | #define BIG5_ISMB_FIRST(byte) (EncLen_BIG5[byte] > 1) 112 | #define BIG5_ISMB_TRAIL(byte) BIG5_CAN_BE_TRAIL_TABLE[(byte)] 113 | 114 | static UChar* 115 | big5_left_adjust_char_head(const UChar* start, const UChar* s) 116 | { 117 | const UChar *p; 118 | int len; 119 | 120 | if (s <= start) return (UChar* )s; 121 | p = s; 122 | 123 | if (BIG5_ISMB_TRAIL(*p)) { 124 | while (p > start) { 125 | if (! BIG5_ISMB_FIRST(*--p)) { 126 | p++; 127 | break; 128 | } 129 | } 130 | } 131 | len = enclen(ONIG_ENCODING_BIG5, p); 132 | if (p + len > s) return (UChar* )p; 133 | p += len; 134 | return (UChar* )(p + ((s - p) & ~1)); 135 | } 136 | 137 | static int 138 | big5_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED) 139 | { 140 | const UChar c = *s; 141 | 142 | return (BIG5_ISMB_TRAIL(c) ? FALSE : TRUE); 143 | } 144 | 145 | OnigEncodingType OnigEncodingBIG5 = { 146 | big5_mbc_enc_len, 147 | "Big5", /* name */ 148 | 2, /* max enc length */ 149 | 1, /* min enc length */ 150 | onigenc_is_mbc_newline_0x0a, 151 | big5_mbc_to_code, 152 | onigenc_mb2_code_to_mbclen, 153 | big5_code_to_mbc, 154 | big5_mbc_case_fold, 155 | onigenc_ascii_apply_all_case_fold, 156 | onigenc_ascii_get_case_fold_codes_by_str, 157 | onigenc_minimum_property_name_to_ctype, 158 | big5_is_code_ctype, 159 | onigenc_not_support_get_ctype_code_range, 160 | big5_left_adjust_char_head, 161 | big5_is_allowed_reverse_match 162 | }; 163 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/euc_kr.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | euc_kr.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static const int EncLen_EUCKR[] = { 33 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 34 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 35 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 36 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 38 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 39 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 40 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 41 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 42 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 43 | 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 44 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 45 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 46 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 47 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 48 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 49 | }; 50 | 51 | static int 52 | euckr_mbc_enc_len(const UChar* p) 53 | { 54 | return EncLen_EUCKR[*p]; 55 | } 56 | 57 | static OnigCodePoint 58 | euckr_mbc_to_code(const UChar* p, const UChar* end) 59 | { 60 | return onigenc_mbn_mbc_to_code(ONIG_ENCODING_EUC_KR, p, end); 61 | } 62 | 63 | static int 64 | euckr_code_to_mbc(OnigCodePoint code, UChar *buf) 65 | { 66 | return onigenc_mb2_code_to_mbc(ONIG_ENCODING_EUC_KR, code, buf); 67 | } 68 | 69 | static int 70 | euckr_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end, 71 | UChar* lower) 72 | { 73 | return onigenc_mbn_mbc_case_fold(ONIG_ENCODING_EUC_KR, flag, 74 | pp, end, lower); 75 | } 76 | 77 | #if 0 78 | static int 79 | euckr_is_mbc_ambiguous(OnigCaseFoldType flag, 80 | const UChar** pp, const UChar* end) 81 | { 82 | return onigenc_mbn_is_mbc_ambiguous(ONIG_ENCODING_EUC_KR, flag, pp, end); 83 | } 84 | #endif 85 | 86 | static int 87 | euckr_is_code_ctype(OnigCodePoint code, unsigned int ctype) 88 | { 89 | return onigenc_mb2_is_code_ctype(ONIG_ENCODING_EUC_KR, code, ctype); 90 | } 91 | 92 | #define euckr_islead(c) ((c) < 0xa1 || (c) == 0xff) 93 | 94 | static UChar* 95 | euckr_left_adjust_char_head(const UChar* start, const UChar* s) 96 | { 97 | /* Assumed in this encoding, 98 | mb-trail bytes don't mix with single bytes. 99 | */ 100 | const UChar *p; 101 | int len; 102 | 103 | if (s <= start) return (UChar* )s; 104 | p = s; 105 | 106 | while (!euckr_islead(*p) && p > start) p--; 107 | len = enclen(ONIG_ENCODING_EUC_KR, p); 108 | if (p + len > s) return (UChar* )p; 109 | p += len; 110 | return (UChar* )(p + ((s - p) & ~1)); 111 | } 112 | 113 | static int 114 | euckr_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED) 115 | { 116 | const UChar c = *s; 117 | if (c <= 0x7e) return TRUE; 118 | else return FALSE; 119 | } 120 | 121 | OnigEncodingType OnigEncodingEUC_KR = { 122 | euckr_mbc_enc_len, 123 | "EUC-KR", /* name */ 124 | 2, /* max enc length */ 125 | 1, /* min enc length */ 126 | onigenc_is_mbc_newline_0x0a, 127 | euckr_mbc_to_code, 128 | onigenc_mb2_code_to_mbclen, 129 | euckr_code_to_mbc, 130 | euckr_mbc_case_fold, 131 | onigenc_ascii_apply_all_case_fold, 132 | onigenc_ascii_get_case_fold_codes_by_str, 133 | onigenc_minimum_property_name_to_ctype, 134 | euckr_is_code_ctype, 135 | onigenc_not_support_get_ctype_code_range, 136 | euckr_left_adjust_char_head, 137 | euckr_is_allowed_reverse_match 138 | }; 139 | 140 | /* Same with OnigEncodingEUC_KR except the name */ 141 | OnigEncodingType OnigEncodingEUC_CN = { 142 | euckr_mbc_enc_len, 143 | "EUC-CN", /* name */ 144 | 2, /* max enc length */ 145 | 1, /* min enc length */ 146 | onigenc_is_mbc_newline_0x0a, 147 | euckr_mbc_to_code, 148 | onigenc_mb2_code_to_mbclen, 149 | euckr_code_to_mbc, 150 | euckr_mbc_case_fold, 151 | onigenc_ascii_apply_all_case_fold, 152 | onigenc_ascii_get_case_fold_codes_by_str, 153 | onigenc_minimum_property_name_to_ctype, 154 | euckr_is_code_ctype, 155 | onigenc_not_support_get_ctype_code_range, 156 | euckr_left_adjust_char_head, 157 | euckr_is_allowed_reverse_match 158 | }; 159 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/euc_tw.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | euc_tw.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2008 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static const int EncLen_EUCTW[] = { 33 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 34 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 35 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 36 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 38 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 39 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 40 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 41 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 42 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 43 | 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 44 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 45 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 46 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 47 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 48 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1 49 | }; 50 | 51 | static int 52 | euctw_mbc_enc_len(const UChar* p) 53 | { 54 | return EncLen_EUCTW[*p]; 55 | } 56 | 57 | static OnigCodePoint 58 | euctw_mbc_to_code(const UChar* p, const UChar* end) 59 | { 60 | return onigenc_mbn_mbc_to_code(ONIG_ENCODING_EUC_TW, p, end); 61 | } 62 | 63 | static int 64 | euctw_code_to_mbc(OnigCodePoint code, UChar *buf) 65 | { 66 | return onigenc_mb4_code_to_mbc(ONIG_ENCODING_EUC_TW, code, buf); 67 | } 68 | 69 | static int 70 | euctw_mbc_case_fold(OnigCaseFoldType flag, const UChar** pp, const UChar* end, 71 | UChar* lower) 72 | { 73 | return onigenc_mbn_mbc_case_fold(ONIG_ENCODING_EUC_TW, flag, 74 | pp, end, lower); 75 | } 76 | 77 | static int 78 | euctw_is_code_ctype(OnigCodePoint code, unsigned int ctype) 79 | { 80 | return onigenc_mb4_is_code_ctype(ONIG_ENCODING_EUC_TW, code, ctype); 81 | } 82 | 83 | #define euctw_islead(c) ((UChar )((c) - 0xa1) > 0xfe - 0xa1) 84 | 85 | static UChar* 86 | euctw_left_adjust_char_head(const UChar* start, const UChar* s) 87 | { 88 | /* Assumed in this encoding, 89 | mb-trail bytes don't mix with single bytes. 90 | */ 91 | const UChar *p; 92 | int len; 93 | 94 | if (s <= start) return (UChar* )s; 95 | p = s; 96 | 97 | while (!euctw_islead(*p) && p > start) p--; 98 | len = enclen(ONIG_ENCODING_EUC_TW, p); 99 | if (p + len > s) return (UChar* )p; 100 | p += len; 101 | return (UChar* )(p + ((s - p) & ~1)); 102 | } 103 | 104 | static int 105 | euctw_is_allowed_reverse_match(const UChar* s, const UChar* end ARG_UNUSED) 106 | { 107 | const UChar c = *s; 108 | if (c <= 0x7e) return TRUE; 109 | else return FALSE; 110 | } 111 | 112 | OnigEncodingType OnigEncodingEUC_TW = { 113 | euctw_mbc_enc_len, 114 | "EUC-TW", /* name */ 115 | 4, /* max enc length */ 116 | 1, /* min enc length */ 117 | onigenc_is_mbc_newline_0x0a, 118 | euctw_mbc_to_code, 119 | onigenc_mb4_code_to_mbclen, 120 | euctw_code_to_mbc, 121 | euctw_mbc_case_fold, 122 | onigenc_ascii_apply_all_case_fold, 123 | onigenc_ascii_get_case_fold_codes_by_str, 124 | onigenc_minimum_property_name_to_ctype, 125 | euctw_is_code_ctype, 126 | onigenc_not_support_get_ctype_code_range, 127 | euctw_left_adjust_char_head, 128 | euctw_is_allowed_reverse_match 129 | }; 130 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/iso8859_11.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | iso8859_11.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | #define ENC_IS_ISO_8859_11_CTYPE(code,ctype) \ 33 | ((EncISO_8859_11_CtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0) 34 | 35 | static const unsigned short EncISO_8859_11_CtypeTable[256] = { 36 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 37 | 0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008, 38 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 39 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 40 | 0x4284, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 41 | 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 42 | 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 43 | 0x78b0, 0x78b0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 44 | 0x41a0, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x74a2, 45 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 46 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 47 | 0x74a2, 0x74a2, 0x74a2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x51a0, 48 | 0x41a0, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x70e2, 49 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 50 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 51 | 0x70e2, 0x70e2, 0x70e2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x4008, 52 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 53 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 54 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 55 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 56 | 0x0284, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 57 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 58 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 59 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 60 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 61 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 62 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 63 | 0x30a2, 0x30a2, 0x30a2, 0x0000, 0x0000, 0x0000, 0x0000, 0x30a2, 64 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 65 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 66 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 67 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x0000, 0x0000, 0x0000, 0x0000 68 | }; 69 | 70 | static int 71 | is_code_ctype(OnigCodePoint code, unsigned int ctype) 72 | { 73 | if (code < 256) 74 | return ENC_IS_ISO_8859_11_CTYPE(code, ctype); 75 | else 76 | return FALSE; 77 | } 78 | 79 | OnigEncodingType OnigEncodingISO_8859_11 = { 80 | onigenc_single_byte_mbc_enc_len, 81 | "ISO-8859-11", /* name */ 82 | 1, /* max enc length */ 83 | 1, /* min enc length */ 84 | onigenc_is_mbc_newline_0x0a, 85 | onigenc_single_byte_mbc_to_code, 86 | onigenc_single_byte_code_to_mbclen, 87 | onigenc_single_byte_code_to_mbc, 88 | onigenc_ascii_mbc_case_fold, 89 | onigenc_ascii_apply_all_case_fold, 90 | onigenc_ascii_get_case_fold_codes_by_str, 91 | onigenc_minimum_property_name_to_ctype, 92 | is_code_ctype, 93 | onigenc_not_support_get_ctype_code_range, 94 | onigenc_single_byte_left_adjust_char_head, 95 | onigenc_always_true_is_allowed_reverse_match 96 | }; 97 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/iso8859_6.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | iso8859_6.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | #define ENC_IS_ISO_8859_6_CTYPE(code,ctype) \ 33 | ((EncISO_8859_6_CtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0) 34 | 35 | static const unsigned short EncISO_8859_6_CtypeTable[256] = { 36 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 37 | 0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008, 38 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 39 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 40 | 0x4284, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 41 | 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 42 | 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 43 | 0x78b0, 0x78b0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 44 | 0x41a0, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x74a2, 45 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 46 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 47 | 0x74a2, 0x74a2, 0x74a2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x51a0, 48 | 0x41a0, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x70e2, 49 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 50 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 51 | 0x70e2, 0x70e2, 0x70e2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x4008, 52 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 53 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 54 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 55 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 56 | 0x0284, 0x0000, 0x0000, 0x0000, 0x00a0, 0x0000, 0x0000, 0x0000, 57 | 0x0000, 0x0000, 0x0000, 0x0000, 0x01a0, 0x01a0, 0x0000, 0x0000, 58 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 59 | 0x0000, 0x0000, 0x0000, 0x01a0, 0x0000, 0x0000, 0x0000, 0x01a0, 60 | 0x0000, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 61 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 62 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 63 | 0x30a2, 0x30a2, 0x30a2, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 64 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 65 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 66 | 0x30a2, 0x30a2, 0x30a2, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 67 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 68 | }; 69 | 70 | static int 71 | is_code_ctype(OnigCodePoint code, unsigned int ctype) 72 | { 73 | if (code < 256) 74 | return ENC_IS_ISO_8859_6_CTYPE(code, ctype); 75 | else 76 | return FALSE; 77 | } 78 | 79 | OnigEncodingType OnigEncodingISO_8859_6 = { 80 | onigenc_single_byte_mbc_enc_len, 81 | "ISO-8859-6", /* name */ 82 | 1, /* max enc length */ 83 | 1, /* min enc length */ 84 | onigenc_is_mbc_newline_0x0a, 85 | onigenc_single_byte_mbc_to_code, 86 | onigenc_single_byte_code_to_mbclen, 87 | onigenc_single_byte_code_to_mbc, 88 | onigenc_ascii_mbc_case_fold, 89 | onigenc_ascii_apply_all_case_fold, 90 | onigenc_ascii_get_case_fold_codes_by_str, 91 | onigenc_minimum_property_name_to_ctype, 92 | is_code_ctype, 93 | onigenc_not_support_get_ctype_code_range, 94 | onigenc_single_byte_left_adjust_char_head, 95 | onigenc_always_true_is_allowed_reverse_match 96 | }; 97 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/iso8859_8.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | iso8859_8.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | #define ENC_IS_ISO_8859_8_CTYPE(code,ctype) \ 33 | ((EncISO_8859_8_CtypeTable[code] & CTYPE_TO_BIT(ctype)) != 0) 34 | 35 | static const unsigned short EncISO_8859_8_CtypeTable[256] = { 36 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 37 | 0x4008, 0x420c, 0x4209, 0x4208, 0x4208, 0x4208, 0x4008, 0x4008, 38 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 39 | 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 0x4008, 40 | 0x4284, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 41 | 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 42 | 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 0x78b0, 43 | 0x78b0, 0x78b0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 44 | 0x41a0, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x7ca2, 0x74a2, 45 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 46 | 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 0x74a2, 47 | 0x74a2, 0x74a2, 0x74a2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x51a0, 48 | 0x41a0, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x78e2, 0x70e2, 49 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 50 | 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 0x70e2, 51 | 0x70e2, 0x70e2, 0x70e2, 0x41a0, 0x41a0, 0x41a0, 0x41a0, 0x4008, 52 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 53 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 54 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 55 | 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 56 | 0x0284, 0x0000, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 57 | 0x00a0, 0x00a0, 0x00a0, 0x01a0, 0x00a0, 0x01a0, 0x00a0, 0x00a0, 58 | 0x00a0, 0x00a0, 0x10a0, 0x10a0, 0x00a0, 0x30e2, 0x00a0, 0x01a0, 59 | 0x00a0, 0x10a0, 0x00a0, 0x01a0, 0x10a0, 0x10a0, 0x10a0, 0x0000, 60 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 61 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 62 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 63 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x01a0, 64 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 65 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 66 | 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 0x30a2, 67 | 0x30a2, 0x30a2, 0x30a2, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 68 | }; 69 | 70 | static int 71 | is_code_ctype(OnigCodePoint code, unsigned int ctype) 72 | { 73 | if (code < 256) 74 | return ENC_IS_ISO_8859_8_CTYPE(code, ctype); 75 | else 76 | return FALSE; 77 | } 78 | 79 | OnigEncodingType OnigEncodingISO_8859_8 = { 80 | onigenc_single_byte_mbc_enc_len, 81 | "ISO-8859-8", /* name */ 82 | 1, /* max enc length */ 83 | 1, /* min enc length */ 84 | onigenc_is_mbc_newline_0x0a, 85 | onigenc_single_byte_mbc_to_code, 86 | onigenc_single_byte_code_to_mbclen, 87 | onigenc_single_byte_code_to_mbc, 88 | onigenc_ascii_mbc_case_fold, 89 | onigenc_ascii_apply_all_case_fold, 90 | onigenc_ascii_get_case_fold_codes_by_str, 91 | onigenc_minimum_property_name_to_ctype, 92 | is_code_ctype, 93 | onigenc_not_support_get_ctype_code_range, 94 | onigenc_single_byte_left_adjust_char_head, 95 | onigenc_always_true_is_allowed_reverse_match 96 | }; 97 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/utf16_be.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | utf16_be.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2008 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static const int EncLen_UTF16[] = { 33 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 34 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 35 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 36 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 37 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 38 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 39 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 40 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 41 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 42 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 43 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 44 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 45 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 46 | 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 47 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 48 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 49 | }; 50 | 51 | static int 52 | utf16be_mbc_enc_len(const UChar* p) 53 | { 54 | return EncLen_UTF16[*p]; 55 | } 56 | 57 | static int 58 | utf16be_is_mbc_newline(const UChar* p, const UChar* end) 59 | { 60 | if (p + 1 < end) { 61 | if (*(p+1) == 0x0a && *p == 0x00) 62 | return 1; 63 | #ifdef USE_UNICODE_ALL_LINE_TERMINATORS 64 | if (( 65 | #ifndef USE_CRNL_AS_LINE_TERMINATOR 66 | *(p+1) == 0x0d || 67 | #endif 68 | *(p+1) == 0x85) && *p == 0x00) 69 | return 1; 70 | if (*p == 0x20 && (*(p+1) == 0x29 || *(p+1) == 0x28)) 71 | return 1; 72 | #endif 73 | } 74 | return 0; 75 | } 76 | 77 | static OnigCodePoint 78 | utf16be_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED) 79 | { 80 | OnigCodePoint code; 81 | 82 | if (UTF16_IS_SURROGATE_FIRST(*p)) { 83 | code = ((((p[0] - 0xd8) << 2) + ((p[1] & 0xc0) >> 6) + 1) << 16) 84 | + ((((p[1] & 0x3f) << 2) + (p[2] - 0xdc)) << 8) 85 | + p[3]; 86 | } 87 | else { 88 | code = p[0] * 256 + p[1]; 89 | } 90 | return code; 91 | } 92 | 93 | static int 94 | utf16be_code_to_mbclen(OnigCodePoint code) 95 | { 96 | return (code > 0xffff ? 4 : 2); 97 | } 98 | 99 | static int 100 | utf16be_code_to_mbc(OnigCodePoint code, UChar *buf) 101 | { 102 | UChar* p = buf; 103 | 104 | if (code > 0xffff) { 105 | unsigned int plane, high; 106 | 107 | plane = (code >> 16) - 1; 108 | *p++ = (plane >> 2) + 0xd8; 109 | high = (code & 0xff00) >> 8; 110 | *p++ = ((plane & 0x03) << 6) + (high >> 2); 111 | *p++ = (high & 0x03) + 0xdc; 112 | *p = (UChar )(code & 0xff); 113 | return 4; 114 | } 115 | else { 116 | *p++ = (UChar )((code & 0xff00) >> 8); 117 | *p++ = (UChar )(code & 0xff); 118 | return 2; 119 | } 120 | } 121 | 122 | static int 123 | utf16be_mbc_case_fold(OnigCaseFoldType flag, 124 | const UChar** pp, const UChar* end, UChar* fold) 125 | { 126 | const UChar* p = *pp; 127 | 128 | if (ONIGENC_IS_ASCII_CODE(*(p+1)) && *p == 0) { 129 | p++; 130 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI 131 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) { 132 | if (*p == 0x49) { 133 | *fold++ = 0x01; 134 | *fold = 0x31; 135 | (*pp) += 2; 136 | return 2; 137 | } 138 | } 139 | #endif 140 | 141 | *fold++ = 0; 142 | *fold = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p); 143 | *pp += 2; 144 | return 2; 145 | } 146 | else 147 | return onigenc_unicode_mbc_case_fold(ONIG_ENCODING_UTF16_BE, flag, 148 | pp, end, fold); 149 | } 150 | 151 | #if 0 152 | static int 153 | utf16be_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* end) 154 | { 155 | const UChar* p = *pp; 156 | 157 | (*pp) += EncLen_UTF16[*p]; 158 | 159 | if (*p == 0) { 160 | int c, v; 161 | 162 | p++; 163 | if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) { 164 | return TRUE; 165 | } 166 | 167 | c = *p; 168 | v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c, 169 | (BIT_CTYPE_UPPER | BIT_CTYPE_LOWER)); 170 | 171 | if ((v | BIT_CTYPE_LOWER) != 0) { 172 | /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */ 173 | if (c >= 0xaa && c <= 0xba) 174 | return FALSE; 175 | else 176 | return TRUE; 177 | } 178 | return (v != 0 ? TRUE : FALSE); 179 | } 180 | 181 | return FALSE; 182 | } 183 | #endif 184 | 185 | static UChar* 186 | utf16be_left_adjust_char_head(const UChar* start, const UChar* s) 187 | { 188 | if (s <= start) return (UChar* )s; 189 | 190 | if ((s - start) % 2 == 1) { 191 | s--; 192 | } 193 | 194 | if (UTF16_IS_SURROGATE_SECOND(*s) && s > start + 1) 195 | s -= 2; 196 | 197 | return (UChar* )s; 198 | } 199 | 200 | static int 201 | utf16be_get_case_fold_codes_by_str(OnigCaseFoldType flag, 202 | const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]) 203 | { 204 | return onigenc_unicode_get_case_fold_codes_by_str(ONIG_ENCODING_UTF16_BE, 205 | flag, p, end, items); 206 | } 207 | 208 | OnigEncodingType OnigEncodingUTF16_BE = { 209 | utf16be_mbc_enc_len, 210 | "UTF-16BE", /* name */ 211 | 4, /* max byte length */ 212 | 2, /* min byte length */ 213 | utf16be_is_mbc_newline, 214 | utf16be_mbc_to_code, 215 | utf16be_code_to_mbclen, 216 | utf16be_code_to_mbc, 217 | utf16be_mbc_case_fold, 218 | onigenc_unicode_apply_all_case_fold, 219 | utf16be_get_case_fold_codes_by_str, 220 | onigenc_unicode_property_name_to_ctype, 221 | onigenc_unicode_is_code_ctype, 222 | onigenc_utf16_32_get_ctype_code_range, 223 | utf16be_left_adjust_char_head, 224 | onigenc_always_false_is_allowed_reverse_match 225 | }; 226 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/utf16_le.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | utf16_le.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2008 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static const int EncLen_UTF16[] = { 33 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 34 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 35 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 36 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 37 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 38 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 39 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 40 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 41 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 42 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 43 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 44 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 45 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 46 | 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2, 2, 47 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 48 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 49 | }; 50 | 51 | static int 52 | utf16le_code_to_mbclen(OnigCodePoint code) 53 | { 54 | return (code > 0xffff ? 4 : 2); 55 | } 56 | 57 | static int 58 | utf16le_mbc_enc_len(const UChar* p) 59 | { 60 | return EncLen_UTF16[*(p+1)]; 61 | } 62 | 63 | static int 64 | utf16le_is_mbc_newline(const UChar* p, const UChar* end) 65 | { 66 | if (p + 1 < end) { 67 | if (*p == 0x0a && *(p+1) == 0x00) 68 | return 1; 69 | #ifdef USE_UNICODE_ALL_LINE_TERMINATORS 70 | if (( 71 | #ifndef USE_CRNL_AS_LINE_TERMINATOR 72 | *p == 0x0d || 73 | #endif 74 | *p == 0x85) && *(p+1) == 0x00) 75 | return 1; 76 | if (*(p+1) == 0x20 && (*p == 0x29 || *p == 0x28)) 77 | return 1; 78 | #endif 79 | } 80 | return 0; 81 | } 82 | 83 | static OnigCodePoint 84 | utf16le_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED) 85 | { 86 | OnigCodePoint code; 87 | UChar c0 = *p; 88 | UChar c1 = *(p+1); 89 | 90 | if (UTF16_IS_SURROGATE_FIRST(c1)) { 91 | code = ((((c1 - 0xd8) << 2) + ((c0 & 0xc0) >> 6) + 1) << 16) 92 | + ((((c0 & 0x3f) << 2) + (p[3] - 0xdc)) << 8) 93 | + p[2]; 94 | } 95 | else { 96 | code = c1 * 256 + p[0]; 97 | } 98 | return code; 99 | } 100 | 101 | static int 102 | utf16le_code_to_mbc(OnigCodePoint code, UChar *buf) 103 | { 104 | UChar* p = buf; 105 | 106 | if (code > 0xffff) { 107 | unsigned int plane, high; 108 | 109 | plane = (code >> 16) - 1; 110 | high = (code & 0xff00) >> 8; 111 | 112 | *p++ = ((plane & 0x03) << 6) + (high >> 2); 113 | *p++ = (plane >> 2) + 0xd8; 114 | *p++ = (UChar )(code & 0xff); 115 | *p = (high & 0x03) + 0xdc; 116 | return 4; 117 | } 118 | else { 119 | *p++ = (UChar )(code & 0xff); 120 | *p++ = (UChar )((code & 0xff00) >> 8); 121 | return 2; 122 | } 123 | } 124 | 125 | static int 126 | utf16le_mbc_case_fold(OnigCaseFoldType flag, 127 | const UChar** pp, const UChar* end, UChar* fold) 128 | { 129 | const UChar* p = *pp; 130 | 131 | if (ONIGENC_IS_ASCII_CODE(*p) && *(p+1) == 0) { 132 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI 133 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) { 134 | if (*p == 0x49) { 135 | *fold++ = 0x31; 136 | *fold = 0x01; 137 | (*pp) += 2; 138 | return 2; 139 | } 140 | } 141 | #endif 142 | 143 | *fold++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p); 144 | *fold = 0; 145 | *pp += 2; 146 | return 2; 147 | } 148 | else 149 | return onigenc_unicode_mbc_case_fold(ONIG_ENCODING_UTF16_LE, flag, pp, end, 150 | fold); 151 | } 152 | 153 | #if 0 154 | static int 155 | utf16le_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, 156 | const UChar* end) 157 | { 158 | const UChar* p = *pp; 159 | 160 | (*pp) += EncLen_UTF16[*(p+1)]; 161 | 162 | if (*(p+1) == 0) { 163 | int c, v; 164 | 165 | if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) { 166 | return TRUE; 167 | } 168 | 169 | c = *p; 170 | v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c, 171 | (BIT_CTYPE_UPPER | BIT_CTYPE_LOWER)); 172 | if ((v | BIT_CTYPE_LOWER) != 0) { 173 | /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */ 174 | if (c >= 0xaa && c <= 0xba) 175 | return FALSE; 176 | else 177 | return TRUE; 178 | } 179 | return (v != 0 ? TRUE : FALSE); 180 | } 181 | 182 | return FALSE; 183 | } 184 | #endif 185 | 186 | static UChar* 187 | utf16le_left_adjust_char_head(const UChar* start, const UChar* s) 188 | { 189 | if (s <= start) return (UChar* )s; 190 | 191 | if ((s - start) % 2 == 1) { 192 | s--; 193 | } 194 | 195 | if (UTF16_IS_SURROGATE_SECOND(*(s+1)) && s > start + 1) 196 | s -= 2; 197 | 198 | return (UChar* )s; 199 | } 200 | 201 | static int 202 | utf16le_get_case_fold_codes_by_str(OnigCaseFoldType flag, 203 | const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]) 204 | { 205 | return onigenc_unicode_get_case_fold_codes_by_str(ONIG_ENCODING_UTF16_LE, 206 | flag, p, end, items); 207 | } 208 | 209 | OnigEncodingType OnigEncodingUTF16_LE = { 210 | utf16le_mbc_enc_len, 211 | "UTF-16LE", /* name */ 212 | 4, /* max byte length */ 213 | 2, /* min byte length */ 214 | utf16le_is_mbc_newline, 215 | utf16le_mbc_to_code, 216 | utf16le_code_to_mbclen, 217 | utf16le_code_to_mbc, 218 | utf16le_mbc_case_fold, 219 | onigenc_unicode_apply_all_case_fold, 220 | utf16le_get_case_fold_codes_by_str, 221 | onigenc_unicode_property_name_to_ctype, 222 | onigenc_unicode_is_code_ctype, 223 | onigenc_utf16_32_get_ctype_code_range, 224 | utf16le_left_adjust_char_head, 225 | onigenc_always_false_is_allowed_reverse_match 226 | }; 227 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/utf32_be.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | utf32_be.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static int 33 | utf32be_mbc_enc_len(const UChar* p ARG_UNUSED) 34 | { 35 | return 4; 36 | } 37 | 38 | static int 39 | utf32be_is_mbc_newline(const UChar* p, const UChar* end) 40 | { 41 | if (p + 3 < end) { 42 | if (*(p+3) == 0x0a && *(p+2) == 0 && *(p+1) == 0 && *p == 0) 43 | return 1; 44 | #ifdef USE_UNICODE_ALL_LINE_TERMINATORS 45 | if (( 46 | #ifndef USE_CRNL_AS_LINE_TERMINATOR 47 | *(p+3) == 0x0d || 48 | #endif 49 | *(p+3) == 0x85) 50 | && *(p+2) == 0 && *(p+1) == 0 && *p == 0x00) 51 | return 1; 52 | if (*(p+2) == 0x20 && (*(p+3) == 0x29 || *(p+3) == 0x28) 53 | && *(p+1) == 0 && *p == 0) 54 | return 1; 55 | #endif 56 | } 57 | return 0; 58 | } 59 | 60 | static OnigCodePoint 61 | utf32be_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED) 62 | { 63 | return (OnigCodePoint )(((p[0] * 256 + p[1]) * 256 + p[2]) * 256 + p[3]); 64 | } 65 | 66 | static int 67 | utf32be_code_to_mbclen(OnigCodePoint code ARG_UNUSED) 68 | { 69 | return 4; 70 | } 71 | 72 | static int 73 | utf32be_code_to_mbc(OnigCodePoint code, UChar *buf) 74 | { 75 | UChar* p = buf; 76 | 77 | *p++ = (UChar )((code & 0xff000000) >>24); 78 | *p++ = (UChar )((code & 0xff0000) >>16); 79 | *p++ = (UChar )((code & 0xff00) >> 8); 80 | *p++ = (UChar ) (code & 0xff); 81 | return 4; 82 | } 83 | 84 | static int 85 | utf32be_mbc_case_fold(OnigCaseFoldType flag, 86 | const UChar** pp, const UChar* end, UChar* fold) 87 | { 88 | const UChar* p = *pp; 89 | 90 | if (ONIGENC_IS_ASCII_CODE(*(p+3)) && *(p+2) == 0 && *(p+1) == 0 && *p == 0) { 91 | *fold++ = 0; 92 | *fold++ = 0; 93 | 94 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI 95 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) { 96 | if (*(p+3) == 0x49) { 97 | *fold++ = 0x01; 98 | *fold = 0x31; 99 | (*pp) += 4; 100 | return 4; 101 | } 102 | } 103 | #endif 104 | 105 | *fold++ = 0; 106 | *fold = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*(p+3)); 107 | *pp += 4; 108 | return 4; 109 | } 110 | else 111 | return onigenc_unicode_mbc_case_fold(ONIG_ENCODING_UTF32_BE, flag, pp, end, 112 | fold); 113 | } 114 | 115 | #if 0 116 | static int 117 | utf32be_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* end) 118 | { 119 | const UChar* p = *pp; 120 | 121 | (*pp) += 4; 122 | 123 | if (*(p+2) == 0 && *(p+1) == 0 && *p == 0) { 124 | int c, v; 125 | 126 | p += 3; 127 | if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) { 128 | return TRUE; 129 | } 130 | 131 | c = *p; 132 | v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c, 133 | (BIT_CTYPE_UPPER | BIT_CTYPE_LOWER)); 134 | if ((v | BIT_CTYPE_LOWER) != 0) { 135 | /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */ 136 | if (c >= 0xaa && c <= 0xba) 137 | return FALSE; 138 | else 139 | return TRUE; 140 | } 141 | return (v != 0 ? TRUE : FALSE); 142 | } 143 | 144 | return FALSE; 145 | } 146 | #endif 147 | 148 | static UChar* 149 | utf32be_left_adjust_char_head(const UChar* start, const UChar* s) 150 | { 151 | int rem; 152 | 153 | if (s <= start) return (UChar* )s; 154 | 155 | rem = (s - start) % 4; 156 | return (UChar* )(s - rem); 157 | } 158 | 159 | static int 160 | utf32be_get_case_fold_codes_by_str(OnigCaseFoldType flag, 161 | const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]) 162 | { 163 | return onigenc_unicode_get_case_fold_codes_by_str(ONIG_ENCODING_UTF32_BE, 164 | flag, p, end, items); 165 | } 166 | 167 | OnigEncodingType OnigEncodingUTF32_BE = { 168 | utf32be_mbc_enc_len, 169 | "UTF-32BE", /* name */ 170 | 4, /* max byte length */ 171 | 4, /* min byte length */ 172 | utf32be_is_mbc_newline, 173 | utf32be_mbc_to_code, 174 | utf32be_code_to_mbclen, 175 | utf32be_code_to_mbc, 176 | utf32be_mbc_case_fold, 177 | onigenc_unicode_apply_all_case_fold, 178 | utf32be_get_case_fold_codes_by_str, 179 | onigenc_unicode_property_name_to_ctype, 180 | onigenc_unicode_is_code_ctype, 181 | onigenc_utf16_32_get_ctype_code_range, 182 | utf32be_left_adjust_char_head, 183 | onigenc_always_false_is_allowed_reverse_match 184 | }; 185 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/enc/utf32_le.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | utf32_le.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regenc.h" 31 | 32 | static int 33 | utf32le_mbc_enc_len(const UChar* p ARG_UNUSED) 34 | { 35 | return 4; 36 | } 37 | 38 | static int 39 | utf32le_is_mbc_newline(const UChar* p, const UChar* end) 40 | { 41 | if (p + 3 < end) { 42 | if (*p == 0x0a && *(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0) 43 | return 1; 44 | #ifdef USE_UNICODE_ALL_LINE_TERMINATORS 45 | if (( 46 | #ifndef USE_CRNL_AS_LINE_TERMINATOR 47 | *p == 0x0d || 48 | #endif 49 | *p == 0x85) 50 | && *(p+1) == 0x00 && (p+2) == 0x00 && *(p+3) == 0x00) 51 | return 1; 52 | if (*(p+1) == 0x20 && (*p == 0x29 || *p == 0x28) 53 | && *(p+2) == 0x00 && *(p+3) == 0x00) 54 | return 1; 55 | #endif 56 | } 57 | return 0; 58 | } 59 | 60 | static OnigCodePoint 61 | utf32le_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED) 62 | { 63 | return (OnigCodePoint )(((p[3] * 256 + p[2]) * 256 + p[1]) * 256 + p[0]); 64 | } 65 | 66 | static int 67 | utf32le_code_to_mbclen(OnigCodePoint code ARG_UNUSED) 68 | { 69 | return 4; 70 | } 71 | 72 | static int 73 | utf32le_code_to_mbc(OnigCodePoint code, UChar *buf) 74 | { 75 | UChar* p = buf; 76 | 77 | *p++ = (UChar ) (code & 0xff); 78 | *p++ = (UChar )((code & 0xff00) >> 8); 79 | *p++ = (UChar )((code & 0xff0000) >>16); 80 | *p++ = (UChar )((code & 0xff000000) >>24); 81 | return 4; 82 | } 83 | 84 | static int 85 | utf32le_mbc_case_fold(OnigCaseFoldType flag, 86 | const UChar** pp, const UChar* end, UChar* fold) 87 | { 88 | const UChar* p = *pp; 89 | 90 | if (ONIGENC_IS_ASCII_CODE(*p) && *(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0) { 91 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI 92 | if ((flag & ONIGENC_CASE_FOLD_TURKISH_AZERI) != 0) { 93 | if (*p == 0x49) { 94 | *fold++ = 0x31; 95 | *fold++ = 0x01; 96 | } 97 | } 98 | else { 99 | #endif 100 | *fold++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p); 101 | *fold++ = 0; 102 | #ifdef USE_UNICODE_CASE_FOLD_TURKISH_AZERI 103 | } 104 | #endif 105 | 106 | *fold++ = 0; 107 | *fold = 0; 108 | *pp += 4; 109 | return 4; 110 | } 111 | else 112 | return onigenc_unicode_mbc_case_fold(ONIG_ENCODING_UTF32_LE, flag, pp, end, 113 | fold); 114 | } 115 | 116 | #if 0 117 | static int 118 | utf32le_is_mbc_ambiguous(OnigCaseFoldType flag, const UChar** pp, const UChar* end) 119 | { 120 | const UChar* p = *pp; 121 | 122 | (*pp) += 4; 123 | 124 | if (*(p+1) == 0 && *(p+2) == 0 && *(p+3) == 0) { 125 | int c, v; 126 | 127 | if (*p == 0xdf && (flag & INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR) != 0) { 128 | return TRUE; 129 | } 130 | 131 | c = *p; 132 | v = ONIGENC_IS_UNICODE_ISO_8859_1_BIT_CTYPE(c, 133 | (BIT_CTYPE_UPPER | BIT_CTYPE_LOWER)); 134 | if ((v | BIT_CTYPE_LOWER) != 0) { 135 | /* 0xaa, 0xb5, 0xba are lower case letter, but can't convert. */ 136 | if (c >= 0xaa && c <= 0xba) 137 | return FALSE; 138 | else 139 | return TRUE; 140 | } 141 | return (v != 0 ? TRUE : FALSE); 142 | } 143 | 144 | return FALSE; 145 | } 146 | #endif 147 | 148 | static UChar* 149 | utf32le_left_adjust_char_head(const UChar* start, const UChar* s) 150 | { 151 | int rem; 152 | 153 | if (s <= start) return (UChar* )s; 154 | 155 | rem = (s - start) % 4; 156 | return (UChar* )(s - rem); 157 | } 158 | 159 | static int 160 | utf32le_get_case_fold_codes_by_str(OnigCaseFoldType flag, 161 | const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem items[]) 162 | { 163 | return onigenc_unicode_get_case_fold_codes_by_str(ONIG_ENCODING_UTF32_LE, 164 | flag, p, end, items); 165 | } 166 | 167 | OnigEncodingType OnigEncodingUTF32_LE = { 168 | utf32le_mbc_enc_len, 169 | "UTF-32LE", /* name */ 170 | 4, /* max byte length */ 171 | 4, /* min byte length */ 172 | utf32le_is_mbc_newline, 173 | utf32le_mbc_to_code, 174 | utf32le_code_to_mbclen, 175 | utf32le_code_to_mbc, 176 | utf32le_mbc_case_fold, 177 | onigenc_unicode_apply_all_case_fold, 178 | utf32le_get_case_fold_codes_by_str, 179 | onigenc_unicode_property_name_to_ctype, 180 | onigenc_unicode_is_code_ctype, 181 | onigenc_utf16_32_get_ctype_code_range, 182 | utf32le_left_adjust_char_head, 183 | onigenc_always_false_is_allowed_reverse_match 184 | }; 185 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/onig-config.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (C) 2006 K.Kosako (sndgk393 AT ybb DOT ne DOT jp) 3 | 4 | ONIG_VERSION=@PACKAGE_VERSION@ 5 | 6 | show_usage() 7 | { 8 | cat < 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include "oniguruma.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #define RE_MBCTYPE_ASCII 0 39 | #define RE_MBCTYPE_EUC 1 40 | #define RE_MBCTYPE_SJIS 2 41 | #define RE_MBCTYPE_UTF8 3 42 | 43 | /* GNU regex options */ 44 | #ifndef RE_NREGS 45 | #define RE_NREGS ONIG_NREGION 46 | #endif 47 | 48 | #define RE_OPTION_IGNORECASE ONIG_OPTION_IGNORECASE 49 | #define RE_OPTION_EXTENDED ONIG_OPTION_EXTEND 50 | #define RE_OPTION_MULTILINE ONIG_OPTION_MULTILINE 51 | #define RE_OPTION_SINGLELINE ONIG_OPTION_SINGLELINE 52 | #define RE_OPTION_LONGEST ONIG_OPTION_FIND_LONGEST 53 | #define RE_OPTION_POSIXLINE (RE_OPTION_MULTILINE|RE_OPTION_SINGLELINE) 54 | #define RE_OPTION_FIND_NOT_EMPTY ONIG_OPTION_FIND_NOT_EMPTY 55 | #define RE_OPTION_NEGATE_SINGLELINE ONIG_OPTION_NEGATE_SINGLELINE 56 | #define RE_OPTION_DONT_CAPTURE_GROUP ONIG_OPTION_DONT_CAPTURE_GROUP 57 | #define RE_OPTION_CAPTURE_GROUP ONIG_OPTION_CAPTURE_GROUP 58 | 59 | 60 | ONIG_EXTERN 61 | void re_mbcinit P_((int)); 62 | ONIG_EXTERN 63 | int re_compile_pattern P_((const char*, int, struct re_pattern_buffer*, char* err_buf)); 64 | ONIG_EXTERN 65 | int re_recompile_pattern P_((const char*, int, struct re_pattern_buffer*, char* err_buf)); 66 | ONIG_EXTERN 67 | void re_free_pattern P_((struct re_pattern_buffer*)); 68 | ONIG_EXTERN 69 | int re_adjust_startpos P_((struct re_pattern_buffer*, const char*, int, int, int)); 70 | ONIG_EXTERN 71 | int re_search P_((struct re_pattern_buffer*, const char*, int, int, int, struct re_registers*)); 72 | ONIG_EXTERN 73 | int re_match P_((struct re_pattern_buffer*, const char *, int, int, struct re_registers*)); 74 | ONIG_EXTERN 75 | void re_set_casetable P_((const char*)); 76 | ONIG_EXTERN 77 | void re_free_registers P_((struct re_registers*)); 78 | ONIG_EXTERN 79 | int re_alloc_pattern P_((struct re_pattern_buffer**)); /* added */ 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif /* ONIGGNU_H */ 86 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/onigposix.h: -------------------------------------------------------------------------------- 1 | #ifndef ONIGPOSIX_H 2 | #define ONIGPOSIX_H 3 | /********************************************************************** 4 | onigposix.h - Oniguruma (regular expression library) 5 | **********************************************************************/ 6 | /*- 7 | * Copyright (c) 2002-2005 K.Kosako 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* options */ 38 | #define REG_ICASE (1<<0) 39 | #define REG_NEWLINE (1<<1) 40 | #define REG_NOTBOL (1<<2) 41 | #define REG_NOTEOL (1<<3) 42 | #define REG_EXTENDED (1<<4) /* if not setted, Basic Onigular Expression */ 43 | #define REG_NOSUB (1<<5) 44 | 45 | /* POSIX error codes */ 46 | #define REG_NOMATCH 1 47 | #define REG_BADPAT 2 48 | #define REG_ECOLLATE 3 49 | #define REG_ECTYPE 4 50 | #define REG_EESCAPE 5 51 | #define REG_ESUBREG 6 52 | #define REG_EBRACK 7 53 | #define REG_EPAREN 8 54 | #define REG_EBRACE 9 55 | #define REG_BADBR 10 56 | #define REG_ERANGE 11 57 | #define REG_ESPACE 12 58 | #define REG_BADRPT 13 59 | 60 | /* extended error codes */ 61 | #define REG_EONIG_INTERNAL 14 62 | #define REG_EONIG_BADWC 15 63 | #define REG_EONIG_BADARG 16 64 | #define REG_EONIG_THREAD 17 65 | 66 | /* character encodings (for reg_set_encoding()) */ 67 | #define REG_POSIX_ENCODING_ASCII 0 68 | #define REG_POSIX_ENCODING_EUC_JP 1 69 | #define REG_POSIX_ENCODING_SJIS 2 70 | #define REG_POSIX_ENCODING_UTF8 3 71 | #define REG_POSIX_ENCODING_UTF16_BE 4 72 | #define REG_POSIX_ENCODING_UTF16_LE 5 73 | 74 | 75 | typedef int regoff_t; 76 | 77 | typedef struct { 78 | regoff_t rm_so; 79 | regoff_t rm_eo; 80 | } regmatch_t; 81 | 82 | /* POSIX regex_t */ 83 | typedef struct { 84 | void* onig; /* Oniguruma regex_t* */ 85 | size_t re_nsub; 86 | int comp_options; 87 | } regex_t; 88 | 89 | 90 | #ifndef P_ 91 | #if defined(__STDC__) || defined(_WIN32) 92 | # define P_(args) args 93 | #else 94 | # define P_(args) () 95 | #endif 96 | #endif 97 | 98 | #ifndef ONIG_EXTERN 99 | #if defined(_WIN32) && !defined(__GNUC__) 100 | #if defined(EXPORT) 101 | #define ONIG_EXTERN extern __declspec(dllexport) 102 | #else 103 | #define ONIG_EXTERN extern __declspec(dllimport) 104 | #endif 105 | #endif 106 | #endif 107 | 108 | #ifndef ONIG_EXTERN 109 | #define ONIG_EXTERN extern 110 | #endif 111 | 112 | #ifndef ONIGURUMA_H 113 | typedef unsigned int OnigOptionType; 114 | 115 | /* syntax */ 116 | typedef struct { 117 | unsigned int op; 118 | unsigned int op2; 119 | unsigned int behavior; 120 | OnigOptionType options; /* default option */ 121 | } OnigSyntaxType; 122 | 123 | ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic; 124 | ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended; 125 | ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs; 126 | ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep; 127 | ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex; 128 | ONIG_EXTERN OnigSyntaxType OnigSyntaxJava; 129 | ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl; 130 | ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby; 131 | 132 | /* predefined syntaxes (see regsyntax.c) */ 133 | #define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic) 134 | #define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended) 135 | #define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs) 136 | #define ONIG_SYNTAX_GREP (&OnigSyntaxGrep) 137 | #define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex) 138 | #define ONIG_SYNTAX_JAVA (&OnigSyntaxJava) 139 | #define ONIG_SYNTAX_PERL (&OnigSyntaxPerl) 140 | #define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby) 141 | /* default syntax */ 142 | #define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax 143 | 144 | ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax; 145 | 146 | ONIG_EXTERN int onig_set_default_syntax P_((OnigSyntaxType* syntax)); 147 | ONIG_EXTERN void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from)); 148 | ONIG_EXTERN const char* onig_version P_((void)); 149 | ONIG_EXTERN const char* onig_copyright P_((void)); 150 | 151 | #endif /* ONIGURUMA_H */ 152 | 153 | 154 | ONIG_EXTERN int regcomp P_((regex_t* reg, const char* pat, int options)); 155 | ONIG_EXTERN int regexec P_((regex_t* reg, const char* str, size_t nmatch, regmatch_t* matches, int options)); 156 | ONIG_EXTERN void regfree P_((regex_t* reg)); 157 | ONIG_EXTERN size_t regerror P_((int code, const regex_t* reg, char* buf, size_t size)); 158 | 159 | /* extended API */ 160 | ONIG_EXTERN void reg_set_encoding P_((int enc)); 161 | ONIG_EXTERN int reg_name_to_group_numbers P_((regex_t* reg, const unsigned char* name, const unsigned char* name_end, int** nums)); 162 | ONIG_EXTERN int reg_foreach_name P_((regex_t* reg, int (*func)(const unsigned char*, const unsigned char*,int,int*,regex_t*,void*), void* arg)); 163 | ONIG_EXTERN int reg_number_of_names P_((regex_t* reg)); 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /* ONIGPOSIX_H */ 170 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/regext.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | regext.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2008 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regint.h" 31 | 32 | static void 33 | conv_ext0be32(const UChar* s, const UChar* end, UChar* conv) 34 | { 35 | while (s < end) { 36 | *conv++ = '\0'; 37 | *conv++ = '\0'; 38 | *conv++ = '\0'; 39 | *conv++ = *s++; 40 | } 41 | } 42 | 43 | static void 44 | conv_ext0le32(const UChar* s, const UChar* end, UChar* conv) 45 | { 46 | while (s < end) { 47 | *conv++ = *s++; 48 | *conv++ = '\0'; 49 | *conv++ = '\0'; 50 | *conv++ = '\0'; 51 | } 52 | } 53 | 54 | static void 55 | conv_ext0be(const UChar* s, const UChar* end, UChar* conv) 56 | { 57 | while (s < end) { 58 | *conv++ = '\0'; 59 | *conv++ = *s++; 60 | } 61 | } 62 | 63 | static void 64 | conv_ext0le(const UChar* s, const UChar* end, UChar* conv) 65 | { 66 | while (s < end) { 67 | *conv++ = *s++; 68 | *conv++ = '\0'; 69 | } 70 | } 71 | 72 | static void 73 | conv_swap4bytes(const UChar* s, const UChar* end, UChar* conv) 74 | { 75 | while (s < end) { 76 | *conv++ = s[3]; 77 | *conv++ = s[2]; 78 | *conv++ = s[1]; 79 | *conv++ = s[0]; 80 | s += 4; 81 | } 82 | } 83 | 84 | static void 85 | conv_swap2bytes(const UChar* s, const UChar* end, UChar* conv) 86 | { 87 | while (s < end) { 88 | *conv++ = s[1]; 89 | *conv++ = s[0]; 90 | s += 2; 91 | } 92 | } 93 | 94 | static int 95 | conv_encoding(OnigEncoding from, OnigEncoding to, const UChar* s, const UChar* end, 96 | UChar** conv, UChar** conv_end) 97 | { 98 | int len = end - s; 99 | 100 | if (to == ONIG_ENCODING_UTF16_BE) { 101 | if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) { 102 | *conv = (UChar* )xmalloc(len * 2); 103 | CHECK_NULL_RETURN_MEMERR(*conv); 104 | *conv_end = *conv + (len * 2); 105 | conv_ext0be(s, end, *conv); 106 | return 0; 107 | } 108 | else if (from == ONIG_ENCODING_UTF16_LE) { 109 | swap16: 110 | *conv = (UChar* )xmalloc(len); 111 | CHECK_NULL_RETURN_MEMERR(*conv); 112 | *conv_end = *conv + len; 113 | conv_swap2bytes(s, end, *conv); 114 | return 0; 115 | } 116 | } 117 | else if (to == ONIG_ENCODING_UTF16_LE) { 118 | if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) { 119 | *conv = (UChar* )xmalloc(len * 2); 120 | CHECK_NULL_RETURN_MEMERR(*conv); 121 | *conv_end = *conv + (len * 2); 122 | conv_ext0le(s, end, *conv); 123 | return 0; 124 | } 125 | else if (from == ONIG_ENCODING_UTF16_BE) { 126 | goto swap16; 127 | } 128 | } 129 | if (to == ONIG_ENCODING_UTF32_BE) { 130 | if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) { 131 | *conv = (UChar* )xmalloc(len * 4); 132 | CHECK_NULL_RETURN_MEMERR(*conv); 133 | *conv_end = *conv + (len * 4); 134 | conv_ext0be32(s, end, *conv); 135 | return 0; 136 | } 137 | else if (from == ONIG_ENCODING_UTF32_LE) { 138 | swap32: 139 | *conv = (UChar* )xmalloc(len); 140 | CHECK_NULL_RETURN_MEMERR(*conv); 141 | *conv_end = *conv + len; 142 | conv_swap4bytes(s, end, *conv); 143 | return 0; 144 | } 145 | } 146 | else if (to == ONIG_ENCODING_UTF32_LE) { 147 | if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) { 148 | *conv = (UChar* )xmalloc(len * 4); 149 | CHECK_NULL_RETURN_MEMERR(*conv); 150 | *conv_end = *conv + (len * 4); 151 | conv_ext0le32(s, end, *conv); 152 | return 0; 153 | } 154 | else if (from == ONIG_ENCODING_UTF32_BE) { 155 | goto swap32; 156 | } 157 | } 158 | 159 | return ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION; 160 | } 161 | 162 | extern int 163 | onig_new_deluxe(regex_t** reg, const UChar* pattern, const UChar* pattern_end, 164 | OnigCompileInfo* ci, OnigErrorInfo* einfo) 165 | { 166 | int r; 167 | UChar *cpat, *cpat_end; 168 | 169 | if (IS_NOT_NULL(einfo)) einfo->par = (UChar* )NULL; 170 | 171 | if (ci->pattern_enc != ci->target_enc) { 172 | r = conv_encoding(ci->pattern_enc, ci->target_enc, pattern, pattern_end, 173 | &cpat, &cpat_end); 174 | if (r) return r; 175 | } 176 | else { 177 | cpat = (UChar* )pattern; 178 | cpat_end = (UChar* )pattern_end; 179 | } 180 | 181 | *reg = (regex_t* )xmalloc(sizeof(regex_t)); 182 | if (IS_NULL(*reg)) { 183 | r = ONIGERR_MEMORY; 184 | goto err2; 185 | } 186 | 187 | r = onig_reg_init(*reg, ci->option, ci->case_fold_flag, ci->target_enc, 188 | ci->syntax); 189 | if (r) goto err; 190 | 191 | r = onig_compile(*reg, cpat, cpat_end, einfo); 192 | if (r) { 193 | err: 194 | onig_free(*reg); 195 | *reg = NULL; 196 | } 197 | 198 | err2: 199 | if (cpat != pattern) xfree(cpat); 200 | 201 | return r; 202 | } 203 | 204 | #ifdef USE_RECOMPILE_API 205 | extern int 206 | onig_recompile_deluxe(regex_t* reg, const UChar* pattern, const UChar* pattern_end, 207 | OnigCompileInfo* ci, OnigErrorInfo* einfo) 208 | { 209 | int r; 210 | regex_t *new_reg; 211 | 212 | r = onig_new_deluxe(&new_reg, pattern, pattern_end, ci, einfo); 213 | if (r) return r; 214 | if (ONIG_STATE(reg) == ONIG_STATE_NORMAL) { 215 | onig_transfer(reg, new_reg); 216 | } 217 | else { 218 | onig_chain_link_add(reg, new_reg); 219 | } 220 | return 0; 221 | } 222 | #endif 223 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/reggnu.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | reggnu.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2008 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regint.h" 31 | 32 | #ifndef ONIGGNU_H 33 | #include "oniggnu.h" 34 | #endif 35 | 36 | extern void 37 | re_free_registers(OnigRegion* r) 38 | { 39 | /* 0: don't free self */ 40 | onig_region_free(r, 0); 41 | } 42 | 43 | extern int 44 | re_adjust_startpos(regex_t* reg, const char* string, int size, 45 | int startpos, int range) 46 | { 47 | if (startpos > 0 && ONIGENC_MBC_MAXLEN(reg->enc) != 1 && startpos < size) { 48 | UChar *p; 49 | UChar *s = (UChar* )string + startpos; 50 | 51 | if (range > 0) { 52 | p = onigenc_get_right_adjust_char_head(reg->enc, (UChar* )string, s); 53 | } 54 | else { 55 | p = ONIGENC_LEFT_ADJUST_CHAR_HEAD(reg->enc, (UChar* )string, s); 56 | } 57 | return p - (UChar* )string; 58 | } 59 | 60 | return startpos; 61 | } 62 | 63 | extern int 64 | re_match(regex_t* reg, const char* str, int size, int pos, 65 | struct re_registers* regs) 66 | { 67 | return onig_match(reg, (UChar* )str, (UChar* )(str + size), 68 | (UChar* )(str + pos), regs, ONIG_OPTION_NONE); 69 | } 70 | 71 | extern int 72 | re_search(regex_t* bufp, const char* string, int size, int startpos, int range, 73 | struct re_registers* regs) 74 | { 75 | return onig_search(bufp, (UChar* )string, (UChar* )(string + size), 76 | (UChar* )(string + startpos), 77 | (UChar* )(string + startpos + range), 78 | regs, ONIG_OPTION_NONE); 79 | } 80 | 81 | extern int 82 | re_compile_pattern(const char* pattern, int size, regex_t* reg, char* ebuf) 83 | { 84 | int r; 85 | OnigErrorInfo einfo; 86 | 87 | r = onig_compile(reg, (UChar* )pattern, (UChar* )(pattern + size), &einfo); 88 | if (r != ONIG_NORMAL) { 89 | if (IS_NOT_NULL(ebuf)) 90 | (void )onig_error_code_to_str((UChar* )ebuf, r, &einfo); 91 | } 92 | 93 | return r; 94 | } 95 | 96 | #ifdef USE_RECOMPILE_API 97 | extern int 98 | re_recompile_pattern(const char* pattern, int size, regex_t* reg, char* ebuf) 99 | { 100 | int r; 101 | OnigErrorInfo einfo; 102 | OnigEncoding enc; 103 | 104 | /* I think encoding and options should be arguments of this function. 105 | But this is adapted to present re.c. (2002/11/29) 106 | */ 107 | enc = OnigEncDefaultCharEncoding; 108 | 109 | r = onig_recompile(reg, (UChar* )pattern, (UChar* )(pattern + size), 110 | reg->options, enc, OnigDefaultSyntax, &einfo); 111 | if (r != ONIG_NORMAL) { 112 | if (IS_NOT_NULL(ebuf)) 113 | (void )onig_error_code_to_str((UChar* )ebuf, r, &einfo); 114 | } 115 | return r; 116 | } 117 | #endif 118 | 119 | extern void 120 | re_free_pattern(regex_t* reg) 121 | { 122 | onig_free(reg); 123 | } 124 | 125 | extern int 126 | re_alloc_pattern(regex_t** reg) 127 | { 128 | *reg = (regex_t* )xmalloc(sizeof(regex_t)); 129 | if (IS_NULL(*reg)) return ONIGERR_MEMORY; 130 | 131 | return onig_reg_init(*reg, ONIG_OPTION_DEFAULT, 132 | ONIGENC_CASE_FOLD_DEFAULT, 133 | OnigEncDefaultCharEncoding, 134 | OnigDefaultSyntax); 135 | } 136 | 137 | extern void 138 | re_set_casetable(const char* table) 139 | { 140 | onigenc_set_default_caseconv_table((UChar* )table); 141 | } 142 | 143 | extern void 144 | re_mbcinit(int mb_code) 145 | { 146 | OnigEncoding enc; 147 | 148 | switch (mb_code) { 149 | case RE_MBCTYPE_ASCII: 150 | enc = ONIG_ENCODING_ASCII; 151 | break; 152 | case RE_MBCTYPE_EUC: 153 | enc = ONIG_ENCODING_EUC_JP; 154 | break; 155 | case RE_MBCTYPE_SJIS: 156 | enc = ONIG_ENCODING_SJIS; 157 | break; 158 | case RE_MBCTYPE_UTF8: 159 | enc = ONIG_ENCODING_UTF8; 160 | break; 161 | default: 162 | return ; 163 | break; 164 | } 165 | 166 | onigenc_set_default_encoding(enc); 167 | } 168 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/regposerr.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | regposerr.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2007 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "config.h" 31 | #include "onigposix.h" 32 | 33 | #ifdef HAVE_STRING_H 34 | # include 35 | #else 36 | # include 37 | #endif 38 | 39 | #if defined(__GNUC__) 40 | # define ARG_UNUSED __attribute__ ((unused)) 41 | #else 42 | # define ARG_UNUSED 43 | #endif 44 | 45 | static char* ESTRING[] = { 46 | NULL, 47 | "failed to match", /* REG_NOMATCH */ 48 | "Invalid regular expression", /* REG_BADPAT */ 49 | "invalid collating element referenced", /* REG_ECOLLATE */ 50 | "invalid character class type referenced", /* REG_ECTYPE */ 51 | "bad backslash-escape sequence", /* REG_EESCAPE */ 52 | "invalid back reference number", /* REG_ESUBREG */ 53 | "imbalanced [ and ]", /* REG_EBRACK */ 54 | "imbalanced ( and )", /* REG_EPAREN */ 55 | "imbalanced { and }", /* REG_EBRACE */ 56 | "invalid repeat range {n,m}", /* REG_BADBR */ 57 | "invalid range", /* REG_ERANGE */ 58 | "Out of memory", /* REG_ESPACE */ 59 | "? * + not preceded by valid regular expression", /* REG_BADRPT */ 60 | 61 | /* Extended errors */ 62 | "internal error", /* REG_EONIG_INTERNAL */ 63 | "invalid wide char value", /* REG_EONIG_BADWC */ 64 | "invalid argument", /* REG_EONIG_BADARG */ 65 | "multi-thread error" /* REG_EONIG_THREAD */ 66 | }; 67 | 68 | #include 69 | 70 | 71 | extern size_t 72 | regerror(int posix_ecode, const regex_t* reg ARG_UNUSED, char* buf, 73 | size_t size) 74 | { 75 | char* s; 76 | char tbuf[35]; 77 | size_t len; 78 | 79 | if (posix_ecode > 0 80 | && posix_ecode < (int )(sizeof(ESTRING) / sizeof(ESTRING[0]))) { 81 | s = ESTRING[posix_ecode]; 82 | } 83 | else if (posix_ecode == 0) { 84 | s = ""; 85 | } 86 | else { 87 | sprintf(tbuf, "undefined error code (%d)", posix_ecode); 88 | s = tbuf; 89 | } 90 | 91 | len = strlen(s) + 1; /* use strlen() because s is ascii encoding. */ 92 | 93 | if (buf != NULL && size > 0) { 94 | strncpy(buf, s, size - 1); 95 | buf[size - 1] = '\0'; 96 | } 97 | return len; 98 | } 99 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/regtrav.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | regtrav.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2004 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "regint.h" 31 | 32 | #ifdef USE_CAPTURE_HISTORY 33 | 34 | static int 35 | capture_tree_traverse(OnigCaptureTreeNode* node, int at, 36 | int(*callback_func)(int,int,int,int,int,void*), 37 | int level, void* arg) 38 | { 39 | int r, i; 40 | 41 | if (node == (OnigCaptureTreeNode* )0) 42 | return 0; 43 | 44 | if ((at & ONIG_TRAVERSE_CALLBACK_AT_FIRST) != 0) { 45 | r = (*callback_func)(node->group, node->beg, node->end, 46 | level, ONIG_TRAVERSE_CALLBACK_AT_FIRST, arg); 47 | if (r != 0) return r; 48 | } 49 | 50 | for (i = 0; i < node->num_childs; i++) { 51 | r = capture_tree_traverse(node->childs[i], at, 52 | callback_func, level + 1, arg); 53 | if (r != 0) return r; 54 | } 55 | 56 | if ((at & ONIG_TRAVERSE_CALLBACK_AT_LAST) != 0) { 57 | r = (*callback_func)(node->group, node->beg, node->end, 58 | level, ONIG_TRAVERSE_CALLBACK_AT_LAST, arg); 59 | if (r != 0) return r; 60 | } 61 | 62 | return 0; 63 | } 64 | #endif /* USE_CAPTURE_HISTORY */ 65 | 66 | extern int 67 | onig_capture_tree_traverse(OnigRegion* region, int at, 68 | int(*callback_func)(int,int,int,int,int,void*), void* arg) 69 | { 70 | #ifdef USE_CAPTURE_HISTORY 71 | return capture_tree_traverse(region->history_root, at, 72 | callback_func, 0, arg); 73 | #else 74 | return ONIG_NO_SUPPORT_CONFIG; 75 | #endif 76 | } 77 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/regversion.c: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | regversion.c - Oniguruma (regular expression library) 3 | **********************************************************************/ 4 | /*- 5 | * Copyright (c) 2002-2008 K.Kosako 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include "config.h" 31 | #include "oniguruma.h" 32 | #include 33 | 34 | extern const char* 35 | onig_version(void) 36 | { 37 | static char s[12]; 38 | 39 | sprintf(s, "%d.%d.%d", 40 | ONIGURUMA_VERSION_MAJOR, 41 | ONIGURUMA_VERSION_MINOR, 42 | ONIGURUMA_VERSION_TEENY); 43 | return s; 44 | } 45 | 46 | extern const char* 47 | onig_copyright(void) 48 | { 49 | static char s[58]; 50 | 51 | sprintf(s, "Oniguruma %d.%d.%d : Copyright (C) 2002-2008 K.Kosako", 52 | ONIGURUMA_VERSION_MAJOR, 53 | ONIGURUMA_VERSION_MINOR, 54 | ONIGURUMA_VERSION_TEENY); 55 | return s; 56 | } 57 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = encode listcap names posix simple sql syntax crnl 2 | 3 | libname = $(top_builddir)/libonig.la 4 | LDADD = $(libname) 5 | INCLUDES = -I$(top_srcdir) -I$(includedir) 6 | 7 | encode_SOURCES = encode.c 8 | listcap_SOURCES = listcap.c 9 | names_SOURCES = names.c 10 | posix_SOURCES = posix.c 11 | simple_SOURCES = simple.c 12 | sql_SOURCES = sql.c 13 | syntax_SOURCES = syntax.c 14 | 15 | 16 | sampledir = $(top_builddir)/sample 17 | 18 | test: encode listcap names posix simple sql syntax 19 | @$(sampledir)/encode 20 | @$(sampledir)/listcap 21 | @$(sampledir)/names 22 | @$(sampledir)/posix 23 | @$(sampledir)/simple 24 | @$(sampledir)/sql 25 | @$(sampledir)/syntax 26 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/crnl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * crnl.c 2007/05/30 K.Kosako 3 | * 4 | * !!! You should enable USE_CRNL_AS_LINE_TERMINATOR. !!! 5 | * 6 | * USE_CRNL_AS_LINE_TERMINATOR config test program. 7 | */ 8 | #include 9 | #include 10 | #include "oniguruma.h" 11 | 12 | static int nfail = 0; 13 | 14 | static void result(int no, int from, int to, 15 | int expected_from, int expected_to) 16 | { 17 | fprintf(stderr, "%3d: ", no); 18 | if (from == expected_from && to == expected_to) { 19 | fprintf(stderr, "Success\n"); 20 | } 21 | else { 22 | fprintf(stderr, "Fail: expected: (%d-%d), result: (%d-%d)\n", 23 | expected_from, expected_to, from, to); 24 | 25 | nfail++; 26 | } 27 | } 28 | 29 | static int 30 | x(int no, char* pattern_arg, char* str_arg, 31 | int expected_from, int expected_to) 32 | { 33 | int r; 34 | unsigned char *start, *range, *end; 35 | regex_t* reg; 36 | OnigErrorInfo einfo; 37 | OnigRegion *region; 38 | UChar *pattern, *str; 39 | 40 | pattern = (UChar* )pattern_arg; 41 | str = (UChar* )str_arg; 42 | 43 | r = onig_new(®, pattern, pattern + strlen((char* )pattern), 44 | ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, ONIG_SYNTAX_DEFAULT, &einfo); 45 | if (r != ONIG_NORMAL) { 46 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 47 | onig_error_code_to_str(s, r, &einfo); 48 | fprintf(stderr, "ERROR: %s\n", s); 49 | return -1; 50 | } 51 | 52 | region = onig_region_new(); 53 | 54 | end = str + strlen((char* )str); 55 | start = str; 56 | range = end; 57 | r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE); 58 | if (r >= 0 || r == ONIG_MISMATCH) { 59 | result(no, region->beg[0], region->end[0], expected_from, expected_to); 60 | } 61 | else if (r == ONIG_MISMATCH) { 62 | result(no, r, -1, expected_from, expected_to); 63 | } 64 | else { /* error */ 65 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 66 | onig_error_code_to_str(s, r); 67 | fprintf(stderr, "ERROR: %s\n", s); 68 | return -1; 69 | } 70 | 71 | onig_region_free(region, 1 /* 1:free self, 0:free contents only */); 72 | onig_free(reg); 73 | return 0; 74 | } 75 | 76 | static int 77 | f(int no, char* pattern_arg, char* str_arg) 78 | { 79 | return x(no, pattern_arg, str_arg, -1, -1); 80 | } 81 | 82 | extern int main(int argc, char* argv[]) 83 | { 84 | x( 1, "", "\r\n", 0, 0); 85 | x( 2, ".", "\r\n", 0, 1); 86 | f( 3, "..", "\r\n"); 87 | x( 4, "^", "\r\n", 0, 0); 88 | x( 5, "\\n^", "\r\nf", 1, 2); 89 | x( 6, "\\n^a", "\r\na", 1, 3); 90 | x( 7, "$", "\r\n", 0, 0); 91 | x( 8, "T$", "T\r\n", 0, 1); 92 | x( 9, "T$", "T\raT\r\n", 3, 4); 93 | x(10, "\\z", "\r\n", 2, 2); 94 | f(11, "a\\z", "a\r\n"); 95 | x(12, "\\Z", "\r\n", 0, 0); 96 | x(13, "\\Z", "\r\na", 3, 3); 97 | x(14, "\\Z", "\r\n\r\n\n", 4, 4); 98 | x(15, "\\Z", "\r\n\r\nX", 5, 5); 99 | x(16, "a\\Z", "a\r\n", 0, 1); 100 | x(17, "aaaaaaaaaaaaaaa\\Z", "aaaaaaaaaaaaaaa\r\n", 0, 15); 101 | x(18, "a|$", "b\r\n", 1, 1); 102 | x(19, "$|b", "\rb", 1, 2); 103 | x(20, "a$|ab$", "\r\nab\r\n", 2, 4); 104 | 105 | x(21, "a|\\Z", "b\r\n", 1, 1); 106 | x(22, "\\Z|b", "\rb", 1, 2); 107 | x(23, "a\\Z|ab\\Z", "\r\nab\r\n", 2, 4); 108 | x(24, "(?=a$).", "a\r\n", 0, 1); 109 | f(25, "(?=a$).", "a\r"); 110 | x(26, "(?!a$)..", "a\r", 0, 2); 111 | x(27, "(?<=a$).\\n", "a\r\n", 1, 3); 112 | f(28, "(? 0) { 120 | fprintf(stderr, "\n"); 121 | fprintf(stderr, "!!! You have to enable USE_CRNL_AS_LINE_TERMINATOR\n"); 122 | fprintf(stderr, "!!! in regenc.h for this test program.\n"); 123 | fprintf(stderr, "\n"); 124 | } 125 | 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/listcap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * listcap.c 3 | * 4 | * capture history (?@...) sample. 5 | */ 6 | #include 7 | #include 8 | #include "oniguruma.h" 9 | 10 | static int 11 | node_callback(int group, int beg, int end, int level, int at, void* arg) 12 | { 13 | int i; 14 | 15 | if (at != ONIG_TRAVERSE_CALLBACK_AT_FIRST) 16 | return -1; /* error */ 17 | 18 | /* indent */ 19 | for (i = 0; i < level * 2; i++) 20 | fputc(' ', stderr); 21 | 22 | fprintf(stderr, "%d: (%d-%d)\n", group, beg, end); 23 | return 0; 24 | } 25 | 26 | extern int ex(unsigned char* str, unsigned char* pattern, 27 | OnigSyntaxType* syntax) 28 | { 29 | int r; 30 | unsigned char *start, *range, *end; 31 | regex_t* reg; 32 | OnigErrorInfo einfo; 33 | OnigRegion *region; 34 | 35 | r = onig_new(®, pattern, pattern + strlen((char* )pattern), 36 | ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, syntax, &einfo); 37 | if (r != ONIG_NORMAL) { 38 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 39 | onig_error_code_to_str(s, r, &einfo); 40 | fprintf(stderr, "ERROR: %s\n", s); 41 | return -1; 42 | } 43 | 44 | fprintf(stderr, "number of captures: %d\n", onig_number_of_captures(reg)); 45 | fprintf(stderr, "number of capture histories: %d\n", 46 | onig_number_of_capture_histories(reg)); 47 | 48 | region = onig_region_new(); 49 | 50 | end = str + strlen((char* )str); 51 | start = str; 52 | range = end; 53 | r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE); 54 | if (r >= 0) { 55 | int i; 56 | 57 | fprintf(stderr, "match at %d\n", r); 58 | for (i = 0; i < region->num_regs; i++) { 59 | fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]); 60 | } 61 | fprintf(stderr, "\n"); 62 | 63 | r = onig_capture_tree_traverse(region, ONIG_TRAVERSE_CALLBACK_AT_FIRST, 64 | node_callback, (void* )0); 65 | } 66 | else if (r == ONIG_MISMATCH) { 67 | fprintf(stderr, "search fail\n"); 68 | } 69 | else { /* error */ 70 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 71 | onig_error_code_to_str(s, r); 72 | return -1; 73 | } 74 | 75 | onig_region_free(region, 1 /* 1:free self, 0:free contents only */); 76 | onig_free(reg); 77 | return 0; 78 | } 79 | 80 | 81 | extern int main(int argc, char* argv[]) 82 | { 83 | int r; 84 | OnigSyntaxType syn; 85 | 86 | static UChar* str1 = (UChar* )"((())())"; 87 | static UChar* pattern1 88 | = (UChar* )"\\g

(?@

\\(\\g\\)){0}(?@(?:\\g

)*|){0}"; 89 | 90 | static UChar* str2 = (UChar* )"x00x00x00"; 91 | static UChar* pattern2 = (UChar* )"(?@x(?@\\d+))+"; 92 | 93 | static UChar* str3 = (UChar* )"0123"; 94 | static UChar* pattern3 = (UChar* )"(?@.)(?@.)(?@.)(?@.)"; 95 | 96 | /* enable capture hostory */ 97 | onig_copy_syntax(&syn, ONIG_SYNTAX_DEFAULT); 98 | onig_set_syntax_op2(&syn, 99 | onig_get_syntax_op2(&syn) | ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY); 100 | 101 | r = ex(str1, pattern1, &syn); 102 | r = ex(str2, pattern2, &syn); 103 | r = ex(str3, pattern3, &syn); 104 | 105 | onig_end(); 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/names.c: -------------------------------------------------------------------------------- 1 | /* 2 | * names.c -- example of group name callback. 3 | */ 4 | #include 5 | #include 6 | #include "oniguruma.h" 7 | 8 | static int 9 | name_callback(const UChar* name, const UChar* name_end, 10 | int ngroup_num, int* group_nums, 11 | regex_t* reg, void* arg) 12 | { 13 | int i, gn, ref; 14 | char* s; 15 | OnigRegion *region = (OnigRegion* )arg; 16 | 17 | for (i = 0; i < ngroup_num; i++) { 18 | gn = group_nums[i]; 19 | ref = onig_name_to_backref_number(reg, name, name_end, region); 20 | s = (ref == gn ? "*" : ""); 21 | fprintf(stderr, "%s (%d): ", name, gn); 22 | fprintf(stderr, "(%d-%d) %s\n", region->beg[gn], region->end[gn], s); 23 | } 24 | return 0; /* 0: continue */ 25 | } 26 | 27 | extern int main(int argc, char* argv[]) 28 | { 29 | int r; 30 | unsigned char *start, *range, *end; 31 | regex_t* reg; 32 | OnigErrorInfo einfo; 33 | OnigRegion *region; 34 | 35 | static UChar* pattern = (UChar* )"(?a*)(?b*)(?c*)"; 36 | static UChar* str = (UChar* )"aaabbbbcc"; 37 | 38 | r = onig_new(®, pattern, pattern + strlen((char* )pattern), 39 | ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, ONIG_SYNTAX_DEFAULT, &einfo); 40 | if (r != ONIG_NORMAL) { 41 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 42 | onig_error_code_to_str(s, r, &einfo); 43 | fprintf(stderr, "ERROR: %s\n", s); 44 | return -1; 45 | } 46 | 47 | fprintf(stderr, "number of names: %d\n", onig_number_of_names(reg)); 48 | 49 | region = onig_region_new(); 50 | 51 | end = str + strlen((char* )str); 52 | start = str; 53 | range = end; 54 | r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE); 55 | if (r >= 0) { 56 | fprintf(stderr, "match at %d\n\n", r); 57 | r = onig_foreach_name(reg, name_callback, (void* )region); 58 | } 59 | else if (r == ONIG_MISMATCH) { 60 | fprintf(stderr, "search fail\n"); 61 | } 62 | else { /* error */ 63 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 64 | onig_error_code_to_str(s, r); 65 | return -1; 66 | } 67 | 68 | onig_region_free(region, 1 /* 1:free self, 0:free contents only */); 69 | onig_free(reg); 70 | onig_end(); 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * posix.c 3 | */ 4 | #include 5 | #include "onigposix.h" 6 | 7 | typedef unsigned char UChar; 8 | 9 | static int x(regex_t* reg, unsigned char* pattern, unsigned char* str) 10 | { 11 | int r, i; 12 | char buf[200]; 13 | regmatch_t pmatch[20]; 14 | 15 | r = regexec(reg, (char* )str, reg->re_nsub + 1, pmatch, 0); 16 | if (r != 0 && r != REG_NOMATCH) { 17 | regerror(r, reg, buf, sizeof(buf)); 18 | fprintf(stderr, "ERROR: %s\n", buf); 19 | return -1; 20 | } 21 | 22 | if (r == REG_NOMATCH) { 23 | fprintf(stderr, "FAIL: /%s/ '%s'\n", pattern, str); 24 | } 25 | else { 26 | fprintf(stderr, "OK: /%s/ '%s'\n", pattern, str); 27 | for (i = 0; i <= (int )reg->re_nsub; i++) { 28 | fprintf(stderr, "%d: %d-%d\n", i, pmatch[i].rm_so, pmatch[i].rm_eo); 29 | } 30 | } 31 | return 0; 32 | } 33 | 34 | extern int main(int argc, char* argv[]) 35 | { 36 | int r; 37 | char buf[200]; 38 | regex_t reg; 39 | UChar* pattern; 40 | 41 | /* default syntax (ONIG_SYNTAX_RUBY) */ 42 | pattern = (UChar* )"^a+b{2,7}[c-f]?$|uuu"; 43 | r = regcomp(®, (char* )pattern, REG_EXTENDED); 44 | if (r) { 45 | regerror(r, ®, buf, sizeof(buf)); 46 | fprintf(stderr, "ERROR: %s\n", buf); 47 | return -1; 48 | } 49 | x(®, pattern, (UChar* )"aaabbbbd"); 50 | 51 | /* POSIX Basic RE (REG_EXTENDED is not specified.) */ 52 | pattern = (UChar* )"^a+b{2,7}[c-f]?|uuu"; 53 | r = regcomp(®, (char* )pattern, 0); 54 | if (r) { 55 | regerror(r, ®, buf, sizeof(buf)); 56 | fprintf(stderr, "ERROR: %s\n", buf); 57 | return -1; 58 | } 59 | x(®, pattern, (UChar* )"a+b{2,7}d?|uuu"); 60 | 61 | /* POSIX Basic RE (REG_EXTENDED is not specified.) */ 62 | pattern = (UChar* )"^a*b\\{2,7\\}\\([c-f]\\)$"; 63 | r = regcomp(®, (char* )pattern, 0); 64 | if (r) { 65 | regerror(r, ®, buf, sizeof(buf)); 66 | fprintf(stderr, "ERROR: %s\n", buf); 67 | return -1; 68 | } 69 | x(®, pattern, (UChar* )"aaaabbbbbbd"); 70 | 71 | /* POSIX Extended RE */ 72 | onig_set_default_syntax(ONIG_SYNTAX_POSIX_EXTENDED); 73 | pattern = (UChar* )"^a+b{2,7}[c-f]?)$|uuu"; 74 | r = regcomp(®, (char* )pattern, REG_EXTENDED); 75 | if (r) { 76 | regerror(r, ®, buf, sizeof(buf)); 77 | fprintf(stderr, "ERROR: %s\n", buf); 78 | return -1; 79 | } 80 | x(®, pattern, (UChar* )"aaabbbbd)"); 81 | 82 | pattern = (UChar* )"^b."; 83 | r = regcomp(®, (char* )pattern, REG_EXTENDED | REG_NEWLINE); 84 | if (r) { 85 | regerror(r, ®, buf, sizeof(buf)); 86 | fprintf(stderr, "ERROR: %s\n", buf); 87 | return -1; 88 | } 89 | x(®, pattern, (UChar* )"a\nb\n"); 90 | 91 | regfree(®); 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/simple.c: -------------------------------------------------------------------------------- 1 | /* 2 | * simple.c 3 | */ 4 | #include 5 | #include 6 | #include "oniguruma.h" 7 | 8 | extern int main(int argc, char* argv[]) 9 | { 10 | int r; 11 | unsigned char *start, *range, *end; 12 | regex_t* reg; 13 | OnigErrorInfo einfo; 14 | OnigRegion *region; 15 | 16 | static UChar* pattern = (UChar* )"a(.*)b|[e-f]+"; 17 | static UChar* str = (UChar* )"zzzzaffffffffb"; 18 | 19 | r = onig_new(®, pattern, pattern + strlen((char* )pattern), 20 | ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, ONIG_SYNTAX_DEFAULT, &einfo); 21 | if (r != ONIG_NORMAL) { 22 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 23 | onig_error_code_to_str(s, r, &einfo); 24 | fprintf(stderr, "ERROR: %s\n", s); 25 | return -1; 26 | } 27 | 28 | region = onig_region_new(); 29 | 30 | end = str + strlen((char* )str); 31 | start = str; 32 | range = end; 33 | r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE); 34 | if (r >= 0) { 35 | int i; 36 | 37 | fprintf(stderr, "match at %d\n", r); 38 | for (i = 0; i < region->num_regs; i++) { 39 | fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]); 40 | } 41 | } 42 | else if (r == ONIG_MISMATCH) { 43 | fprintf(stderr, "search fail\n"); 44 | } 45 | else { /* error */ 46 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 47 | onig_error_code_to_str(s, r); 48 | fprintf(stderr, "ERROR: %s\n", s); 49 | return -1; 50 | } 51 | 52 | onig_region_free(region, 1 /* 1:free self, 0:free contents only */); 53 | onig_free(reg); 54 | onig_end(); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/sql.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sql.c 3 | */ 4 | #include 5 | #include 6 | #include "oniguruma.h" 7 | 8 | extern int main(int argc, char* argv[]) 9 | { 10 | static OnigSyntaxType SQLSyntax; 11 | 12 | int r; 13 | unsigned char *start, *range, *end; 14 | regex_t* reg; 15 | OnigErrorInfo einfo; 16 | OnigRegion *region; 17 | 18 | static UChar* pattern = (UChar* )"\\_%\\\\__zz"; 19 | static UChar* str = (UChar* )"a_abcabcabc\\ppzz"; 20 | 21 | onig_set_syntax_op (&SQLSyntax, ONIG_SYN_OP_VARIABLE_META_CHARACTERS); 22 | onig_set_syntax_op2 (&SQLSyntax, 0); 23 | onig_set_syntax_behavior(&SQLSyntax, 0); 24 | onig_set_syntax_options (&SQLSyntax, ONIG_OPTION_MULTILINE); 25 | onig_set_meta_char(&SQLSyntax, ONIG_META_CHAR_ESCAPE, (OnigCodePoint )'\\'); 26 | onig_set_meta_char(&SQLSyntax, ONIG_META_CHAR_ANYCHAR, (OnigCodePoint )'_'); 27 | onig_set_meta_char(&SQLSyntax, ONIG_META_CHAR_ANYTIME, 28 | ONIG_INEFFECTIVE_META_CHAR); 29 | onig_set_meta_char(&SQLSyntax, ONIG_META_CHAR_ZERO_OR_ONE_TIME, 30 | ONIG_INEFFECTIVE_META_CHAR); 31 | onig_set_meta_char(&SQLSyntax, ONIG_META_CHAR_ONE_OR_MORE_TIME, 32 | ONIG_INEFFECTIVE_META_CHAR); 33 | onig_set_meta_char(&SQLSyntax, ONIG_META_CHAR_ANYCHAR_ANYTIME, 34 | (OnigCodePoint )'%'); 35 | 36 | r = onig_new(®, pattern, pattern + strlen((char* )pattern), 37 | ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, &SQLSyntax, &einfo); 38 | if (r != ONIG_NORMAL) { 39 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 40 | onig_error_code_to_str(s, r, &einfo); 41 | fprintf(stderr, "ERROR: %s\n", s); 42 | return -1; 43 | } 44 | 45 | region = onig_region_new(); 46 | 47 | end = str + strlen((char* )str); 48 | start = str; 49 | range = end; 50 | r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE); 51 | if (r >= 0) { 52 | int i; 53 | 54 | fprintf(stderr, "match at %d\n", r); 55 | for (i = 0; i < region->num_regs; i++) { 56 | fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]); 57 | } 58 | } 59 | else if (r == ONIG_MISMATCH) { 60 | fprintf(stderr, "search fail\n"); 61 | } 62 | else { /* error */ 63 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 64 | onig_error_code_to_str(s, r); 65 | fprintf(stderr, "ERROR: %s\n", s); 66 | return -1; 67 | } 68 | 69 | onig_region_free(region, 1 /* 1:free self, 0:free contents only */); 70 | onig_free(reg); 71 | onig_end(); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/sample/syntax.c: -------------------------------------------------------------------------------- 1 | /* 2 | * syntax.c 3 | */ 4 | #include 5 | #include 6 | #include "oniguruma.h" 7 | 8 | extern int exec(OnigSyntaxType* syntax, 9 | char* apattern, char* astr) 10 | { 11 | int r; 12 | unsigned char *start, *range, *end; 13 | regex_t* reg; 14 | OnigErrorInfo einfo; 15 | OnigRegion *region; 16 | UChar* pattern = (UChar* )apattern; 17 | UChar* str = (UChar* )astr; 18 | 19 | r = onig_new(®, pattern, pattern + strlen((char* )pattern), 20 | ONIG_OPTION_DEFAULT, ONIG_ENCODING_ASCII, syntax, &einfo); 21 | if (r != ONIG_NORMAL) { 22 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 23 | onig_error_code_to_str(s, r, &einfo); 24 | fprintf(stderr, "ERROR: %s\n", s); 25 | return -1; 26 | } 27 | 28 | region = onig_region_new(); 29 | 30 | end = str + strlen((char* )str); 31 | start = str; 32 | range = end; 33 | r = onig_search(reg, str, end, start, range, region, ONIG_OPTION_NONE); 34 | if (r >= 0) { 35 | int i; 36 | 37 | fprintf(stderr, "match at %d\n", r); 38 | for (i = 0; i < region->num_regs; i++) { 39 | fprintf(stderr, "%d: (%d-%d)\n", i, region->beg[i], region->end[i]); 40 | } 41 | } 42 | else if (r == ONIG_MISMATCH) { 43 | fprintf(stderr, "search fail\n"); 44 | } 45 | else { /* error */ 46 | char s[ONIG_MAX_ERROR_MESSAGE_LEN]; 47 | onig_error_code_to_str(s, r); 48 | fprintf(stderr, "ERROR: %s\n", s); 49 | return -1; 50 | } 51 | 52 | onig_region_free(region, 1 /* 1:free self, 0:free contents only */); 53 | onig_free(reg); 54 | onig_end(); 55 | return 0; 56 | } 57 | 58 | extern int main(int argc, char* argv[]) 59 | { 60 | int r; 61 | 62 | r = exec(ONIG_SYNTAX_PERL, 63 | "\\p{XDigit}\\P{XDigit}\\p{^XDigit}\\P{^XDigit}\\p{XDigit}", 64 | "bgh3a"); 65 | 66 | r = exec(ONIG_SYNTAX_JAVA, 67 | "\\p{XDigit}\\P{XDigit}[a-c&&b-g]", "bgc"); 68 | 69 | r = exec(ONIG_SYNTAX_ASIS, 70 | "abc def* e+ g?ddd[a-rvvv] (vv){3,7}hv\\dvv(?:aczui ss)\\W\\w$", 71 | "abc def* e+ g?ddd[a-rvvv] (vv){3,7}hv\\dvv(?:aczui ss)\\W\\w$"); 72 | onig_end(); 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/st.h: -------------------------------------------------------------------------------- 1 | /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */ 2 | 3 | /* @(#) st.h 5.1 89/12/14 */ 4 | 5 | #ifndef ST_INCLUDED 6 | 7 | #define ST_INCLUDED 8 | 9 | typedef unsigned long st_data_t; 10 | #define ST_DATA_T_DEFINED 11 | 12 | typedef struct st_table st_table; 13 | 14 | struct st_hash_type { 15 | int (*compare)(); 16 | int (*hash)(); 17 | }; 18 | 19 | struct st_table { 20 | struct st_hash_type *type; 21 | int num_bins; 22 | int num_entries; 23 | struct st_table_entry **bins; 24 | }; 25 | 26 | #define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0) 27 | 28 | enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; 29 | 30 | #ifndef _ 31 | # define _(args) args 32 | #endif 33 | #ifndef ANYARGS 34 | # ifdef __cplusplus 35 | # define ANYARGS ... 36 | # else 37 | # define ANYARGS 38 | # endif 39 | #endif 40 | 41 | st_table *st_init_table _((struct st_hash_type *)); 42 | st_table *st_init_table_with_size _((struct st_hash_type *, int)); 43 | st_table *st_init_numtable _((void)); 44 | st_table *st_init_numtable_with_size _((int)); 45 | st_table *st_init_strtable _((void)); 46 | st_table *st_init_strtable_with_size _((int)); 47 | int st_delete _((st_table *, st_data_t *, st_data_t *)); 48 | int st_delete_safe _((st_table *, st_data_t *, st_data_t *, st_data_t)); 49 | int st_insert _((st_table *, st_data_t, st_data_t)); 50 | int st_lookup _((st_table *, st_data_t, st_data_t *)); 51 | int st_foreach _((st_table *, int (*)(ANYARGS), st_data_t)); 52 | void st_add_direct _((st_table *, st_data_t, st_data_t)); 53 | void st_free_table _((st_table *)); 54 | void st_cleanup_safe _((st_table *, st_data_t)); 55 | st_table *st_copy _((st_table *)); 56 | 57 | #define ST_NUMCMP ((int (*)()) 0) 58 | #define ST_NUMHASH ((int (*)()) -2) 59 | 60 | #define st_numcmp ST_NUMCMP 61 | #define st_numhash ST_NUMHASH 62 | 63 | #endif /* ST_INCLUDED */ 64 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/testc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forhappy/tinydb/26e382fc11ba3c273ef49b56d38c92732beb674d/libevhtp/oniguruma/testc.c -------------------------------------------------------------------------------- /libevhtp/oniguruma/win32/config.h: -------------------------------------------------------------------------------- 1 | #define STDC_HEADERS 1 2 | #define HAVE_SYS_TYPES_H 1 3 | #define HAVE_SYS_STAT_H 1 4 | #define HAVE_STDLIB_H 1 5 | #define HAVE_STRING_H 1 6 | #define HAVE_MEMORY_H 1 7 | #define HAVE_FLOAT_H 1 8 | #define HAVE_OFF_T 1 9 | #define SIZEOF_INT 4 10 | #define SIZEOF_SHORT 2 11 | #define SIZEOF_LONG 4 12 | #define SIZEOF_LONG_LONG 0 13 | #define SIZEOF___INT64 8 14 | #define SIZEOF_OFF_T 4 15 | #define SIZEOF_VOIDP 4 16 | #define SIZEOF_FLOAT 4 17 | #define SIZEOF_DOUBLE 8 18 | #define HAVE_PROTOTYPES 1 19 | #define TOKEN_PASTE(x,y) x##y 20 | #define HAVE_STDARG_PROTOTYPES 1 21 | #ifndef NORETURN 22 | #if _MSC_VER > 1100 23 | #define NORETURN(x) __declspec(noreturn) x 24 | #else 25 | #define NORETURN(x) x 26 | #endif 27 | #endif 28 | #define HAVE_DECL_SYS_NERR 1 29 | #define STDC_HEADERS 1 30 | #define HAVE_STDLIB_H 1 31 | #define HAVE_STRING_H 1 32 | #define HAVE_LIMITS_H 1 33 | #define HAVE_FCNTL_H 1 34 | #define HAVE_SYS_UTIME_H 1 35 | #define HAVE_MEMORY_H 1 36 | #define uid_t int 37 | #define gid_t int 38 | #define HAVE_STRUCT_STAT_ST_RDEV 1 39 | #define HAVE_ST_RDEV 1 40 | #define GETGROUPS_T int 41 | #define RETSIGTYPE void 42 | #define HAVE_ALLOCA 1 43 | #define HAVE_DUP2 1 44 | #define HAVE_MEMCMP 1 45 | #define HAVE_MEMMOVE 1 46 | #define HAVE_MKDIR 1 47 | #define HAVE_STRCASECMP 1 48 | #define HAVE_STRNCASECMP 1 49 | #define HAVE_STRERROR 1 50 | #define HAVE_STRFTIME 1 51 | #define HAVE_STRCHR 1 52 | #define HAVE_STRSTR 1 53 | #define HAVE_STRTOD 1 54 | #define HAVE_STRTOL 1 55 | #define HAVE_STRTOUL 1 56 | #define HAVE_FLOCK 1 57 | #define HAVE_VSNPRINTF 1 58 | #define HAVE_FINITE 1 59 | #define HAVE_FMOD 1 60 | #define HAVE_FREXP 1 61 | #define HAVE_HYPOT 1 62 | #define HAVE_MODF 1 63 | #define HAVE_WAITPID 1 64 | #define HAVE_CHSIZE 1 65 | #define HAVE_TIMES 1 66 | #define HAVE__SETJMP 1 67 | #define HAVE_TELLDIR 1 68 | #define HAVE_SEEKDIR 1 69 | #define HAVE_MKTIME 1 70 | #define HAVE_COSH 1 71 | #define HAVE_SINH 1 72 | #define HAVE_TANH 1 73 | #define HAVE_EXECVE 1 74 | #define HAVE_TZNAME 1 75 | #define HAVE_DAYLIGHT 1 76 | #define SETPGRP_VOID 1 77 | #define inline __inline 78 | #define NEED_IO_SEEK_BETWEEN_RW 1 79 | #define RSHIFT(x,y) ((x)>>(int)y) 80 | #define FILE_COUNT _cnt 81 | #define FILE_READPTR _ptr 82 | #define DEFAULT_KCODE KCODE_NONE 83 | #define DLEXT ".so" 84 | #define DLEXT2 ".dll" 85 | -------------------------------------------------------------------------------- /libevhtp/oniguruma/win32/testc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forhappy/tinydb/26e382fc11ba3c273ef49b56d38c92732beb674d/libevhtp/oniguruma/win32/testc.c -------------------------------------------------------------------------------- /libevhtp/test_basic.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static int 9 | output_header(evhtp_header_t * header, void * arg) { 10 | evbuf_t * buf = arg; 11 | 12 | evbuffer_add_printf(buf, "print_kvs() key = '%s', val = '%s'\n", 13 | header->key, header->val); 14 | return 0; 15 | } 16 | 17 | static evhtp_res 18 | print_kvs(evhtp_request_t * req, evhtp_headers_t * hdrs, void * arg ) { 19 | evhtp_headers_for_each(hdrs, output_header, req->buffer_out); 20 | return EVHTP_RES_OK; 21 | } 22 | 23 | void 24 | testcb(evhtp_request_t * req, void * a) { 25 | const char * str = "{\"hello\": \"world\"}"; 26 | int method= evhtp_request_get_method(req); 27 | evhtp_uri_t *uri = req->uri; 28 | evhtp_query_t *uri_query = uri->query; 29 | 30 | print_kvs(req, uri_query, NULL); 31 | evbuffer_add_printf(req->buffer_out, "%s\n%d\n", str, method); 32 | evhtp_send_reply(req, EVHTP_RES_OK); 33 | } 34 | 35 | int 36 | main(int argc, char ** argv) { 37 | evbase_t * evbase = event_base_new(); 38 | evhtp_t * htp = evhtp_new(evbase, NULL); 39 | evhtp_callback_t * cb = NULL; 40 | 41 | cb = evhtp_set_cb(htp, "/metasearch/attr_q", testcb, NULL); 42 | #ifndef EVHTP_DISABLE_EVTHR 43 | evhtp_use_threads(htp, NULL, 4, NULL); 44 | #endif 45 | evhtp_bind_socket(htp, "0.0.0.0", 8081, 1024); 46 | 47 | event_base_loop(evbase, 0); 48 | 49 | evhtp_unbind_socket(htp); 50 | evhtp_callback_free(cb); 51 | evhtp_free(htp); 52 | event_base_free(evbase); 53 | 54 | return 0; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /libevhtp/test_vhost.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void 9 | testcb(evhtp_request_t * req, void * a) { 10 | evbuffer_add_reference(req->buffer_out, "foobar", 6, NULL, NULL); 11 | evhtp_send_reply(req, EVHTP_RES_OK); 12 | } 13 | 14 | int 15 | main(int argc, char ** argv) { 16 | evbase_t * evbase = event_base_new(); 17 | evhtp_t * evhtp = evhtp_new(evbase, NULL); 18 | evhtp_t * v1 = evhtp_new(evbase, NULL); 19 | evhtp_t * v2 = evhtp_new(evbase, NULL); 20 | evhtp_callback_t * cb_1 = NULL; 21 | evhtp_callback_t * cb_2 = NULL; 22 | 23 | cb_1 = evhtp_set_cb(v1, "/host1", NULL, "host1.com"); 24 | cb_2 = evhtp_set_cb(v2, "/localhost", testcb, "localhost"); 25 | 26 | evhtp_add_vhost(evhtp, "host1.com", v1); 27 | evhtp_add_vhost(evhtp, "localhost", v2); 28 | 29 | evhtp_add_alias(v2, "127.0.0.1"); 30 | evhtp_add_alias(v2, "localhost"); 31 | evhtp_add_alias(v2, "localhost:8081"); 32 | 33 | #if 0 34 | scfg1.pemfile = "./server.pem"; 35 | scfg1.privfile = "./server.pem"; 36 | scfg2.pemfile = "./server1.pem"; 37 | scfg2.pemfile = "./server1.pem"; 38 | 39 | evhtp_ssl_init(evhtp, &scfg1); 40 | evhtp_ssl_init(v1, &scfg2); 41 | evhtp_ssl_init(v2, &scfg2); 42 | #endif 43 | 44 | evhtp_bind_socket(evhtp, "0.0.0.0", 8081, 1024); 45 | 46 | event_base_loop(evbase, 0); 47 | 48 | evhtp_unbind_socket(evhtp); 49 | evhtp_callback_free(cb_2); 50 | evhtp_callback_free(cb_1); 51 | evhtp_free(v2); 52 | evhtp_free(v1); 53 | evhtp_free(evhtp); 54 | event_base_free(evbase); 55 | 56 | return 0; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /sqlite-engine.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: leveldb-engine.c 5 | * 6 | * Description: leveldb storage engine. 7 | * 8 | * Created: 11/24/2012 03:49:34 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "sqlite-engine.h" 21 | 22 | static int put(engine_base_t *engine, 23 | const char *key, unsigned int key_len, 24 | const char *value, unsigned int value_len) 25 | { 26 | printf("hook call to sqlite put.\n"); 27 | return 0; 28 | } 29 | 30 | static char * get(engine_base_t *engine, 31 | const char *key, unsigned int key_len, 32 | unsigned int *value_len) 33 | { 34 | printf("hook call to sqlite engine get.\n"); 35 | return NULL; 36 | } 37 | 38 | static int delete(engine_base_t *engine, 39 | const char *key, unsigned int key_len) 40 | { 41 | printf("hook call to sqlite engine delete.\n"); 42 | return 0; 43 | } 44 | 45 | engine_base_t * engine_sqlite_init(void) 46 | { 47 | engine_base_t *engine = (engine_base_t *) malloc(sizeof(engine_base_t)); 48 | engine_operation_t *engine_ops = (engine_operation_t *) 49 | malloc(sizeof(engine_operation_t)); 50 | 51 | const char *engine_name = "sqlite engine v0.1"; 52 | unsigned int engine_name_len = strlen(engine_name); 53 | unsigned int version = 0x1; 54 | engine->name = malloc(sizeof(char) * (engine_name_len + 1)); 55 | memset(engine->name, 0, (engine_name_len + 1)); 56 | strncpy(engine->name, engine_name, engine_name_len); 57 | engine->version = version; 58 | 59 | engine_ops->put = put; 60 | engine_ops->get = get; 61 | engine_ops->delete = delete; 62 | 63 | engine->engine_ops = engine_ops; 64 | 65 | return engine; 66 | } 67 | -------------------------------------------------------------------------------- /sqlite-engine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: sqlite-engine.h 5 | * 6 | * Description: sqlite storage engine 7 | * 8 | * Created: 11/24/2012 03:49:23 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | 16 | #ifndef SQLITE_ENGINE_H 17 | #define SQLITE_ENGINE_H 18 | #include "csas.h" 19 | 20 | extern engine_base_t * engine_sqlite_init(); 21 | 22 | #endif /* SQLITE_ENGINE_H */ 23 | -------------------------------------------------------------------------------- /t.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ============================================================================= 3 | * 4 | * Filename: main.c 5 | * 6 | * Description: main routine. 7 | * 8 | * Created: 11/24/2012 05:58:22 PM 9 | * 10 | * Author: Fu Haiping (forhappy), haipingf@gmail.com 11 | * Company: ICT ( Institute Of Computing Technology, CAS ) 12 | * 13 | * ============================================================================= 14 | */ 15 | #include 16 | #include 17 | 18 | #include "leveldb-engine.h" 19 | #include "inmemory-engine.h" 20 | #define NUM_OPERATIONS 65536 21 | 22 | int main(int args, const char *argv[]) 23 | { 24 | char buf[1024] = {0}; 25 | char *value = NULL; 26 | unsigned int value_len = -1; 27 | 28 | #if 0 // leveldb engine. 29 | engine_base_t *engine_leveldb = (engine_base_t *)engine_leveldb_init(); 30 | csas_context_t *context = csas_init(engine_leveldb); 31 | #endif 32 | 33 | #if 1 // in-memory engine. 34 | engine_base_t *engine_inmemory = (engine_base_t *)engine_inmemory_init(); 35 | csas_context_t *context = csas_init(engine_inmemory); 36 | #endif 37 | 38 | 39 | #if 1 40 | /* put operation. */ 41 | 42 | char key[64] = {0}; 43 | char val[64] = {0}; 44 | for (int i = 0; i < NUM_OPERATIONS; i++) { 45 | sprintf(key, "%d%d%d%d%d", i, i + 1, i + 2, i + 3, i + 4); 46 | sprintf(val, "%d%d%d%d%d", i, i + 1, i + 2, i + 3, i + 4 ); 47 | csas_put(context, key, strlen(key), val, strlen(val)); 48 | } 49 | #endif 50 | 51 | #if 1 52 | /* get operation. */ 53 | value = csas_get(context, "910111213", 5, &value_len); 54 | snprintf(buf, value_len + 1, "%s", value); 55 | printf("value: %s\tlength: %d\n", buf, strlen(buf)); 56 | free(value); 57 | 58 | #endif 59 | 60 | #if 1 61 | /* delete operation. */ 62 | csas_delete(context, "12345", 5); 63 | /* verify deletion. */ 64 | value = csas_get(context, "12345", 5, &value_len); 65 | snprintf(buf, value_len + 1, "%s", value); 66 | printf("value: %s\tlength: %d\n", buf, strlen(buf)); 67 | free(value); 68 | #endif 69 | 70 | return 0; 71 | 72 | } 73 | --------------------------------------------------------------------------------