mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-03-01 17:42:02 +01:00
Update upload RPC according to amd 5
This commit is contained in:
parent
747f7c31e9
commit
9ef8a6eb18
7 changed files with 111 additions and 111 deletions
|
|
@ -337,6 +337,16 @@ int get_vcf_alias(char *refparam, struct dmctx *ctx, char **value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int lookup_vcf_name(char *instance, char **value) {
|
||||
struct uci_section *s = NULL;
|
||||
uci_foreach_option_eq("dmmap", "vcf", "vcf_instance", instance, s) {
|
||||
dmuci_get_value_by_section_string(s, "name", value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*************************************************************
|
||||
* ENTRY METHOD
|
||||
/*************************************************************/
|
||||
int entry_method_root_DeviceInfo(struct dmctx *ctx)
|
||||
{
|
||||
IF_MATCH(ctx, DMROOT"DeviceInfo.") {
|
||||
|
|
@ -367,33 +377,57 @@ int entry_method_root_DeviceInfo(struct dmctx *ctx)
|
|||
return FAULT_9005;
|
||||
}
|
||||
|
||||
int check_file_dir(char *name)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *d_file;
|
||||
if ((dir = opendir ("/etc/config/")) != NULL) {
|
||||
while ((d_file = readdir (dir)) != NULL) {
|
||||
if(strcmp(name, d_file->d_name) == 0)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int entry_method_device_info_vcf(struct dmctx *ctx)
|
||||
{
|
||||
char *vcf = NULL, *vcf_last = NULL;
|
||||
struct uci_section *s = NULL;
|
||||
char *vcf = NULL, *vcf_last = NULL, *name;
|
||||
struct uci_section *s = NULL, *del_sec = NULL;
|
||||
DIR *dir;
|
||||
struct dirent *d_file;
|
||||
struct stat attr;
|
||||
char *path = NULL;
|
||||
char path[128];
|
||||
char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
|
||||
|
||||
if ((dir = opendir ("/etc/config/")) != NULL) {
|
||||
while ((d_file = readdir (dir)) != NULL) {
|
||||
if(d_file->d_name[0] == '.')
|
||||
continue;
|
||||
dmastrcat(&path, "/etc/config/", d_file->d_name);
|
||||
sprintf(path, "/etc/config/%s", d_file->d_name);
|
||||
stat(path, &attr);
|
||||
strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&attr.st_mtime));
|
||||
update_section_list("dmmap","vcf", "name", 1, d_file->d_name, "date", s_now, "backup_restore", "true");
|
||||
dmfree(path);
|
||||
}
|
||||
uci_foreach_sections("dmmap", "vcf", s) {
|
||||
init_args_vcf(ctx, s);
|
||||
vcf = handle_update_instance(1, ctx, &vcf_last, update_instance_alias, 3, s, "vcf_instance", "vcf_alias");
|
||||
SUBENTRY(entry_method_device_info_vcf_instance, ctx, vcf);
|
||||
update_section_list("dmmap","vcf", "name", 1, d_file->d_name, "date", s_now, "backup_restore", "1");
|
||||
}
|
||||
}
|
||||
closedir (dir);
|
||||
uci_foreach_sections("dmmap", "vcf", s) {
|
||||
dmuci_get_value_by_section_string(s, "name", &name);
|
||||
if(del_sec) {
|
||||
dmuci_delete_by_section(del_sec, NULL, NULL);
|
||||
del_sec = NULL;
|
||||
}
|
||||
if (check_file_dir(name) == 0) {
|
||||
del_sec = s;
|
||||
continue;
|
||||
}
|
||||
init_args_vcf(ctx, s);
|
||||
vcf = handle_update_instance(1, ctx, &vcf_last, update_instance_alias, 3, s, "vcf_instance", "vcf_alias");
|
||||
SUBENTRY(entry_method_device_info_vcf_instance, ctx, vcf);
|
||||
}
|
||||
if(del_sec)
|
||||
dmuci_delete_by_section(del_sec, NULL, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ char *get_deviceid_productclass();
|
|||
char *get_deviceid_serialnumber();
|
||||
char *get_softwareversion();
|
||||
int entry_method_root_DeviceInfo(struct dmctx *ctx);
|
||||
int lookup_vcf_name(char *instance, char **value);
|
||||
|
||||
struct dev_vcf
|
||||
{
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ int external_change_du_state_download(char *url, char *user, char *pass)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int external_upload(char *url, char *type, char *user, char *pass)
|
||||
int external_upload(char *url, char *type, char *user, char *pass, char *name)
|
||||
{
|
||||
DD(INFO,"executing download url '%s'", url);
|
||||
|
||||
|
|
@ -307,6 +307,7 @@ int external_upload(char *url, char *type, char *user, char *pass)
|
|||
json_obj_out_add(json_obj_out, "command", "upload");
|
||||
json_obj_out_add(json_obj_out, "url", url);
|
||||
json_obj_out_add(json_obj_out, "type", type);
|
||||
json_obj_out_add(json_obj_out, "name", name);
|
||||
if(user) json_obj_out_add(json_obj_out, "user", user);
|
||||
if(pass) json_obj_out_add(json_obj_out, "pass", pass);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ void external_uninstallFaultResp (char *fault_code);
|
|||
void external_fetch_uninstallFaultResp (char **fault);
|
||||
int external_simple(char *command, char *arg);
|
||||
int external_download(char *url, char *size, char *type, char *user, char *pass,time_t c);
|
||||
int external_upload(char *url, char *type, char *user, char *pass);
|
||||
int external_upload(char *url, char *type, char *user, char *pass, char *name);
|
||||
int external_apply(char *action, char *arg,time_t c);
|
||||
int external_change_du_state_uninstall(char *package_name);
|
||||
int external_handle_action(int (*external_handler)(char *msg));
|
||||
|
|
|
|||
|
|
@ -210,13 +210,14 @@ typedef struct operations {
|
|||
} operations;
|
||||
|
||||
typedef struct upload {
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
struct list_head list;
|
||||
time_t scheduled_time;
|
||||
char *command_key;
|
||||
char *file_type;
|
||||
char *url;
|
||||
char *username;
|
||||
char *password;
|
||||
char *f_instance;
|
||||
} upload;
|
||||
|
||||
typedef struct transfer_complete {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ NEW_LINE='\n'
|
|||
CWMP_PROMPT="icwmp>"
|
||||
UCI_GET="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get -q"
|
||||
UCI_SHOW="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show -q"
|
||||
UCI_IMPORT="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} import -q"
|
||||
UCI_EXPORT="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} export -q"
|
||||
TMP_SET_VALUE="/tmp/.tmp_set_value"
|
||||
TMP_SET_NOTIFICATION="/tmp/.tmp_set_notification"
|
||||
|
||||
|
|
@ -79,6 +81,7 @@ case "$1" in
|
|||
__arg2="$3"
|
||||
__arg3="$4"
|
||||
__arg4="$5"
|
||||
__arg5="$6"
|
||||
action="upload"
|
||||
;;
|
||||
factory_reset)
|
||||
|
|
@ -291,15 +294,21 @@ handle_action() {
|
|||
fi
|
||||
if [ "$action" = "upload" ]; then
|
||||
local fault_code="9000"
|
||||
if [ "$__arg5" = "" ];then
|
||||
__arg5="all_configs"
|
||||
$UCI_EXPORT > "/tmp/${__arg5}"
|
||||
else
|
||||
$UCI_EXPORT "$__arg5" > "/tmp/${__arg5}"
|
||||
fi
|
||||
if [ "$__arg3" = "" -o "$__arg4" = "" ];then
|
||||
curl -T /etc/config/cwmp "$__arg1" 2> /dev/null
|
||||
if [ "$?" != "0" ];then
|
||||
curl -T "/tmp/${__arg5}" "$__arg1" 2> /dev/null
|
||||
if [ "$?" != "0" ];then
|
||||
let fault_code=$fault_code+$FAULT_CPE_UPLOAD_FAILURE
|
||||
icwmp_fault_output "" "$fault_code"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
curl -T /etc/config/cwmp -u $__arg3:$__arg4 "$__arg1" 2> /dev/null
|
||||
curl -T "/tmp/${__arg5}" -u $__arg3:$__arg4 "$__arg1" 2> /dev/null
|
||||
if [ "$?" != "0" ];then
|
||||
let fault_code=$fault_code+$FAULT_CPE_UPLOAD_FAILURE
|
||||
icwmp_fault_output "" "$fault_code"
|
||||
|
|
@ -418,6 +427,7 @@ handle_action() {
|
|||
json_get_var __arg2 type
|
||||
json_get_var __arg3 user
|
||||
json_get_var __arg4 pass
|
||||
json_get_var __arg5 name
|
||||
action="upload"
|
||||
;;
|
||||
factory_reset)
|
||||
|
|
|
|||
137
xml.c
137
xml.c
|
|
@ -2349,27 +2349,34 @@ int cwmp_launch_schedule_download(struct schedule_download *pdownload, struct tr
|
|||
|
||||
return error;
|
||||
}
|
||||
|
||||
int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptransfer_complete)
|
||||
{
|
||||
int i, error = FAULT_CPE_NO_FAULT;
|
||||
char *upload_startTime;
|
||||
struct transfer_complete *p;
|
||||
char *fault_code;
|
||||
|
||||
upload_startTime = mix_get_time();
|
||||
int i, error = FAULT_CPE_NO_FAULT;
|
||||
char *upload_startTime;
|
||||
struct transfer_complete *p;
|
||||
char *fault_code;
|
||||
char *name = "";
|
||||
struct dmctx dmctx = {0};
|
||||
upload_startTime = mix_get_time();
|
||||
|
||||
bkp_session_delete_upload(pupload);
|
||||
bkp_session_save();
|
||||
bkp_session_delete_upload(pupload);
|
||||
bkp_session_save();
|
||||
|
||||
external_upload(pupload->url, pupload->file_type,
|
||||
pupload->username, pupload->password);
|
||||
external_handle_action(cwmp_handle_uploadFault);
|
||||
external_fetch_uploadFaultResp(&fault_code);
|
||||
dm_ctx_init(&dmctx);
|
||||
if (pupload->file_type[0] == '3' && pupload->f_instance && isdigit(pupload->f_instance[0])) {
|
||||
lookup_vcf_name(pupload->f_instance, &name);
|
||||
}
|
||||
external_upload(pupload->url, pupload->file_type,
|
||||
pupload->username, pupload->password, name);
|
||||
dm_ctx_clean(&dmctx);
|
||||
external_handle_action(cwmp_handle_uploadFault);
|
||||
external_fetch_uploadFaultResp(&fault_code);
|
||||
|
||||
if(fault_code != NULL)
|
||||
{
|
||||
if(fault_code[0]=='9')
|
||||
{
|
||||
if(fault_code != NULL)
|
||||
{
|
||||
if(fault_code[0]=='9')
|
||||
{
|
||||
for(i=1;i<__FAULT_CPE_MAX;i++)
|
||||
{
|
||||
if(strcmp(FAULT_CPE_ARRAY[i].CODE,fault_code) == 0)
|
||||
|
|
@ -2378,13 +2385,9 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(fault_code);
|
||||
}
|
||||
/*else {
|
||||
error = FAULT_CPE_INTERNAL_ERROR;
|
||||
}*/
|
||||
|
||||
}
|
||||
free(fault_code);
|
||||
}
|
||||
p = calloc (1,sizeof(struct transfer_complete));
|
||||
if(p == NULL)
|
||||
{
|
||||
|
|
@ -2402,63 +2405,7 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans
|
|||
|
||||
*ptransfer_complete = p;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int cwmp_launch_uninstall(struct upload *pupload, struct transfer_complete **ptransfer_complete)
|
||||
{
|
||||
int i, error = FAULT_CPE_NO_FAULT;
|
||||
char *upload_startTime;
|
||||
struct transfer_complete *p;
|
||||
char *fault_code;
|
||||
|
||||
upload_startTime = mix_get_time();
|
||||
|
||||
bkp_session_delete_upload(pupload);
|
||||
bkp_session_save();
|
||||
|
||||
external_upload(pupload->url, pupload->file_type,
|
||||
pupload->username, pupload->password);
|
||||
external_handle_action(cwmp_handle_uploadFault);
|
||||
external_fetch_uploadFaultResp(&fault_code);
|
||||
|
||||
if(fault_code != NULL)
|
||||
{
|
||||
if(fault_code[0]=='9')
|
||||
{
|
||||
for(i=1;i<__FAULT_CPE_MAX;i++)
|
||||
{
|
||||
if(strcmp(FAULT_CPE_ARRAY[i].CODE,fault_code) == 0)
|
||||
{
|
||||
error = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(fault_code);
|
||||
}
|
||||
/*else {
|
||||
error = FAULT_CPE_INTERNAL_ERROR;
|
||||
}*/
|
||||
|
||||
p = calloc (1,sizeof(struct transfer_complete));
|
||||
if(p == NULL)
|
||||
{
|
||||
error = FAULT_CPE_INTERNAL_ERROR;
|
||||
return error;
|
||||
}
|
||||
|
||||
p->command_key = strdup(pupload->command_key);
|
||||
p->start_time = strdup(upload_startTime);
|
||||
p->complete_time = strdup(mix_get_time());
|
||||
if(error != FAULT_CPE_NO_FAULT)
|
||||
{
|
||||
p->fault_code = error;
|
||||
}
|
||||
|
||||
*ptransfer_complete = p;
|
||||
|
||||
return error;
|
||||
return error;
|
||||
}
|
||||
|
||||
void *thread_cwmp_rpc_cpe_download (void *v)
|
||||
|
|
@ -3741,25 +3688,29 @@ int cwmp_free_upload_request(struct upload *upload)
|
|||
{
|
||||
if(upload->command_key != NULL)
|
||||
{
|
||||
free(upload->command_key);
|
||||
FREE(upload->command_key);
|
||||
}
|
||||
if(upload->file_type != NULL)
|
||||
{
|
||||
free(upload->file_type);
|
||||
FREE(upload->file_type);
|
||||
}
|
||||
if(upload->url != NULL)
|
||||
{
|
||||
free(upload->url);
|
||||
FREE(upload->url);
|
||||
}
|
||||
if(upload->username != NULL)
|
||||
{
|
||||
free(upload->username);
|
||||
FREE(upload->username);
|
||||
}
|
||||
if(upload->password != NULL)
|
||||
{
|
||||
free(upload->password);
|
||||
FREE(upload->password);
|
||||
}
|
||||
free(upload);
|
||||
if(upload->f_instance != NULL)
|
||||
{
|
||||
FREE(upload->f_instance);
|
||||
}
|
||||
FREE(upload);
|
||||
}
|
||||
return CWMP_OK;
|
||||
}
|
||||
|
|
@ -4529,7 +4480,7 @@ int cwmp_handle_rpc_cpe_schedule_download(struct session *session, struct rpc *r
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
cwmp_free_schedule_download_request(schedule_download);
|
||||
cwmp_free_schedule_download_request(schedule_download);
|
||||
if (cwmp_create_fault_message(session, rpc, error))
|
||||
goto error;
|
||||
return 0;
|
||||
|
|
@ -4569,7 +4520,7 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
|
|||
error = FAULT_CPE_INTERNAL_ERROR;
|
||||
goto fault;
|
||||
}
|
||||
|
||||
upload->f_instance = strdup("");
|
||||
while (b != NULL) {
|
||||
if (b && b->type == MXML_TEXT &&
|
||||
b->value.text.string &&
|
||||
|
|
@ -4594,6 +4545,9 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
|
|||
error = FAULT_CPE_INTERNAL_ERROR;
|
||||
goto fault;
|
||||
}
|
||||
if (isdigit(b->value.text.string[0])) {
|
||||
upload->f_instance = strdup(b->value.text.string);
|
||||
}
|
||||
FREE(tmp);
|
||||
}
|
||||
}
|
||||
|
|
@ -4623,9 +4577,8 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
|
|||
}
|
||||
b = mxmlWalkNext(b, n, MXML_DESCEND);
|
||||
}
|
||||
|
||||
if(strcmp(file_type,"3 Vendor Configuration File") &&
|
||||
strcmp(file_type,"4 Vendor Log File"))
|
||||
if(strncmp(file_type, "3 Vendor Configuration File", sizeof"3 Vendor Configuration File" -1) != 0 &&
|
||||
strncmp(file_type, "4 Vendor Log File", sizeof"4 Vendor Log File" -1) != 0)
|
||||
{
|
||||
error = FAULT_CPE_REQUEST_DENIED;
|
||||
}
|
||||
|
|
@ -4715,7 +4668,7 @@ int cwmp_handle_rpc_cpe_upload(struct session *session, struct rpc *rpc)
|
|||
return 0;
|
||||
|
||||
fault:
|
||||
cwmp_free_upload_request(upload);
|
||||
cwmp_free_upload_request(upload);
|
||||
if (cwmp_create_fault_message(session, rpc, error))
|
||||
goto error;
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue