diff options
| author | git commit -m first <[email protected]> | 2019-06-12 15:06:20 +0800 |
|---|---|---|
| committer | git commit -m first <[email protected]> | 2019-06-12 15:06:20 +0800 |
| commit | 10e810b629148dcc96159d96045edccb94af600a (patch) | |
| tree | d8e4724d2f1ea208f05fa6d96be8ad6413b6df3b /inc | |
add source code
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/cJSON.h | 149 | ||||
| -rw-r--r-- | inc/comm_audit.h | 489 | ||||
| -rw-r--r-- | inc/identify.h | 35 | ||||
| -rw-r--r-- | inc/maxminddb.h | 241 | ||||
| -rw-r--r-- | inc/project_requirement.h | 112 |
5 files changed, 1026 insertions, 0 deletions
diff --git a/inc/cJSON.h b/inc/cJSON.h new file mode 100644 index 0000000..466d10d --- /dev/null +++ b/inc/cJSON.h @@ -0,0 +1,149 @@ +/* + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef cJSON__h +#define cJSON__h + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* cJSON Types: */ +#define cJSON_False 0 +#define cJSON_True 1 +#define cJSON_NULL 2 +#define cJSON_Number 3 +#define cJSON_String 4 +#define cJSON_Array 5 +#define cJSON_Object 6 + +#define cJSON_IsReference 256 +#define cJSON_StringIsConst 512 + +/* The cJSON structure: */ +typedef struct cJSON { + struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + + int type; /* The type of the item, as above. */ + + char *valuestring; /* The item's string, if type==cJSON_String */ + int valueint; /* The item's number, if type==cJSON_Number */ + double valuedouble; /* The item's number, if type==cJSON_Number */ + + char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ +} cJSON; + +typedef struct cJSON_Hooks { + void *(*malloc_fn)(size_t sz); + void (*free_fn)(void *ptr); +} cJSON_Hooks; + +/* Supply malloc, realloc and free functions to cJSON */ +extern void cJSON_InitHooks(cJSON_Hooks* hooks); + + +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ +extern cJSON *cJSON_Parse(const char *value); +/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ +extern char *cJSON_Print(cJSON *item); +/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ +extern char *cJSON_PrintUnformatted(cJSON *item); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +extern char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt); +/* Delete a cJSON entity and all subentities. */ +extern void cJSON_Delete(cJSON *c); + +/* Returns the number of items in an array (or object). */ +extern int cJSON_GetArraySize(cJSON *array); +/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ +extern cJSON *cJSON_GetArrayItem(cJSON *array,int item); +/* Get item "string" from object. Case insensitive. */ +extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); + +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +extern const char *cJSON_GetErrorPtr(void); + +/* These calls create a cJSON item of the appropriate type. */ +extern cJSON *cJSON_CreateNull(void); +extern cJSON *cJSON_CreateTrue(void); +extern cJSON *cJSON_CreateFalse(void); +extern cJSON *cJSON_CreateBool(int b); +extern cJSON *cJSON_CreateNumber(double num); +extern cJSON *cJSON_CreateString(const char *string); +extern cJSON *cJSON_CreateArray(void); +extern cJSON *cJSON_CreateObject(void); + +/* These utilities create an Array of count items. */ +extern cJSON *cJSON_CreateIntArray(const int *numbers,int count); +extern cJSON *cJSON_CreateFloatArray(const float *numbers,int count); +extern cJSON *cJSON_CreateDoubleArray(const double *numbers,int count); +extern cJSON *cJSON_CreateStringArray(const char **strings,int count); + +/* Append item to the specified array/object. */ +extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); +extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); +extern void cJSON_AddItemToObjectCS(cJSON *object,const char *string,cJSON *item); /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object */ +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); + +/* Remove/Detatch items from Arrays/Objects. */ +extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which); +extern void cJSON_DeleteItemFromArray(cJSON *array,int which); +extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); +extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); + +/* Update array items. */ +extern void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem); /* Shifts pre-existing items to the right. */ +extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem); +extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); + +/* Duplicate a cJSON item */ +extern cJSON *cJSON_Duplicate(cJSON *item,int recurse); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will +need to be released. With recurse!=0, it will duplicate any children connected to the item. +The item->next and ->prev pointers are always zero on return from Duplicate. */ + +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated); + +extern void cJSON_Minify(char *json); + +/* Macros for creating things quickly. */ +#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) +#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) +#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) +#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) +#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) +#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) + +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) +#define cJSON_SetNumberValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/inc/comm_audit.h b/inc/comm_audit.h new file mode 100644 index 0000000..be9038d --- /dev/null +++ b/inc/comm_audit.h @@ -0,0 +1,489 @@ +/*
+ * COMM_AUDIT.h
+ *
+ * Created on: 2017-8-14
+ * Last Modified: 2017-11-23
+ * Author: zhangxi
+ */
+
+#ifndef _COMM_AUDIT_H_
+#define _COMM_AUDIT_H_
+
+#include <sys/types.h>
+#include <time.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+#include <string.h>
+#include <dirent.h>
+#include <assert.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+
+#include <MESA/stream.h>
+#include <MESA/MESA_handle_logger.h>
+#include <MESA/MESA_htable.h>
+#include <MESA/MESA_prof_load.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define IPLEN (16)
+#define MACLEN (60)
+#define MB (1024 * 1024)
+#define MAX_LEN (1024)
+
+#define STREAM_TYPE(num)\
+({\
+ string type;\
+ switch(num)\
+ {\
+ case 0:\
+ type="NON";\
+ break;\
+ case 1:\
+ type="TCP";\
+ break;\
+ case 2:\
+ type="UDP";\
+ break;\
+ case 3:\
+ type="VLAN";\
+ break;\
+ case 4:\
+ type="SOCKS4";\
+ break;\
+ case 5:\
+ type="SOCKS5";\
+ break;\
+ case 6:\
+ type="HTTP_PROXY";\
+ break;\
+ case 7:\
+ type="PPPOE";\
+ break;\
+ case 8:\
+ type="L2TP";\
+ break;\
+ case 9:\
+ type="OPENVPN";\
+ break;\
+ case 10:\
+ type="PPTP";\
+ break;\
+ case 11:\
+ type="ISAKMP";\
+ break;\
+ }\
+ (type);\
+})
+
+
+#define APP_TYPE(num)\
+({\
+ string type;\
+ switch(num)\
+ {\
+ case 227:\
+ type="HTTP";\
+ break;\
+ case 256:\
+ type="DNS";\
+ break;\
+ case 314:\
+ type="SSL";\
+ break;\
+ case 229:\
+ type="FTP";\
+ break;\
+ case 243:\
+ type="SMTP";\
+ break;\
+ case 242:\
+ type="POP3";\
+ break;\
+ case 244:\
+ type="IMAP";\
+ break;\
+ case 1:\
+ type="BT";\
+ break;\
+ case 145:\
+ type="RTSP";\
+ break;\
+ case 1054:\
+ type="SSH";\
+ break;\
+ case 1058:\
+ type="telnet";\
+ break;\
+ case 312:\
+ type="socks4";\
+ break;\
+ case 313:\
+ type="socks5";\
+ break;\
+ case 15:\
+ type="fasttrack";\
+ break;\
+ case 17:\
+ type="filetopia";\
+ break;\
+ case 18:\
+ type="flashget";\
+ break;\
+ case 954:\
+ type="oracle";\
+ break;\
+ case 1002:\
+ type="skinny";\
+ break;\
+ case 1023:\
+ type="yyvoice";\
+ break;\
+ case 28:\
+ type="imesh";\
+ break;\
+ case 975:\
+ type="iax";\
+ break;\
+ case 986:\
+ type="mgcp";\
+ break;\
+ case 997:\
+ type="rtcp";\
+ break;\
+ case 998:\
+ type="rtp";\
+ break;\
+ case 1042:\
+ type="citrix";\
+ break;\
+ case 1043:\
+ type="corba";\
+ break;\
+ case 1044:\
+ type="dameware";\
+ break;\
+ case 1050:\
+ type="pcanywhere";\
+ break;\
+ case 1051:\
+ type="qq_rdp";\
+ break;\
+ case 1056:\
+ type="teamview";\
+ break;\
+ case 1060:\
+ type="vnc";\
+ break;\
+ case 1063:\
+ type="xdmcp";\
+ break;\
+ case 1068:\
+ type="rdp";\
+ break;\
+ case 4:\
+ type="aimini";\
+ break;\
+ case 41:\
+ type="poco";\
+ break;\
+ case 46:\
+ type="qqdownload";\
+ break;\
+ case 5:\
+ type="applejuice";\
+ break;\
+ case 55:\
+ type="stealthnet";\
+ break;\
+ case 59:\
+ type="winmx";\
+ break;\
+ case 66:\
+ type="emule";\
+ break;\
+ case 72:\
+ type="kuwo";\
+ break;\
+ case 80:\
+ type="thunder";\
+ break;\
+ case 138:\
+ type="qvod";\
+ break;\
+ case 953:\
+ type="mysql";\
+ break;\
+ case 101:\
+ type="icecast";\
+ break;\
+ case 113:\
+ type="mms";\
+ break;\
+ case 127:\
+ type="pplive";\
+ break;\
+ case 129:\
+ type="ppstream";\
+ break;\
+ case 151:\
+ type="sopcast";\
+ break;\
+ case 153:\
+ type="steam";\
+ break;\
+ case 157:\
+ type="tvants";\
+ break;\
+ case 199:\
+ type="iqiyi";\
+ break;\
+ case 208:\
+ type="sohutv";\
+ break;\
+ case 223:\
+ type="iku";\
+ break;\
+ case 228:\
+ type="cvs";\
+ break;\
+ case 232:\
+ type="ipp";\
+ break;\
+ case 235:\
+ type="nfs";\
+ break;\
+ case 236:\
+ type="rsync";\
+ break;\
+ case 237:\
+ type="smb";\
+ break;\
+ case 239:\
+ type="tftp";\
+ break;\
+ case 247:\
+ type="lotus_notes";\
+ break;\
+ case 251:\
+ type="bgp";\
+ break;\
+ case 254:\
+ type="dhcp";\
+ break;\
+ case 259:\
+ type="finger";\
+ break;\
+ case 264:\
+ type="kerberos";\
+ break;\
+ case 265:\
+ type="ldap";\
+ break;\
+ case 266:\
+ type="mdns";\
+ break;\
+ case 268:\
+ type="nntp";\
+ break;\
+ case 276:\
+ type="snmp";\
+ break;\
+ case 277:\
+ type="ssdp";\
+ break;\
+ case 278:\
+ type="syslog";\
+ break;\
+ case 281:\
+ type="whois";\
+ break;\
+ case 288:\
+ type="radius";\
+ break;\
+ case 1150:\
+ type="quic";\
+ break;\
+ case 295:\
+ type="ikev1";\
+ break;\
+ case 296:\
+ type="ikev2";\
+ break;\
+ case 304:\
+ type="l2tp";\
+ break;\
+ case 307:\
+ type="openvpn";\
+ break;\
+ case 309:\
+ type="pptp";\
+ break;\
+ case 315:\
+ type="stun";\
+ break;\
+ case 317:\
+ type="teredo";\
+ break;\
+ case 318:\
+ type="tor";\
+ break;\
+ case 328:\
+ type="xunyou_speedup";\
+ break;\
+ case 360:\
+ type="msn";\
+ break;\
+ case 368:\
+ type="popo";\
+ break;\
+ case 404:\
+ type="qq";\
+ break;\
+ case 410:\
+ type="sinauc";\
+ break;\
+ case 467:\
+ type="qqbattle";\
+ break;\
+ case 484:\
+ type="quake";\
+ break;\
+ case 507:\
+ type="xbox";\
+ break;\
+ case 690:\
+ type="wow";\
+ break;\
+ case 1074:\
+ type="gtp";\
+ break;\
+ default:\
+ type="unknown";\
+ break;\
+ }\
+ (type);\
+})
+
+#define TCP_FLAG(num)\
+({\
+ string flag;\
+ int n = num;\
+ if(n >= 32)\
+ {\
+ flag += "U";\
+ n -= 32;\
+ }\
+ if(n >= 16)\
+ {\
+ flag += "A";\
+ n -= 16;\
+ }\
+ if(n >= 8)\
+ {\
+ flag += "P";\
+ n -= 8;\
+ }\
+ if(n >= 4)\
+ {\
+ flag += "R";\
+ n -= 4;\
+ }\
+ if(n >= 2)\
+ {\
+ flag += "S";\
+ n -= 2;\
+ }\
+ if(n >= 1)\
+ {\
+ flag += "F";\
+ n -= 1;\
+ }\
+ (flag);\
+})
+
+
+typedef struct _htable_data_t
+{
+
+ unsigned int inner_ip;
+ unsigned int ext_ip;
+ unsigned short inner_port;
+ unsigned short ext_port;
+ char inner_mac[MACLEN];
+ char ext_mac[MACLEN];
+ unsigned char protocol;
+ unsigned short app;
+
+ unsigned short tcp_flag;
+ unsigned long long in_bytes;
+ unsigned long long out_bytes;
+ unsigned long long in_pkts;
+ unsigned long long out_pkts;
+ long long start_time;
+ long long end_time;
+
+}htable_data_t;
+
+
+typedef struct htable_search_arg
+{
+ struct streaminfo * stream;
+ void * packet;
+ int is_end;
+}htable_search_arg;
+
+
+typedef struct comm_prog_configure_t
+{
+ int htable_size;
+ int sleep;
+ int read_interval;
+ int write_interval;
+ int write_max_num;
+ int flag; //0:use mmd filter;1:no filter;2:no have any data
+ // char * log_path;
+ char * tmp_log_path;
+ char * upload_pz_path;
+ char * mmdb_path;
+}comm_prog_configure_t;
+
+typedef struct comm_prog_runtime_parameter_t
+{
+ int project_id_pro;
+ int thread_num;
+ void* log_handle;
+ long long last_send_time;
+ pthread_mutex_t mutex;
+ MESA_htable_handle **htable_handle;
+ // MESA_htable_handle htable_handle1;
+ // MESA_htable_handle htable_handle2;
+ // MESA_htable_handle wtable;
+ // MESA_htable_handle rtable;
+
+}comm_prog_runtime_parameter_t;
+
+typedef struct del_para_t
+{
+ char * writetime;
+ int thread_seq;
+}del_para_t;
+
+int COMM_AUDIT_INIT();
+char COMM_AUDIT_ENTRY(struct streaminfo *, void **, int , void *);
+void COMM_AUDIT_DESTROY();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/inc/identify.h b/inc/identify.h new file mode 100644 index 0000000..2912b8d --- /dev/null +++ b/inc/identify.h @@ -0,0 +1,35 @@ +#ifndef _IDENTIFY_PROC_H_
+#define _IDENTIFY_PROC_H_
+
+
+#define DNTY_PPROJECT_TYPE "struct"
+
+#define DNTY_PPROJECT_AREA "PPROJECT_AREA"
+#define DNTY_PPROJECT_PRO "PPROJECT_PRO"
+
+
+#define DNTY_AREA_OUTSIDE 700000
+#define DNTY_AREA_UNKONW 0
+
+
+typedef struct _dnty_area_info
+{
+ unsigned int client_area;
+ unsigned int server_area;
+}stDntyAreaInfo;
+
+
+typedef struct _dnty_protocol_info
+{
+ unsigned char trans_proto;
+ unsigned char communicate_mode:7;
+ unsigned char v6:1;
+ unsigned short protocol_type;
+ unsigned short application_class;
+ unsigned char cmd_type;
+ unsigned char reserved;
+}stDntyProInfo;
+
+
+#endif
+
diff --git a/inc/maxminddb.h b/inc/maxminddb.h new file mode 100644 index 0000000..de1fdf8 --- /dev/null +++ b/inc/maxminddb.h @@ -0,0 +1,241 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef MAXMINDDB_H +#define MAXMINDDB_H + +/* Request POSIX.1-2008. However, we want to remain compatible with + * POSIX.1-2001 (since we have been historically and see no reason to drop + * compatibility). By requesting POSIX.1-2008, we can conditionally use + * features provided by that standard if the implementation provides it. We can + * check for what the implementation provides by checking the _POSIX_VERSION + * macro after including unistd.h. If a feature is in POSIX.1-2008 but not + * POSIX.1-2001, check that macro before using the feature (or check for the + * feature directly if possible). */ +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#include "maxminddb_config.h" +#include <stdarg.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <sys/types.h> + +#ifdef _WIN32 +#include <winsock2.h> +#include <ws2tcpip.h> +/* libmaxminddb package version from configure */ +#define PACKAGE_VERSION "1.3.2" + +typedef ADDRESS_FAMILY sa_family_t; + +#if defined(_MSC_VER) +/* MSVC doesn't define signed size_t, copy it from configure */ +#define ssize_t SSIZE_T + +/* MSVC doesn't support restricted pointers */ +#define restrict +#endif +#else +#include <netdb.h> +#include <netinet/in.h> +#include <sys/socket.h> +#endif + +#define MMDB_DATA_TYPE_EXTENDED (0) +#define MMDB_DATA_TYPE_POINTER (1) +#define MMDB_DATA_TYPE_UTF8_STRING (2) +#define MMDB_DATA_TYPE_DOUBLE (3) +#define MMDB_DATA_TYPE_BYTES (4) +#define MMDB_DATA_TYPE_UINT16 (5) +#define MMDB_DATA_TYPE_UINT32 (6) +#define MMDB_DATA_TYPE_MAP (7) +#define MMDB_DATA_TYPE_INT32 (8) +#define MMDB_DATA_TYPE_UINT64 (9) +#define MMDB_DATA_TYPE_UINT128 (10) +#define MMDB_DATA_TYPE_ARRAY (11) +#define MMDB_DATA_TYPE_CONTAINER (12) +#define MMDB_DATA_TYPE_END_MARKER (13) +#define MMDB_DATA_TYPE_BOOLEAN (14) +#define MMDB_DATA_TYPE_FLOAT (15) + +#define MMDB_RECORD_TYPE_SEARCH_NODE (0) +#define MMDB_RECORD_TYPE_EMPTY (1) +#define MMDB_RECORD_TYPE_DATA (2) +#define MMDB_RECORD_TYPE_INVALID (3) + +/* flags for open */ +#define MMDB_MODE_MMAP (1) +#define MMDB_MODE_MASK (7) + +/* error codes */ +#define MMDB_SUCCESS (0) +#define MMDB_FILE_OPEN_ERROR (1) +#define MMDB_CORRUPT_SEARCH_TREE_ERROR (2) +#define MMDB_INVALID_METADATA_ERROR (3) +#define MMDB_IO_ERROR (4) +#define MMDB_OUT_OF_MEMORY_ERROR (5) +#define MMDB_UNKNOWN_DATABASE_FORMAT_ERROR (6) +#define MMDB_INVALID_DATA_ERROR (7) +#define MMDB_INVALID_LOOKUP_PATH_ERROR (8) +#define MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR (9) +#define MMDB_INVALID_NODE_NUMBER_ERROR (10) +#define MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR (11) + +#if !(MMDB_UINT128_IS_BYTE_ARRAY) +#if MMDB_UINT128_USING_MODE +typedef unsigned int mmdb_uint128_t __attribute__ ((__mode__(TI))); +#else +typedef unsigned __int128 mmdb_uint128_t; +#endif +#endif + +/* This is a pointer into the data section for a given IP address lookup */ +typedef struct MMDB_entry_s { + struct MMDB_s *mmdb; + uint32_t offset; +} MMDB_entry_s; + +typedef struct MMDB_lookup_result_s { + bool found_entry; + MMDB_entry_s entry; + uint16_t netmask; +} MMDB_lookup_result_s; + +typedef struct MMDB_entry_data_s { + bool has_data; + union { + uint32_t pointer; + const char *utf8_string; + double double_value; + const uint8_t *bytes; + uint16_t uint16; + uint32_t uint32; + int32_t int32; + uint64_t uint64; +#if MMDB_UINT128_IS_BYTE_ARRAY + uint8_t uint128[16]; +#else + mmdb_uint128_t uint128; +#endif + bool boolean; + float float_value; + }; + /* This is a 0 if a given entry cannot be found. This can only happen + * when a call to MMDB_(v)get_value() asks for hash keys or array + * indices that don't exist. */ + uint32_t offset; + /* This is the next entry in the data section, but it's really only + * relevant for entries that part of a larger map or array + * struct. There's no good reason for an end user to look at this + * directly. */ + uint32_t offset_to_next; + /* This is only valid for strings, utf8_strings or binary data */ + uint32_t data_size; + /* This is an MMDB_DATA_TYPE_* constant */ + uint32_t type; +} MMDB_entry_data_s; + +/* This is the return type when someone asks for all the entry data in a map or array */ +typedef struct MMDB_entry_data_list_s { + MMDB_entry_data_s entry_data; + struct MMDB_entry_data_list_s *next; + void *pool; +} MMDB_entry_data_list_s; + +typedef struct MMDB_description_s { + const char *language; + const char *description; +} MMDB_description_s; + +typedef struct MMDB_metadata_s { + uint32_t node_count; + uint16_t record_size; + uint16_t ip_version; + const char *database_type; + struct { + size_t count; + const char **names; + } languages; + uint16_t binary_format_major_version; + uint16_t binary_format_minor_version; + uint64_t build_epoch; + struct { + size_t count; + MMDB_description_s **descriptions; + } description; +} MMDB_metadata_s; + +typedef struct MMDB_ipv4_start_node_s { + uint16_t netmask; + uint32_t node_value; +} MMDB_ipv4_start_node_s; + +typedef struct MMDB_s { + uint32_t flags; + const char *filename; + ssize_t file_size; + const uint8_t *file_content; + const uint8_t *data_section; + uint32_t data_section_size; + const uint8_t *metadata_section; + uint32_t metadata_section_size; + uint16_t full_record_byte_size; + uint16_t depth; + MMDB_ipv4_start_node_s ipv4_start_node; + MMDB_metadata_s metadata; +} MMDB_s; + +typedef struct MMDB_search_node_s { + uint64_t left_record; + uint64_t right_record; + uint8_t left_record_type; + uint8_t right_record_type; + MMDB_entry_s left_record_entry; + MMDB_entry_s right_record_entry; +} MMDB_search_node_s; + + /* *INDENT-OFF* */ + /* --prototypes automatically generated by dev-bin/regen-prototypes.pl - don't remove this comment */ + extern int MMDB_open(const char *const filename, uint32_t flags, MMDB_s *const mmdb); + extern MMDB_lookup_result_s MMDB_lookup_string(MMDB_s *const mmdb, + const char *const ipstr, + int *const gai_error, + int *const mmdb_error); + extern MMDB_lookup_result_s MMDB_lookup_sockaddr( + MMDB_s *const mmdb, + const struct sockaddr *const sockaddr, + int *const mmdb_error); + extern int MMDB_read_node(MMDB_s *const mmdb, uint32_t node_number, + MMDB_search_node_s *const node); + extern int MMDB_get_value(MMDB_entry_s *const start, + MMDB_entry_data_s *const entry_data, + ...); + extern int MMDB_vget_value(MMDB_entry_s *const start, + MMDB_entry_data_s *const entry_data, + va_list va_path); + extern int MMDB_aget_value(MMDB_entry_s *const start, + MMDB_entry_data_s *const entry_data, + const char *const *const path); + extern int MMDB_get_metadata_as_entry_data_list( + MMDB_s *const mmdb, MMDB_entry_data_list_s **const entry_data_list); + extern int MMDB_get_entry_data_list( + MMDB_entry_s *start, MMDB_entry_data_list_s **const entry_data_list); + extern void MMDB_free_entry_data_list(MMDB_entry_data_list_s *const entry_data_list); + extern void MMDB_close(MMDB_s *const mmdb); + extern const char *MMDB_lib_version(void); + extern int MMDB_dump_entry_data_list(FILE *const stream, + MMDB_entry_data_list_s *const entry_data_list, + int indent); + extern const char *MMDB_strerror(int error_code); + /* --prototypes end - don't remove this comment-- */ + /* *INDENT-ON* */ + +#endif /* MAXMINDDB_H */ + +#ifdef __cplusplus +} +#endif diff --git a/inc/project_requirement.h b/inc/project_requirement.h new file mode 100644 index 0000000..3159b36 --- /dev/null +++ b/inc/project_requirement.h @@ -0,0 +1,112 @@ +#ifndef _PROJECT_REQUIREMENT_H_
+#define _PROJECT_REQUIREMENT_H_
+
+#include <MESA/stream.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define PROJECT_REQ_NAME_MAX_LEN (64)
+
+typedef void (project_req_free_t)(int thread_seq, void *project_req_value);
+
+#define PROJECT_VAL_TYPE_CHAR "char"
+#define PROJECT_VAL_TYPE_SHORT "short"
+#define PROJECT_VAL_TYPE_INT "int"
+#define PROJECT_VAL_TYPE_LONG "long"
+#define PROJECT_VAL_TYPE_STRUCT "struct"
+
+
+int project_requirement_global_init(void);
+
+/*
+ must call this function in initialization, only one times,
+ the 'free_cb' should be NULL if 'project_req_val_type' is simple type,
+ otherwise please implement it by youself.
+
+ args:
+ project_req_name: for example, "terminal_tag", "stream_id".
+ project_req_val_type: support "char","short","int","long","struct".
+ free_cb: used to free resource when 'project_req_val_type' is "struct".
+
+
+ return value: 'project_req_id' of this project_req_name, must use this id in following functions.
+ >= 0 : success;
+ -1 : error.
+*/
+int project_producer_register(const char *project_req_name, const char *project_req_val_type, project_req_free_t *free_cb);
+
+/* args and return value same with project_producer_register() */
+int project_customer_register(const char *project_req_name, const char *project_req_val_type);
+
+/*
+ Function project_req_add_struct: 'project_req_value' must be a pointer to heap memory(obtain by malloc).
+
+ return value:
+ 0 : success;
+ -1: error.
+*/
+int project_req_add_char(struct streaminfo *stream, int project_req_id, char project_req_value);
+int project_req_add_short(struct streaminfo *stream, int project_req_id, short project_req_value);
+int project_req_add_int(struct streaminfo *stream, int project_req_id, int project_req_value);
+int project_req_add_long(struct streaminfo *stream, int project_req_id, long project_req_value);
+
+int project_req_add_uchar(struct streaminfo *stream, int project_req_id, unsigned char project_req_value);
+int project_req_add_ushort(struct streaminfo *stream, int project_req_id, unsigned short project_req_value);
+int project_req_add_uint(struct streaminfo *stream, int project_req_id, unsigned int project_req_value);
+int project_req_add_ulong(struct streaminfo *stream, int project_req_id, unsigned long project_req_value);
+
+
+int project_req_add_struct(struct streaminfo *stream, int project_req_id, const void *project_req_value);
+
+
+/*
+ return value:
+ -1(or all bit is '1' in Hex mode, 0xFF, 0xFFFF):
+ maybe error, maybe the actual project_req_value is -1 indeed,
+ must check tht 'errno' in this case,
+ the 'errno' will be set to 'ERANGE' indicate an error.
+ others: success.
+
+ for example:
+ int value = project_req_get_int(stream, req_id);
+ if((-1 == value) && (ERANGE == errno)){
+ error_handle();
+ }else{
+ do_somgthing();
+ }
+
+ for example2:
+ unsigned short value = project_req_get_ushort(stream, req_id);
+ if((0xFF == value) && (ERANGE == errno)){
+ error_handle();
+ }else{
+ do_somgthing();
+ }
+
+*/
+char project_req_get_char(const struct streaminfo *stream, int project_req_id);
+short project_req_get_short(const struct streaminfo *stream, int project_req_id);
+int project_req_get_int(const struct streaminfo *stream, int project_req_id);
+long project_req_get_long(const struct streaminfo *stream, int project_req_id);
+
+unsigned char project_req_get_uchar(const struct streaminfo *stream, int project_req_id);
+unsigned short project_req_get_ushort(const struct streaminfo *stream, int project_req_id);
+unsigned int project_req_get_uint(const struct streaminfo *stream, int project_req_id);
+unsigned long project_req_get_ulong(const struct streaminfo *stream, int project_req_id);
+
+/*
+ return value:
+ NULL : error;
+ others: success.
+*/
+const void *project_req_get_struct(const struct streaminfo *stream, int project_req_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
|
