projects
/
platform
/
framework
/
web
/
livebox-viewer.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update coding convention & file-service added.
[platform/framework/web/livebox-viewer.git]
/
src
/
desc_parser.c
diff --git
a/src/desc_parser.c
b/src/desc_parser.c
index
25595c0
..
74fb887
100644
(file)
--- a/
src/desc_parser.c
+++ b/
src/desc_parser.c
@@
-1,11
+1,11
@@
/*
/*
- * Copyright 201
2
Samsung Electronics Co., Ltd
+ * Copyright 201
3
Samsung Electronics Co., Ltd
*
*
- * Licensed under the Flora License, Version 1.
0
(the "License");
+ * Licensed under the Flora License, Version 1.
1
(the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://
www.tizenopensource.org/license
+ * http://
floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@
-21,6
+21,7
@@
#include <ctype.h>
#include <dlog.h>
#include <ctype.h>
#include <dlog.h>
+#include <livebox-errno.h>
#include "debug.h"
#include "livebox.h"
#include "debug.h"
#include "livebox.h"
@@
-53,8
+54,8
@@
struct block {
char *file;
int file_len;
char *file;
int file_len;
- char *
group
;
- int
group
_len;
+ char *
option
;
+ int
option
_len;
char *id;
int id_len;
char *id;
int id_len;
@@
-66,12
+67,13
@@
static int update_text(struct livebox *handle, struct block *block, int is_pd)
if (!block || !block->part || !block->data) {
ErrPrint("Invalid argument\n");
if (!block || !block->part || !block->data) {
ErrPrint("Invalid argument\n");
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
- if (ops->update_text)
+ if (ops->update_text)
{
ops->update_text(handle, (const char *)block->id, (const char *)block->part, (const char *)block->data);
ops->update_text(handle, (const char *)block->id, (const char *)block->part, (const char *)block->data);
+ }
return 0;
}
return 0;
}
@@
-81,12
+83,13
@@
static int update_image(struct livebox *handle, struct block *block, int is_pd)
struct livebox_script_operators *ops;
if (!block || !block->part) {
ErrPrint("Invalid argument\n");
struct livebox_script_operators *ops;
if (!block || !block->part) {
ErrPrint("Invalid argument\n");
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
- if (ops->update_image)
- ops->update_image(handle, block->id, block->part, block->data);
+ if (ops->update_image) {
+ ops->update_image(handle, block->id, block->part, block->data, block->option);
+ }
return 0;
}
return 0;
}
@@
-96,12
+99,13
@@
static int update_script(struct livebox *handle, struct block *block, int is_pd)
struct livebox_script_operators *ops;
if (!block || !block->part) {
ErrPrint("Invalid argument\n");
struct livebox_script_operators *ops;
if (!block || !block->part) {
ErrPrint("Invalid argument\n");
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
- if (ops->update_script)
- ops->update_script(handle, block->id, block->part, block->data, block->group);
+ if (ops->update_script) {
+ ops->update_script(handle, block->id, block->part, block->data, block->option);
+ }
return 0;
}
return 0;
}
@@
-112,12
+116,13
@@
static int update_signal(struct livebox *handle, struct block *block, int is_pd)
if (!block) {
ErrPrint("Invalid argument\n");
if (!block) {
ErrPrint("Invalid argument\n");
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
- if (ops->update_signal)
+ if (ops->update_signal)
{
ops->update_signal(handle, block->id, block->data, block->part);
ops->update_signal(handle, block->id, block->data, block->part);
+ }
return 0;
}
return 0;
}
@@
-129,18
+134,19
@@
static int update_drag(struct livebox *handle, struct block *block, int is_pd)
if (!block || !block->data || !block->part) {
ErrPrint("Invalid argument\n");
if (!block || !block->data || !block->part) {
ErrPrint("Invalid argument\n");
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) {
ErrPrint("Invalid format of data\n");
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
if (sscanf(block->data, "%lfx%lf", &dx, &dy) != 2) {
ErrPrint("Invalid format of data\n");
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
}
- if (ops->update_drag)
+ if (ops->update_drag)
{
ops->update_drag(handle, block->id, block->part, dx, dy);
ops->update_drag(handle, block->id, block->part, dx, dy);
+ }
return 0;
}
return 0;
}
@@
-151,7
+157,7
@@
static int update_info(struct livebox *handle, struct block *block, int is_pd)
if (!block || !block->part || !block->data) {
ErrPrint("Invalid argument\n");
if (!block || !block->part || !block->data) {
ErrPrint("Invalid argument\n");
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
}
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
@@
-161,15
+167,16
@@
static int update_info(struct livebox *handle, struct block *block, int is_pd)
if (sscanf(block->data, "%dx%d", &w, &h) != 2) {
ErrPrint("Invalid format (%s)\n", block->data);
if (sscanf(block->data, "%dx%d", &w, &h) != 2) {
ErrPrint("Invalid format (%s)\n", block->data);
- return
-EINVAL
;
+ return
LB_STATUS_ERROR_INVALID
;
}
}
- if (ops->update_info_size)
+ if (ops->update_info_size)
{
ops->update_info_size(handle, block->id, w, h);
ops->update_info_size(handle, block->id, w, h);
-
+ }
} else if (!strcasecmp(block->part, INFO_CATEGORY)) {
} else if (!strcasecmp(block->part, INFO_CATEGORY)) {
- if (ops->update_info_category)
+ if (ops->update_info_category)
{
ops->update_info_category(handle, block->id, block->data);
ops->update_info_category(handle, block->id, block->data);
+ }
}
return 0;
}
return 0;
@@
-181,8
+188,9
@@
static inline int update_begin(struct livebox *handle, int is_pd)
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
- if (ops->update_begin)
+ if (ops->update_begin)
{
ops->update_begin(handle);
ops->update_begin(handle);
+ }
return 0;
}
return 0;
}
@@
-193,8
+201,9
@@
static inline int update_end(struct livebox *handle, int is_pd)
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
ops = is_pd ? &handle->pd.data.ops : &handle->lb.data.ops;
- if (ops->update_end)
+ if (ops->update_end)
{
ops->update_end(handle);
ops->update_end(handle);
+ }
return 0;
}
return 0;
}
@@
-214,15
+223,15
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
VALUE_PART = 0x01,
VALUE_DATA = 0x02,
VALUE_FILE = 0x03,
VALUE_PART = 0x01,
VALUE_DATA = 0x02,
VALUE_FILE = 0x03,
- VALUE_
GROUP
= 0x04,
- VALUE_ID = 0x05
,
+ VALUE_
OPTION
= 0x04,
+ VALUE_ID = 0x05
};
const char *field_name[] = {
"type",
"part",
"data",
"file",
};
const char *field_name[] = {
"type",
"part",
"data",
"file",
- "
group
",
+ "
option
",
"id",
NULL
};
"id",
NULL
};
@@
-268,7
+277,7
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
fp = fopen(descfile, "rt");
if (!fp) {
ErrPrint("Error: %s\n", strerror(errno));
fp = fopen(descfile, "rt");
if (!fp) {
ErrPrint("Error: %s\n", strerror(errno));
- return
-E
IO;
+ return
LB_STATUS_ERROR_
IO;
}
update_begin(handle, is_pd);
}
update_begin(handle, is_pd);
@@
-289,24
+298,30
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
if (!isspace(ch)) {
update_end(handle, is_pd);
if (!isspace(ch)) {
update_end(handle, is_pd);
- fclose(fp);
- return -EINVAL;
+ if (fclose(fp) != 0) {
+ ErrPrint("fclose: %s\n", strerror(errno));
+ }
+ return LB_STATUS_ERROR_INVALID;
}
break;
case BLOCK_OPEN:
}
break;
case BLOCK_OPEN:
- if (isblank(ch))
+ if (isblank(ch))
{
break;
break;
+ }
- if (ch != '\n')
+ if (ch != '\n')
{
goto errout;
goto errout;
+ }
block = calloc(1, sizeof(*block));
if (!block) {
CRITICAL_LOG("Heap: %s\n", strerror(errno));
update_end(handle, is_pd);
block = calloc(1, sizeof(*block));
if (!block) {
CRITICAL_LOG("Heap: %s\n", strerror(errno));
update_end(handle, is_pd);
- fclose(fp);
- return -ENOMEM;
+ if (fclose(fp) != 0) {
+ ErrPrint("fclose: %s\n", strerror(errno));
+ }
+ return LB_STATUS_ERROR_MEMORY;
}
state = FIELD;
}
state = FIELD;
@@
-315,8
+330,9
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
break;
case FIELD:
break;
case FIELD:
- if (isspace(ch))
+ if (isspace(ch))
{
break;
break;
+ }
if (ch == '}') {
state = BLOCK_CLOSE;
if (ch == '}') {
state = BLOCK_CLOSE;
@@
-324,8
+340,9
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
}
if (ch == '=') {
}
if (ch == '=') {
- if (field_name[field_idx][idx] != '\0')
+ if (field_name[field_idx][idx] != '\0')
{
goto errout;
goto errout;
+ }
switch (field_idx) {
case 0:
switch (field_idx) {
case 0:
@@
-365,11
+382,11
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
idx = 0;
break;
case 4:
idx = 0;
break;
case 4:
- state = VALUE_
GROUP
;
- if (block->
group
) {
- free(block->
group
);
- block->
group
= NULL;
- block->
group
_len = 0;
+ state = VALUE_
OPTION
;
+ if (block->
option
) {
+ free(block->
option
);
+ block->
option
= NULL;
+ block->
option
_len = 0;
}
idx = 0;
break;
}
idx = 0;
break;
@@
-389,17
+406,25
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
break;
}
break;
}
- if (ch == '\n')
+ if (ch == '\n')
{
goto errout;
goto errout;
+ }
if (field_name[field_idx][idx] != ch) {
if (field_name[field_idx][idx] != ch) {
- ungetc(ch, fp);
- while (--idx >= 0)
- ungetc(field_name[field_idx][idx], fp);
+ if (ungetc(ch, fp) != ch) {
+ ErrPrint("ungetc: %s\n", strerror(errno));
+ }
+
+ while (--idx >= 0) {
+ if (ungetc(field_name[field_idx][idx], fp) != field_name[field_idx][idx]) {
+ ErrPrint("ungetc: %s\n", strerror(errno));
+ }
+ }
field_idx++;
field_idx++;
- if (field_name[field_idx] == NULL)
+ if (field_name[field_idx] == NULL)
{
goto errout;
goto errout;
+ }
idx = 0;
break;
idx = 0;
break;
@@
-496,25
+521,25
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
idx++;
break;
idx++;
break;
- case VALUE_
GROUP
:
- if (idx == block->
group
_len) {
- block->
group
_len += 256;
- block->
group = realloc(block->group, block->group
_len);
- if (!block->
group
) {
+ case VALUE_
OPTION
:
+ if (idx == block->
option
_len) {
+ block->
option
_len += 256;
+ block->
option = realloc(block->option, block->option
_len);
+ if (!block->
option
) {
CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
}
}
if (ch == '\n') {
CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
}
}
if (ch == '\n') {
- block->
group
[idx] = '\0';
+ block->
option
[idx] = '\0';
state = FIELD;
idx = 0;
field_idx = 0;
break;
}
state = FIELD;
idx = 0;
field_idx = 0;
break;
}
- block->
group
[idx] = ch;
+ block->
option
[idx] = ch;
idx++;
break;
case VALUE_ID:
idx++;
break;
case VALUE_ID:
@@
-541,8
+566,9
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
case BLOCK_CLOSE:
if (!block->file) {
block->file = strdup(util_uri_to_path(handle->id));
case BLOCK_CLOSE:
if (!block->file) {
block->file = strdup(util_uri_to_path(handle->id));
- if (!block->file)
+ if (!block->file)
{
goto errout;
goto errout;
+ }
}
i = 0;
}
i = 0;
@@
-554,14
+580,15
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
i++;
}
i++;
}
- if (!handlers[i].type)
+ if (!handlers[i].type)
{
ErrPrint("Unknown block type: %s\n", block->type);
ErrPrint("Unknown block type: %s\n", block->type);
+ }
free(block->file);
free(block->type);
free(block->part);
free(block->data);
free(block->file);
free(block->type);
free(block->part);
free(block->data);
- free(block->
group
);
+ free(block->
option
);
free(block->id);
free(block);
block = NULL;
free(block->id);
free(block);
block = NULL;
@@
-574,12
+601,15
@@
int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
} /* switch */
} /* while */
} /* switch */
} /* while */
- if (state != UNKNOWN)
+ if (state != UNKNOWN)
{
goto errout;
goto errout;
+ }
update_end(handle, is_pd);
update_end(handle, is_pd);
- fclose(fp);
+ if (fclose(fp) != 0) {
+ ErrPrint("fclose: %s\n", strerror(errno));
+ }
return 0;
errout:
return 0;
errout:
@@
-589,15
+619,17
@@
errout:
free(block->type);
free(block->part);
free(block->data);
free(block->type);
free(block->part);
free(block->data);
- free(block->
group
);
+ free(block->
option
);
free(block->id);
free(block);
}
update_end(handle, is_pd);
free(block->id);
free(block);
}
update_end(handle, is_pd);
- fclose(fp);
- return -EINVAL;
+ if (fclose(fp) != 0) {
+ ErrPrint("fclose: %s\n", strerror(errno));
+ }
+ return LB_STATUS_ERROR_INVALID;
}
/* End of a file */
}
/* End of a file */