Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
fcbf58cf
Commit
fcbf58cf
authored
Jan 02, 2016
by
dnc40085
Browse files
Rewrote wifi_sta_gethostname in wifi module.
parent
b2190e4d
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/wifi.c
View file @
fcbf58cf
...
@@ -920,7 +920,6 @@ static int wifi_station_listap( lua_State* L )
...
@@ -920,7 +920,6 @@ static int wifi_station_listap( lua_State* L )
}
}
}
}
// Lua: wifi.sta.gethostname()
// Lua: wifi.sta.gethostname()
static
int
wifi_sta_gethostname
(
lua_State
*
L
)
static
int
wifi_sta_gethostname
(
lua_State
*
L
)
{
{
...
@@ -931,28 +930,25 @@ static int wifi_sta_gethostname( lua_State* L )
...
@@ -931,28 +930,25 @@ static int wifi_sta_gethostname( lua_State* L )
static
uint8
wifi_sta_sethostname
(
const
char
*
hostname
,
size_t
len
)
static
uint8
wifi_sta_sethostname
(
const
char
*
hostname
,
size_t
len
)
{
{
const
char
*
charset
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-"
;
uint8
status
;
size_t
span
=
strspn
(
hostname
,
charset
);
if
(
hostname
[
0
]
!=
'-'
&&
hostname
[
len
-
1
]
!=
'-'
&&
(
len
>=
1
&&
len
<=
32
))
if
(
hostname
[
span
]
==
'\0'
&&
hostname
[
span
-
1
]
!=
'-'
&&
hostname
[
0
]
!=
'-'
&&
(
len
>=
1
&&
len
<=
32
))
{
{
NODE_DBG
(
"
\n\t
string is:
\"
%s
\"\n\t
length is: %d
\n
"
,
hostname
,
len
);
uint8
i
=
0
;
if
(
wifi_station_set_hostname
((
char
*
)
hostname
))
while
(
hostname
[
i
])
{
NODE_DBG
(
"
\n\t
wifi_sta_sethostname returned: true
\n
"
);
return
1
;
//pass
}
else
{
{
NODE_DBG
(
"
\n\t
wifi_sta_sethostname returned: false
\n
"
);
if
(
!
(
isalnum
(
hostname
[
i
])
||
hostname
[
i
]
==
'-'
))
return
0
;
//fail
{
}
return
2
;
}
i
++
;
}
status
=
wifi_station_set_hostname
((
char
*
)
hostname
);
}
}
else
else
{
{
NODE_DBG
(
"
\n\t
Invalid hostname!
\n
"
);
return
2
;
return
2
;
//Invalid hostname
}
}
return
status
;
}
}
// Lua: wifi.sta.sethostname()
// Lua: wifi.sta.sethostname()
...
@@ -961,7 +957,7 @@ static int wifi_sta_sethostname_lua( lua_State* L )
...
@@ -961,7 +957,7 @@ static int wifi_sta_sethostname_lua( lua_State* L )
size_t
len
;
size_t
len
;
const
char
*
hostname
=
luaL_checklstring
(
L
,
1
,
&
len
);
const
char
*
hostname
=
luaL_checklstring
(
L
,
1
,
&
len
);
uint8
retval
=
wifi_sta_sethostname
(
hostname
,
len
);
uint8
retval
=
wifi_sta_sethostname
(
hostname
,
len
);
NODE_DBG
(
"
\n\t
wifi_sta_sethostname returned: %
d
\n
"
,
retval
);
NODE_DBG
(
"
\n\t
string is:
\"
%s
\"\n\t
length is: %u
\t
wifi_sta_sethostname returned: %
u
\n
"
,
hostname
,
len
,
retval
);
if
(
retval
==
0
)
if
(
retval
==
0
)
{
{
lua_pushboolean
(
L
,
0
);
lua_pushboolean
(
L
,
0
);
...
...
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