hewei %!s(int64=6) %!d(string=hai) anos
pai
achega
0e1c67caf4
Modificáronse 5 ficheiros con 470 adicións e 6 borrados
  1. 17 1
      base/hmutex.h
  2. 3 3
      base/hstring.h
  3. 448 0
      docs/apis.md
  4. 1 1
      http/http_content.h
  5. 1 1
      http/server/http_page.h

+ 17 - 1
base/hmutex.h

@@ -135,6 +135,19 @@ using std::condition_variable;
 using std::lock_guard;
 using std::unique_lock;
 
+namespace hv {
+
+class MutexLock {
+public:
+    MutexLock() { hmutex_init(&_mutex); }
+    ~MutexLock() { hmutex_destroy(&_mutex); }
+
+    void lock() { hmutex_lock(&_mutex); }
+    void unlock() { hmutex_unlock(&_mutex); }
+protected:
+    hmutex_t _mutex;
+};
+
 class RWLock {
 public:
     RWLock()    { hrwlock_init(&_rwlock); }
@@ -148,6 +161,9 @@ public:
 protected:
     hrwlock_t   _rwlock;
 };
-#endif
+
+} // end namespace
+
+#endif // __cplusplus
 
 #endif // HV_MUTEX_H_

+ 3 - 3
base/hstring.h

@@ -44,13 +44,13 @@ public:
 }
 
 #ifdef USE_MULTIMAP
-#define HMAP    std::MultiMap
+#define HV_MAP      std::MultiMap
 #else
-#define HMAP    std::map
+#define HV_MAP      std::map
 #endif
 
 // KeyValue
