Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
8be30350
Commit
8be30350
authored
Mar 30, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mg_set_option(): allow NULL as value. Fast success if old_value == new_value.
parent
2609a2ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
40 deletions
+50
-40
mongoose.c
mongoose.c
+50
-40
No files found.
mongoose.c
View file @
8be30350
...
...
@@ -4415,53 +4415,63 @@ const char *mg_set_option(struct mg_server *server, const char *name,
const
char
*
value
)
{
int
ind
=
get_option_index
(
name
);
const
char
*
error_msg
=
NULL
;
char
**
v
=
NULL
;
if
(
ind
<
0
)
{
error_msg
=
"No such option"
;
}
else
{
if
(
server
->
config_options
[
ind
]
!=
NULL
)
{
free
(
server
->
config_options
[
ind
]);
}
server
->
config_options
[
ind
]
=
mg_strdup
(
value
);
DBG
((
"%s [%s]"
,
name
,
value
));
if
(
ind
<
0
)
return
"No such option"
;
v
=
&
server
->
config_options
[
ind
];
if
(
ind
==
LISTENING_PORT
)
{
int
port
=
ns_bind
(
&
server
->
ns_server
,
value
);
if
(
port
<
0
)
{
error_msg
=
"Cannot bind to port"
;
}
else
{
ns_sock_to_str
(
server
->
ns_server
.
listening_sock
,
server
->
local_ip
,
sizeof
(
server
->
local_ip
),
0
);
if
(
!
strcmp
(
value
,
"0"
))
{
char
buf
[
10
];
mg_snprintf
(
buf
,
sizeof
(
buf
),
"%d"
,
port
);
free
(
server
->
config_options
[
ind
]);
server
->
config_options
[
ind
]
=
mg_strdup
(
buf
);
}
// Return success immediately if setting to the same value
if
((
*
v
==
NULL
&&
value
==
NULL
)
||
(
value
!=
NULL
&&
*
v
!=
NULL
&&
!
strcmp
(
value
,
*
v
)))
{
return
NULL
;
}
if
(
*
v
!=
NULL
)
{
free
(
*
v
);
*
v
=
NULL
;
}
if
(
value
==
NULL
)
return
NULL
;
*
v
=
mg_strdup
(
value
);
DBG
((
"%s [%s]"
,
name
,
*
v
));
if
(
ind
==
LISTENING_PORT
)
{
int
port
=
ns_bind
(
&
server
->
ns_server
,
value
);
if
(
port
<
0
)
{
error_msg
=
"Cannot bind to port"
;
}
else
{
ns_sock_to_str
(
server
->
ns_server
.
listening_sock
,
server
->
local_ip
,
sizeof
(
server
->
local_ip
),
0
);
if
(
!
strcmp
(
value
,
"0"
))
{
char
buf
[
10
];
mg_snprintf
(
buf
,
sizeof
(
buf
),
"%d"
,
port
);
free
(
*
v
);
*
v
=
mg_strdup
(
buf
);
}
}
#ifndef _WIN32
}
else
if
(
ind
==
RUN_AS_USER
)
{
struct
passwd
*
pw
;
if
((
pw
=
getpwnam
(
value
))
==
NULL
)
{
error_msg
=
"Unknown user"
;
}
else
if
(
setgid
(
pw
->
pw_gid
)
!=
0
)
{
error_msg
=
"setgid() failed"
;
}
else
if
(
setuid
(
pw
->
pw_uid
)
!=
0
)
{
error_msg
=
"setuid() failed"
;
}
}
else
if
(
ind
==
RUN_AS_USER
)
{
struct
passwd
*
pw
;
if
((
pw
=
getpwnam
(
value
))
==
NULL
)
{
error_msg
=
"Unknown user"
;
}
else
if
(
setgid
(
pw
->
pw_gid
)
!=
0
)
{
error_msg
=
"setgid() failed"
;
}
else
if
(
setuid
(
pw
->
pw_uid
)
!=
0
)
{
error_msg
=
"setuid() failed"
;
}
#endif
#ifdef NS_ENABLE_SSL
}
else
if
(
ind
==
SSL_CERTIFICATE
)
{
int
res
=
ns_set_ssl_cert
(
&
server
->
ns_server
,
value
);
if
(
res
==
-
2
)
{
error_msg
=
"Cannot load PEM"
;
}
else
if
(
res
==
-
3
)
{
error_msg
=
"SSL not enabled"
;
}
else
if
(
res
==
-
1
)
{
error_msg
=
"SSL_CTX_new() failed"
;
}
#endif
}
else
if
(
ind
==
SSL_CERTIFICATE
)
{
int
res
=
ns_set_ssl_cert
(
&
server
->
ns_server
,
value
);
if
(
res
==
-
2
)
{
error_msg
=
"Cannot load PEM"
;
}
else
if
(
res
==
-
3
)
{
error_msg
=
"SSL not enabled"
;
}
else
if
(
res
==
-
1
)
{
error_msg
=
"SSL_CTX_new() failed"
;
}
#endif
}
return
error_msg
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment