Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
fbed4b59
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fbed4b59
编写于
3月 06, 2022
作者:
O
openharmony_ci
提交者:
Gitee
3月 06, 2022
浏览文件
操作
浏览文件
下载
差异文件
!376 bugfix paramservice can not trim quoted strings
Merge pull request !376 from handy/0306
上级
1cf91618
ae14f15d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
107 addition
and
31 deletion
+107
-31
services/param/service/param_service.c
services/param/service/param_service.c
+107
-31
未找到文件。
services/param/service/param_service.c
浏览文件 @
fbed4b59
...
...
@@ -15,6 +15,7 @@
#include "param_service.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
...
...
@@ -67,7 +68,9 @@ static int AddParam(WorkSpace *workSpace, const char *name, const char *value, u
PARAM_CHECK
(
offset
>
0
,
return
PARAM_CODE_REACHED_MAX
,
"Failed to allocate name %s"
,
name
);
SaveIndex
(
&
node
->
dataIndex
,
offset
);
}
*
dataIndex
=
node
->
dataIndex
;
if
(
dataIndex
!=
NULL
)
{
*
dataIndex
=
node
->
dataIndex
;
}
return
0
;
}
...
...
@@ -111,13 +114,15 @@ static int CheckParamValue(const WorkSpace *workSpace, const ParamTrieNode *node
int
WriteParam
(
const
WorkSpace
*
workSpace
,
const
char
*
name
,
const
char
*
value
,
uint32_t
*
dataIndex
,
int
onlyAdd
)
{
PARAM_CHECK
(
workSpace
!=
NULL
&&
dataIndex
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid workSpace"
);
PARAM_CHECK
(
workSpace
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid workSpace"
);
PARAM_CHECK
(
value
!=
NULL
&&
name
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid name or value"
);
ParamTrieNode
*
node
=
FindTrieNode
(
workSpace
,
name
,
strlen
(
name
),
NULL
);
int
ret
=
CheckParamValue
(
workSpace
,
node
,
name
,
value
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Invalid param value param: %s=%s"
,
name
,
value
);
if
(
node
!=
NULL
&&
node
->
dataIndex
!=
0
)
{
*
dataIndex
=
node
->
dataIndex
;
if
(
dataIndex
!=
NULL
)
{
*
dataIndex
=
node
->
dataIndex
;
}
if
(
onlyAdd
)
{
return
0
;
}
...
...
@@ -164,7 +169,7 @@ static char *BuildKey(ParamWorkSpace *workSpace, const char *format, ...)
size_t
buffSize
=
sizeof
(
workSpace
->
buffer
);
int
len
=
vsnprintf_s
(
workSpace
->
buffer
,
buffSize
,
buffSize
-
1
,
format
,
vargs
);
va_end
(
vargs
);
if
(
len
>
0
&&
len
<
buffSize
)
{
if
(
len
>
0
&&
(
size_t
)
len
<
buffSize
)
{
workSpace
->
buffer
[
len
]
=
'\0'
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
workSpace
->
buffer
[
i
]
==
'|'
)
{
...
...
@@ -521,35 +526,107 @@ PARAM_STATIC int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *m
return
0
;
}
static
int
LoadOneParam_
(
char
*
line
,
uint32_t
mode
,
const
char
*
exclude
[],
uint32_t
count
)
{
char
*
name
;
char
*
value
;
char
*
pos
;
// Skip spaces
name
=
line
;
while
(
isspace
(
*
name
)
&&
(
*
name
!=
'\0'
))
{
name
++
;
}
// Empty line
if
(
*
name
==
'\0'
)
{
return
0
;
}
// Comment line
if
(
*
name
==
'#'
)
{
return
0
;
}
value
=
name
;
// find the first delimiter '='
while
(
*
value
!=
'\0'
)
{
if
(
*
value
==
'='
)
{
(
*
value
)
=
'\0'
;
value
=
value
+
1
;
break
;
}
value
++
;
}
// empty name, just ignore this line
if
(
*
name
==
'\0'
)
{
return
0
;
}
// Trim the ending spaces of name
pos
=
value
-
1
;
pos
-=
1
;
while
(
isspace
(
*
pos
)
&&
pos
>
name
)
{
(
*
pos
)
=
'\0'
;
pos
--
;
}
// Filter excluded parameters
for
(
uint32_t
i
=
0
;
i
<
count
;
i
++
)
{
if
(
strncmp
(
name
,
exclude
[
i
],
strlen
(
exclude
[
i
]))
==
0
)
{
return
0
;
}
}
// Skip spaces for value
while
(
isspace
(
*
value
)
&&
(
*
value
!=
'\0'
))
{
value
++
;
}
// Trim the ending spaces of value
pos
=
value
+
strlen
(
value
);
pos
--
;
while
(
isspace
(
*
pos
)
&&
pos
>
value
)
{
(
*
pos
)
=
'\0'
;
pos
--
;
}
// Strip starting and ending " for value
if
((
*
value
==
'"'
)
&&
(
pos
>
value
)
&&
(
*
pos
==
'"'
))
{
value
=
value
+
1
;
*
pos
=
'\0'
;
}
int
ret
=
CheckParamName
(
name
,
0
);
// Invalid name, just ignore
if
(
ret
!=
0
)
{
return
0
;
}
PARAM_LOGV
(
"Add default parameter [%s] [%s]"
,
name
,
value
);
return
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
name
,
value
,
NULL
,
mode
&
LOAD_PARAM_ONLY_ADD
);
}
static
int
LoadDefaultParam_
(
const
char
*
fileName
,
uint32_t
mode
,
const
char
*
exclude
[],
uint32_t
count
)
{
// max length for each line of para files: max name length + max value length + spaces
#define PARAM_LINE_MAX_LENGTH (PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10)
uint32_t
paramNum
=
0
;
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
PARAM_CHECK
(
fp
!=
NULL
,
return
-
1
,
"Open file %s fail"
,
fileName
);
char
*
buff
=
calloc
(
1
,
sizeof
(
SubStringInfo
)
*
(
SUBSTR_INFO_VALUE
+
1
)
+
PARAM_BUFFER_SIZE
);
PARAM_CHECK
(
buff
!=
NULL
,
(
void
)
fclose
(
fp
);
return
-
1
,
"Failed to alloc memory for load %s"
,
fileName
);
SubStringInfo
*
info
=
(
SubStringInfo
*
)(
buff
+
PARAM_BUFFER_SIZE
);
while
(
fgets
(
buff
,
PARAM_BUFFER_SIZE
,
fp
)
!=
NULL
)
{
buff
[
PARAM_BUFFER_SIZE
-
1
]
=
'\0'
;
int
subStrNumber
=
GetSubStringInfo
(
buff
,
strlen
(
buff
),
'='
,
info
,
SUBSTR_INFO_VALUE
+
1
);
if
(
subStrNumber
<=
SUBSTR_INFO_VALUE
)
{
continue
;
}
// 过滤
for
(
uint32_t
i
=
0
;
i
<
count
;
i
++
)
{
if
(
strncmp
(
info
[
0
].
value
,
exclude
[
i
],
strlen
(
exclude
[
i
]))
==
0
)
{
PARAM_LOGI
(
"Do not set %s parameters"
,
info
[
0
].
value
);
continue
;
}
}
int
ret
=
CheckParamName
(
info
[
0
].
value
,
0
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Illegal param name %s"
,
info
[
0
].
value
);
PARAM_LOGV
(
"Add default parameter %s %s"
,
info
[
0
].
value
,
info
[
1
].
value
);
uint32_t
dataIndex
=
0
;
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
info
[
0
].
value
,
info
[
1
].
value
,
&
dataIndex
,
mode
&
LOAD_PARAM_ONLY_ADD
);
if
(
fp
==
NULL
)
{
return
-
1
;
}
char
*
buff
=
calloc
(
1
,
PARAM_LINE_MAX_LENGTH
);
if
(
buff
==
NULL
)
{
(
void
)
fclose
(
fp
);
return
-
1
;
}
while
(
fgets
(
buff
,
PARAM_LINE_MAX_LENGTH
,
fp
)
!=
NULL
)
{
buff
[
PARAM_LINE_MAX_LENGTH
-
1
]
=
'\0'
;
int
ret
=
LoadOneParam_
(
buff
,
mode
,
exclude
,
count
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to set param %d %s"
,
ret
,
buff
);
paramNum
++
;
}
...
...
@@ -625,9 +702,8 @@ static int LoadParamFromCmdLine(void)
PARAM_LOGV
(
"Add param from cmdline %s %s"
,
cmdLines
[
i
],
value
);
ret
=
CheckParamName
(
cmdLines
[
i
],
0
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Invalid name %s"
,
cmdLines
[
i
]);
uint32_t
dataIndex
=
0
;
PARAM_LOGV
(
"**** cmdLines[%d] %s, value %s"
,
i
,
cmdLines
[
i
],
value
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
cmdLines
[
i
],
value
,
&
dataIndex
,
0
);
ret
=
WriteParam
(
&
g_paramWorkSpace
.
paramSpace
,
cmdLines
[
i
],
value
,
NULL
,
0
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to write param %s %s"
,
cmdLines
[
i
],
value
);
}
else
{
PARAM_LOGE
(
"Can not find arrt %s"
,
cmdLines
[
i
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录