b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | #ifndef __XML_UBUS_H_ |
| 2 | #define __XML_UBUS_H_ |
| 3 | #include <libubox/blobmsg.h> |
| 4 | #include <libubox/blobmsg_json.h> |
| 5 | #include <libubox/avl.h> |
| 6 | #include <libubox/avl-cmp.h> |
| 7 | #include <libubox/list.h> |
| 8 | #include <libubox/uloop.h> |
| 9 | #include <libubox/ustream.h> |
| 10 | #include <libubox/blob.h> |
| 11 | #include <libubox/utils.h> |
| 12 | #include <libubox/usock.h> |
| 13 | #include <libubus.h> |
| 14 | |
| 15 | #include <syslog.h> |
| 16 | #include <stdio.h> |
| 17 | #include <string.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <unistd.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <sys/wait.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <linux/limits.h> |
| 25 | |
| 26 | #include <poll.h> |
| 27 | #include <mxml.h> |
| 28 | #include <cgi.h> |
| 29 | #include "blobmsg_xml.h" |
| 30 | #include <include/log.h> |
| 31 | #include <sys/prctl.h> |
| 32 | |
| 33 | #define XML_GET_BUF_SIZE 16*1024 |
| 34 | #define UBUS_DEFAULE_SID "00000000000000000000000000000000" |
| 35 | #define ARG_METHOD "method" |
| 36 | #define ARG_FILE "file" |
| 37 | #define ARG_COMMAND "command" |
| 38 | #define ARG_MODULE "module" |
| 39 | #define ARG_ACTION "Action" |
| 40 | #define ERROR_CAUSE_TAG "error_cause" |
| 41 | #define RESPONSE_TAG "response" |
| 42 | #define OTA_UNIX_PATH "/tmp/ota.unix" |
| 43 | #define CONFIG_FILE_NAME "pxa1826_cfg.tar.gz" |
| 44 | |
| 45 | #define LOGCAT |
| 46 | #ifdef LOGCAT |
| 47 | #define CGI_LOGI(format, args...) RDPRINTF(format, ##args) |
| 48 | #define CGI_LOGD(format, args...) RDBGMSG(format, ##args) |
| 49 | #define CGI_LOGE(format, args...) RERRMSG(format, ##args) |
| 50 | #else |
| 51 | #define CGI_LOGI(format, args.. |
| 52 | #endif |
| 53 | |
| 54 | #ifndef UNUSEDPARAM |
| 55 | #define UNUSEDPARAM(param) (void)param; |
| 56 | #endif |
| 57 | |
| 58 | enum { |
| 59 | RPC_METHOD, |
| 60 | RPC_SESSIONID, |
| 61 | RPC_OBJPATH, |
| 62 | PRC_OBJMETHOD, |
| 63 | RPC_MAX, |
| 64 | }; |
| 65 | |
| 66 | enum { |
| 67 | SES_ACCESS, |
| 68 | __SES_MAX, |
| 69 | }; |
| 70 | |
| 71 | typedef enum _error_cause_format { |
| 72 | ERR_NUMBER, |
| 73 | ERR_STRING, |
| 74 | } e_error_cause_format; |
| 75 | |
| 76 | typedef enum _error_cause { |
| 77 | NO_ERR, |
| 78 | ERR_CGI_FORMAT, |
| 79 | ERR_PARAM_INVALID, |
| 80 | ERR_SERVICE_NOT_FOUND, |
| 81 | ERR_METHOD_NOT_SUPPORT, |
| 82 | ERR_SESSION_INVALID, |
| 83 | ERR_CGI_FILE, |
| 84 | _ERR_MAX, |
| 85 | } e_error_cause; |
| 86 | |
| 87 | struct rpc_data { |
| 88 | char *sid; |
| 89 | char *ubus_method; |
| 90 | char *object_path; |
| 91 | char *object_method; |
| 92 | struct blob_attr *data; |
| 93 | struct blob_attr *params; |
| 94 | }; |
| 95 | |
| 96 | const char *error_cause_msg[] = { |
| 97 | "OK", |
| 98 | "inner cgi error, wrong post XML", |
| 99 | "invalid param", |
| 100 | "not found the object path", |
| 101 | "list method not support", |
| 102 | "session invalid", |
| 103 | "inner cgi error, open file failed", |
| 104 | }; |
| 105 | |
| 106 | typedef enum _e_upload_status{ |
| 107 | UPLOAD_OK, |
| 108 | ERR_UPLOAD_FAILED, |
| 109 | } e_upload_status; |
| 110 | |
| 111 | struct upload_ctx { |
| 112 | unsigned int id; |
| 113 | char f_name[32]; |
| 114 | int n_file_total; |
| 115 | int n_file_segmnet; |
| 116 | int n_send; |
| 117 | int fd; |
| 118 | e_upload_status upload_status; |
| 119 | }; |
| 120 | |
| 121 | typedef int (*upload_fw_init_cb_t) (struct upload_ctx *, int, int); |
| 122 | typedef int (*upload_fw_write_cb_t) (struct upload_ctx *, char *, int); |
| 123 | typedef int (*upload_fw_done_cb_t) (struct upload_ctx *); |
| 124 | typedef int (*download_init_cb_t) (); |
| 125 | typedef int (*download_response_cb_t) (); |
| 126 | typedef int (*upload_response_cb_t) (struct upload_ctx *); |
| 127 | |
| 128 | struct upload_forward_ops { |
| 129 | upload_fw_init_cb_t upload_fw_init_cb; |
| 130 | upload_fw_write_cb_t upload_fw_write_cb; |
| 131 | upload_fw_done_cb_t upload_fw_done_cb; |
| 132 | upload_response_cb_t upload_response_cb; |
| 133 | }; |
| 134 | |
| 135 | struct download_ops { |
| 136 | download_init_cb_t download_init_cb; |
| 137 | download_response_cb_t download_response_cb; |
| 138 | }; |
| 139 | |
| 140 | struct mime_vec { |
| 141 | char *str; |
| 142 | int len; |
| 143 | }; |
| 144 | |
| 145 | #endif |