-typedef HMAP<std::string, std::string> KeyValue;
+typedef HV_MAP<std::string, std::string> KeyValue;
 
 // std::map<std::string, std::string, StringCaseLess>
 class StringCaseLess : public std::binary_function<std::string, std::string, bool> {

+ 448 - 0
docs/apis.md

@@ -0,0 +1,448 @@
+#  c
+## functions
+### hversion.h
+- get_compile_version
+- version_atoi
+- version_itoa
+
+### hmath.h
+- floor2e
+- ceil2e
+
+### hbase.h
+- getboolean
+- safe_malloc
+- safe_calloc
+- safe_realloc
+- safe_zalloc
+- safe_strncpy
+- safe_strncat
+- strlower
+- strupper
+- strreverse
+- strstartswith
+- strendswith
+- strcontains
+
+### htime.h
+- calc_next_timeout
+- datetime_now
+- datetime_past
+- datetime_future
+- datetime_mktime
+- datetime_fmt
+- gmtime_fmt
+- gettick
+- gethrtime
+- sleep
+- msleep
+- get_compile_datetime
+- days_of_month
+- month_atoi
+- month_itoa
+- weekday_atoi
+- weekday_itoa
+
+### hlog.h
+- default_logger
+- file_logger
+- stderr_logger
+- stdout_logger
+- logger_create
+- logger_destroy
+- logger_enable_color
+- logger_enable_fsync
+- logger_fsync
+- logger_print
+- logger_set_file
+- logger_set_handler
+- logger_set_level
+- logger_set_max_bufsize
+- logger_set_max_filesize
+- logger_set_remain_days
+
+### herr.h
+- hv_strerror
+
+### hsocket.h
+- Bind
+- Listen
+- Connect
+- ConnectNonblock
+- ConnectTimeout
+- Resolver
+- Socketpair
+- socket_strerror
+- sockaddrlen
+- sockaddr_assign
+- sockaddr_ip
+- sockaddr_port
+- sockaddr_set_port
+- sockaddr_str
+- sockaddr_print
+- tcp_nodelay
+- tcp_nopush
+- tcp_keepalive
+- udp_broadcast
+- so_sndtimeo
+- so_rcvtimeo
+
+### hproc.h
+- spawn_proc
+
+### hthread.h
+- gettid
+- hthread_create
+- hthread_join
+
+### hloop.h
+- create_tcp_client
+- create_tcp_server
+- create_udp_client
+- create_udp_server
+- hloop_new
+- hloop_free
+- hloop_run
+- hloop_stop
+- hloop_pause
+- hloop_resume
+- hloop_now
+- hloop_now_hrtime
+- hloop_now_ms
+- hloop_update_time
+- hloop_set_userdata
+- hloop_userdata
+- hloop_post_event
+- haccept
+- hconnect
+- hread
+- hwrite
+- hrecv
+- hsend
+- hrecvfrom
+- hsendto
+- hio_add
+- hio_del
+- hio_get
+- hio_read
+- hio_write
+- hio_close
+- hio_accept
+- hio_connect
+- hio_fd
+- hio_type
+- hio_error
+- hio_localaddr
+- hio_peeraddr
+- hio_setcb_accept
+- hio_setcb_connect
+- hio_setcb_read
+- hio_setcb_write
+- hio_setcb_close
+- hio_set_localaddr
+- hio_set_peeraddr
+- hio_set_readbuf
+- hio_set_type
+- hio_enable_ssl
+- htimer_add
+- htimer_add_period
+- htimer_del
+- htimer_reset
+- hidle_add
+- hidle_del
+
+### nlog.h
+- network_logger
+- nlog_listen
+
+### dns.h
+- dns_name_decode
+- dns_name_encode
+- dns_pack
+- dns_unpack
+- dns_rr_pack
+- dns_rr_unpack
+- dns_query
+- dns_free
+- nslookup
+
+### ftp.h
+- ftp_command_str
+- ftp_connect
+- ftp_login
+- ftp_exec
+- ftp_upload
+- ftp_download
+- ftp_download_with_cb
+- ftp_quit
+- ftp_status_str
+
+### smtp.h
+- smtp_command_str
+- smtp_status_str
+- smtp_build_command
+- sendmail
+
+### icmp.h
+- ping
+
+### httpdef.h
+- http_content_type_enum
+- http_content_type_enum_by_suffix
+- http_content_type_str
+- http_content_type_str_by_suffix
+- http_content_type_suffix
+- http_errno_description
+- http_errno_name
+- http_method_enum
+- http_method_str
+- http_status_enum
+- http_status_str
+
+### md5.h
+- MD5Init
+- MD5Update
+- MD5Final
+
+### base64.h
+- base64_decode
+- base64_encode
+
+### ssl_ctx.h
+- ssl_ctx_init
+- ssl_ctx_destory
+
+# cpp
+## functions
+### hmain.h
+- main_ctx_init
+- parse_opt
+- parse_opt_long
+- get_arg
+- get_env
+- setproctitle
+- signal_init
+- signal_handler
+- handle_signal
+- create_pidfile
+- delete_pidfile
+- getpid_form_pidfile
+- master_workers_run
+
+### hstring.h
+- asprintf
+- trim
+- trimL
+- trimR
+- trim_pairs
+- split
+- splitKV
+- replace
+- basename
+- dirname
+- filename
+- suffixname
+
+### hdir.h
+- listdir
+
+### hurl.h
+- url_escape
+- url_unescape
+
+### http_client.h
+- http_client_new
+- http_client_del
+- http_client_send
+- http_client_strerror
+- http_client_set_timeout
+- http_client_set_header
+- http_client_del_header
+- http_client_get_header
+- http_client_clear_headers
+
+### HttpServer.h
+- http_server_run
+- http_server_stop
+
+### http_content.h
+- parse_query_params
+- parse_json
+- parse_multipart
+- dump_query_params
+- dump_json
+- dump_multipart
+
+### hsysinfo.h
+- get_ncpu
+- get_meminfo
+
+### ifconfig.h
+- ifconfig
+
+### nmap.h
+- nmap_discovery
+- segment_discovery
+- host_discovery
+
+## classes
+### hscope.h
+- ScopeCleanup
+- ScopeFree
+- ScopeDelete
+- ScopeDeleteArray
+- ScopeRelease
+- ScopeLock
+
+### http
+- HttpMessage
+- HttpRequest
+- HttpResponse
+- HttpService
+
+### misc
+- IniParser
+- HObject
+- HVar
+- HFile
+- HThread
+- HThreadPool
+- HObjectPool
+- HBuf
+- HVLBuf
+- HRingBuf
+- HPoint
+- HSize
+- HRect
+- `hv::MutexLock`
+- `hv::RWLock`
+
+# marcos
+### hdef.h
+- ABS
+- ARRAY_SIZE
+- BITSET
+- BITCLR
+- BITGET
+- CR
+- LF
+- CRLF
+- LOWER
+- UPPER
+- IS_NUM
+- IS_UPPER
+- IS_LOWER
+- IS_ALPHA
+- IS_ALPHANUM
+- IS_HEX
+- IS_GRAPH
+- MAX
+- MIN
+- LIMIT
+- MAKE_FOURCC
+- MAKEWORD
+- HIBYTE
+- LOBYTE
+- MAKELONG
+- HIWORD
+- LOWORD
+- MAKEINT64
+- HIINT
+- LOINT
+- SAFE_ALLOC
+- SAFE_FREE
+- SAFE_DELETE
+- SAFE_DELETE_ARRAY
+- SAFE_RELEASE
+- STRINGIFY
+- STRINGCAT
+- FLOAT_EQUAL_ZERO
+- offsetof
+- offsetoffend
+- container_of
+- prefetch
+- printd
+- NULL
+- TRUE
+- FALSE
+- INFINITE
+- BEGIN_NAMESPACE
+- END_NAMESPACE
+- EXTERN_C
+- BEGIN_EXTERN_C
+- END_EXTERN_C
+- ENUM
+- STRUCT
+- DEFAULT
+
+### hlog.h
+- hlogd
+- hlogi
+- hlogw
+- hloge
+- hlogf
+- LOGD
+- LOGI
+- LOGW
+- LOGE
+- LOGF
+
+### hmutex.h
+- hmutex_t
+- hmutex_init
+- hmutex_destroy
+- hmutex_lock
+- hmutex_unlock
+- hspinlock_t
+- hspinlock_init
+- hspinlock_destroy
+- hspinlock_lock
+- hspinlock_unlock
+- hrwlock_t
+- hrwlock_init
+- hrwlock_destroy
+- hrwlock_rdlock
+- hrwlock_rdunlock
+- hrwlock_wrlock
+- hrwlock_wrunlock
+- htimed_mutex_t
+- htimed_mutex_init
+- htimed_mutex_destroy
+- htimed_mutex_lock
+- htimed_mutex_unlock
+- htimed_mutex_lock_for
+- hcondvar_t
+- hcondvar_init
+- hcondvar_destroy
+- hcondvar_wait
+- hcondvar_signal
+- hcondvar_broadcast
+- honce_t
+- HONCE_INIT
+- honce
+
+### hsocket.h
+- INVALID_SOCKET
+- closesocket
+- blocking
+- nonblocking
+- SOCKADDR_STRLEN
+- SOCKADDR_STR
+
+### hloop.h
+- hevent_loop
+- hevent_type
+- hevent_id
+- hevent_priority
+- hevent_userdata
+- hevent_set_priority
+- hevent_ser_userdata
+
+### hscope.h
+- defer
+
+### singleton.h
+- DISABLE_COPY
+- SINGLETON_DECL
+- SINGLETON_IMPL
+

+ 1 - 1
http/http_content.h

@@ -50,7 +50,7 @@ struct FormData {
 
 // Multipart
 // name => FormData
-typedef MAP<std::string, FormData>          MultiPart;
+typedef HV_MAP<std::string, FormData>          MultiPart;
 #define DEFAULT_MULTIPART_BOUNDARY  "----WebKitFormBoundary7MA4YWxkTrZu0gW"
 std::string dump_multipart(MultiPart& mp, const char* boundary = DEFAULT_MULTIPART_BOUNDARY);
 int         parse_multipart(std::string& str, MultiPart& mp, const char* boundary);

+ 1 - 1
http/server/http_page.h

@@ -3,7 +3,7 @@
 
 #include <string>
 
-#include "http_parser.h"
+#include "httpdef.h"
 
 /*
 <!DOCTYPE html>