[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/lynq/lib/liblynq-protcl/include/http/lynq_http.h b/src/lynq/lib/liblynq-protcl/include/http/lynq_http.h
new file mode 100644
index 0000000..455abc2
--- /dev/null
+++ b/src/lynq/lib/liblynq-protcl/include/http/lynq_http.h
@@ -0,0 +1,185 @@
+#ifndef _LYNQ_HTTP_H_
+#define _LYNQ_HTTP_H_
+
+#define HTTP_API
+
+
+#include "lynq_http_parser.h"
+#include "lynq_msgq.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/select.h>
+#include <time.h>
+#include <ctype.h>
+#include <netdb.h>
+#include <strings.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+
+#ifdef _cplusplus
+extern "C" {
+#endif
+
+#define HTTP_INVALID_SOCKET -1
+#define HTTP_EINTR EINTR
+#define HTTP_EINPROGRESS EINPROGRESS
+#define HTTP_EWOULDBLOCK EWOULDBLOCK
+#define HTTP_EALREADY EALREADY
+
+#define free_member(member) if((member)) { free(member); (member) = NULL; }
+#define close_socket(fd) if(fd != HTTP_INVALID_SOCKET) { socket_close(fd); fd = HTTP_INVALID_SOCKET; }
+#define close_file(pf) if(pf != NULL) { fclose(pf); pf = NULL; }
+
+#define RECV_BUF_SIZE 4 * 1024
+
+#define socket_close close
+
+
+enum parser_statue_e { PARSERD_NONE = 0, PARSERD_FIELD, PARSERD_VALUE, PARSERD_BODY };
+
+enum proto_type_e { PROTO_HTTP = 0, PROTO_HTTPS };
+ typedef enum http_request_method_e
+ {
+ M_GET = 0,
+ M_POST,
+ M_HEAD
+ } http_request_method_e;
+
+ typedef enum http_connent_method_e
+ {
+ M_CLOSE = 0,
+ M_KEEP,
+ } http_connent_method_e;
+
+ enum http_error_e
+ {
+ ERR_OK = 0,
+
+ ERR_INVALID_PARAM,
+ ERR_OUT_MEMORY,
+ ERR_OPEN_FILE,
+ ERR_PARSE_REP,
+ ERR_URL_INVALID,
+ ERR_URL_INVALID_PROTO,
+ ERR_URL_INVALID_HOST,
+ ERR_URL_INVALID_IP,
+ ERR_URL_RESOLVED_HOST,
+ ERR_SOCKET_CREATE = 10,
+ ERR_SOCKET_SET_OPT,
+ ERR_SOCKET_NOBLOCKING,
+ ERR_SOCKET_CONNECT,
+ ERR_SOCKET_CONNECT_TIMEOUT,
+ ERR_SOCKET_SELECT,
+ ERR_SOCKET_WRITE,
+ ERR_SOCKET_READ,
+ ERR_SOCKET_TIMEOUT,
+ ERR_SOCKET_CLOSED,
+ ERR_SOCKET_GET_OPT = 20,
+ ERR_SSL_CREATE_CTX,
+ ERR_SSL_CREATE_SSL,
+ ERR_SSL_SET_FD,
+ ERR_SSL_CONNECT,
+ ERR_SSL_WRITE,
+ ERR_SSL_READ,
+ ERR_NOCERT,
+ ERR_MSG
+ };
+
+ struct lynq_http_client_t;
+ typedef struct lynq_http_client_t lynq_http_client_t;
+ typedef int (*data_recv_cb_t)( lynq_http_client_t* http, const char* data, int size, int total, void* user);
+
+ typedef int socket_t;
+
+
+ struct lynq_http_client_t
+ {
+ int index;
+
+ char protocol[10];
+ int session;
+
+ char action[10];
+ char *data;
+ char *section;
+ int request_method;
+ int connent_method;
+ int sockfd;
+ int modify_thread;
+ int add_thread;
+
+ FILE* pf;
+ char* filename;
+ char* body;
+ char* redirect_url;
+ char* header_field;
+ char* header_value;
+
+ char* post_data;
+ char* url;
+ int post_data_len;
+ struct http_parser_url u;
+ char* user_header;
+ int user_header_len;
+
+ http_parser_settings parser_setting;
+ struct http_parser parser;
+
+
+ char* user;
+ data_recv_cb_t recv_cb;
+
+ unsigned long body_len;
+ unsigned long content_length;
+
+ enum http_request_method_e method;
+ enum http_connent_method_e conn_method;
+ enum proto_type_e proto_type;
+
+ unsigned short field_size;
+ unsigned short value_size;
+ unsigned short cur_field_size;
+ unsigned short cur_value_size;
+ SSL_CTX *ctx;
+ SSL *ssl;
+
+ socket_t fd;
+ int timeout;
+
+ short status_code;
+ char parser_statue;
+ char error_code;
+ unsigned cancel : 1;
+ unsigned exit : 1;
+ unsigned download : 1;
+ unsigned redirect : 1;
+};
+
+
+int lynq_http_init(void);
+lynq_http_client_t* lynq_http_new();
+void lynq_http_destroy(lynq_http_client_t* http);
+int lynq_http_get_error_code(lynq_http_client_t* http);
+const char* lynq_http_sync_request(lynq_http_client_t* http, const char* url, http_request_method_e m, http_connent_method_e c_m);
+const char* lynq_http_sync_post_request(lynq_http_client_t* http, char* url, char* post_data, http_request_method_e m, http_connent_method_e c_m);
+int lynq_http_sync_download_file(lynq_http_client_t* http, char* url, char* filepath, http_request_method_e m, http_connent_method_e c_m);
+int lynq_http_set_data_recv_cb(lynq_http_client_t* http, data_recv_cb_t cb, void* user);
+int lynq_http_exit(lynq_http_client_t* http);
+int lynq_http_data_send(char *data);
+void *lynq_http_write_head_data(lynq_http_client_t* http);
+#ifdef _cplusplus
+}
+#endif
+#endif
+
diff --git a/src/lynq/lib/liblynq-protcl/include/http/lynq_http_parser.h b/src/lynq/lib/liblynq-protcl/include/http/lynq_http_parser.h
new file mode 100644
index 0000000..99d9f20
--- /dev/null
+++ b/src/lynq/lib/liblynq-protcl/include/http/lynq_http_parser.h
@@ -0,0 +1,220 @@
+#ifndef _LYNQ_HTTP_PARSER_H_
+#define _LYNQ_HTTP_PARSER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define HTTP_PARSER_VERSION_MAJOR 2
+#define HTTP_PARSER_VERSION_MINOR 5
+#define HTTP_PARSER_VERSION_PATCH 0
+#include <stddef.h>
+#include <stdint.h>
+#include "liblog/liblog.h"
+#include "liblog/lynq_deflog.h"
+
+
+
+#ifndef HTTP_PARSER_STRICT
+# define HTTP_PARSER_STRICT 1
+#endif
+
+#ifndef HTTP_MAX_HEADER_SIZE
+# define HTTP_MAX_HEADER_SIZE (80*1024)
+#endif
+
+ typedef struct http_parser http_parser;
+ typedef struct http_parser_settings http_parser_settings;
+
+ typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
+ typedef int (*http_cb) (http_parser*);
+
+
+ /* Request Methods */
+#define HTTP_METHOD_MAP(XX) \
+ XX(0, DELETE, DELETE) \
+ XX(1, GET, GET) \
+ XX(2, HEAD, HEAD) \
+ XX(3, POST, POST) \
+ XX(4, PUT, PUT) \
+ /* pathological */ \
+ XX(5, CONNECT, CONNECT) \
+ XX(6, OPTIONS, OPTIONS) \
+ XX(7, TRACE, TRACE) \
+ /* WebDAV */ \
+ XX(8, COPY, COPY) \
+ XX(9, LOCK, LOCK) \
+ XX(10, MKCOL, MKCOL) \
+ XX(11, MOVE, MOVE) \
+ XX(12, PROPFIND, PROPFIND) \
+ XX(13, PROPPATCH, PROPPATCH) \
+ XX(14, SEARCH, SEARCH) \
+ XX(15, UNLOCK, UNLOCK) \
+ XX(16, BIND, BIND) \
+ XX(17, REBIND, REBIND) \
+ XX(18, UNBIND, UNBIND) \
+ XX(19, ACL, ACL) \
+ /* subversion */ \
+ XX(20, REPORT, REPORT) \
+ XX(21, MKACTIVITY, MKACTIVITY) \
+ XX(22, CHECKOUT, CHECKOUT) \
+ XX(23, MERGE, MERGE) \
+ /* upnp */ \
+ XX(24, MSEARCH, M-SEARCH) \
+ XX(25, NOTIFY, NOTIFY) \
+ XX(26, SUBSCRIBE, SUBSCRIBE) \
+ XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
+ /* RFC-5789 */ \
+ XX(28, PATCH, PATCH) \
+ XX(29, PURGE, PURGE) \
+ /* CalDAV */ \
+ XX(30, MKCALENDAR, MKCALENDAR) \
+
+ enum http_method
+ {
+#define XX(num, name, string) HTTP_##name = num,
+ HTTP_METHOD_MAP(XX)
+#undef XX
+ };
+
+
+ enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
+ enum flags
+ { F_CHUNKED = 1 << 0
+ , F_CONNECTION_KEEP_ALIVE = 1 << 1
+ , F_CONNECTION_CLOSE = 1 << 2
+ , F_CONNECTION_UPGRADE = 1 << 3
+ , F_TRAILING = 1 << 4
+ , F_UPGRADE = 1 << 5
+ , F_SKIPBODY = 1 << 6
+ };
+
+#define HTTP_ERRNO_MAP(XX) \
+ /* No error */ \
+ XX(OK, "success") \
+ \
+ /* Callback-related errors */ \
+ XX(CB_message_begin, "the on_message_begin callback failed") \
+ XX(CB_url, "the on_url callback failed") \
+ XX(CB_header_field, "the on_header_field callback failed") \
+ XX(CB_header_value, "the on_header_value callback failed") \
+ XX(CB_headers_complete, "the on_headers_complete callback failed") \
+ XX(CB_body, "the on_body callback failed") \
+ XX(CB_message_complete, "the on_message_complete callback failed") \
+ XX(CB_status, "the on_status callback failed") \
+ XX(CB_chunk_header, "the on_chunk_header callback failed") \
+ XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
+ \
+ /* Parsing-related errors */ \
+ XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
+ XX(HEADER_OVERFLOW, \
+ "too many header bytes seen; overflow detected") \
+ XX(CLOSED_CONNECTION, \
+ "data received after completed connection: close message") \
+ XX(INVALID_VERSION, "invalid HTTP version") \
+ XX(INVALID_STATUS, "invalid HTTP status code") \
+ XX(INVALID_METHOD, "invalid HTTP method") \
+ XX(INVALID_URL, "invalid URL") \
+ XX(INVALID_HOST, "invalid host") \
+ XX(INVALID_PORT, "invalid port") \
+ XX(INVALID_PATH, "invalid path") \
+ XX(INVALID_QUERY_STRING, "invalid query string") \
+ XX(INVALID_FRAGMENT, "invalid fragment") \
+ XX(LF_EXPECTED, "LF character expected") \
+ XX(INVALID_HEADER_TOKEN, "invalid character in header") \
+ XX(INVALID_CONTENT_LENGTH, \
+ "invalid character in content-length header") \
+ XX(INVALID_CHUNK_SIZE, \
+ "invalid character in chunk size header") \
+ XX(INVALID_CONSTANT, "invalid constant string") \
+ XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
+ XX(STRICT, "strict mode assertion failed") \
+ XX(PAUSED, "parser is paused") \
+ XX(UNKNOWN, "an unknown error occurred")
+
+#define HTTP_ERRNO_GEN(n, s) HPE_##n,
+ enum http_errno {
+ HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
+ };
+#undef HTTP_ERRNO_GEN
+
+#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
+
+ struct http_parser {
+ unsigned int type : 2; /* enum http_parser_type */
+ unsigned int flags : 7; /* F_* values from 'flags' enum; semi-public */
+ unsigned int state : 7; /* enum state from http_parser.c */
+ unsigned int header_state : 8; /* enum header_state from http_parser.c */
+ unsigned int index : 8; /* index into current matcher */
+
+ uint32_t nread; /* # bytes read in various scenarios */
+ uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
+
+ unsigned short http_major;
+ unsigned short http_minor;
+ unsigned int status_code : 16;
+ unsigned int method : 8;
+ unsigned int http_errno : 7;
+ unsigned int upgrade : 1;
+ void *data;
+ };
+
+
+ struct http_parser_settings {
+ http_cb on_message_begin;
+ http_data_cb on_url;
+ http_data_cb on_status;
+ http_data_cb on_header_field;
+ http_data_cb on_header_value;
+ http_cb on_headers_complete;
+ http_data_cb on_body;
+ http_cb on_message_complete;
+ http_cb on_chunk_header;
+ http_cb on_chunk_complete;
+ };
+
+
+ enum http_parser_url_fields
+ {
+ UF_SCHEMA = 0,
+ UF_HOST = 1,
+ UF_PORT = 2,
+ UF_PATH = 3,
+ UF_QUERY = 4,
+ UF_FRAGMENT = 5,
+ UF_USERINFO = 6,
+ UF_MAX = 7,
+ };
+
+ struct http_parser_url {
+ uint16_t field_set; /* Bitmask of (1 << UF_*) values */
+ uint16_t port; /* Converted UF_PORT string */
+
+ struct {
+ uint16_t off; /* Offset into buffer in which field starts */
+ uint16_t len; /* Length of run in buffer */
+ } field_data[UF_MAX];
+ };
+
+ unsigned long http_parser_version(void);
+ void http_parser_init(http_parser *parser, enum http_parser_type type);
+ void http_parser_settings_init(http_parser_settings *settings);
+ size_t http_parser_execute(http_parser *parser,
+ const http_parser_settings *settings,
+ const char *data,
+ size_t len);
+
+ int http_should_keep_alive(const http_parser *parser);
+ const char *http_method_str(enum http_method m);
+ const char *http_errno_name(enum http_errno err);
+ const char *http_errno_description(enum http_errno err);
+ int http_parser_parse_url(const char *buf, size_t buflen,
+ int is_connect,
+ struct http_parser_url *u);
+ void http_parser_pause(http_parser *parser, int paused);
+ int http_body_is_final(const http_parser *parser);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/lynq/lib/liblynq-protcl/include/http/lynq_msgq.h b/src/lynq/lib/liblynq-protcl/include/http/lynq_msgq.h
new file mode 100644
index 0000000..784e077
--- /dev/null
+++ b/src/lynq/lib/liblynq-protcl/include/http/lynq_msgq.h
@@ -0,0 +1,19 @@
+#ifndef _LYNQ_MSGQ_H_
+#define _LYNQ_MSGQ_H_
+
+#include <sys/msg.h>
+#include <sys/ipc.h>
+#include "liblog/liblog.h"
+#include "liblog/lynq_deflog.h"
+#include "http/lynq_http.h"
+
+struct mymesg{
+ long int mtype;
+ char mtext[512];
+};
+
+int lynq_msgq_init(char *pathname, int create);
+int lynq_msgq_send(int queueId, struct mymesg *ckxmsg);
+
+#endif
+