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
Show 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 )
}
}
// Lua: wifi.sta.gethostname()
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)
{
const char* charset="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-";
size_t span = strspn(hostname, charset);
if(hostname[span] == '\0' && hostname[span - 1] != '-' && hostname[0] != '-' && (len >= 1 && len <= 32))
uint8 status;
if(hostname[0]!='-' && hostname[len-1]!='-' && (len >= 1 && len <= 32))
{
NODE_DBG("\n\tstring is: \"%s\"\n\tlength is: %d\n", hostname, len )
;
if(wifi_station_set_hostname((char*)
hostname
)
)
uint8 i=0
;
while(
hostname
[i]
)
{
NODE_DBG("\n\twifi_sta_sethostname returned: true\n");
return 1; //pass
}
else
if(!(isalnum(hostname[i])||hostname[i]=='-'))
{
NODE_DBG("\n\twifi_sta_sethostname returned: false\n");
return 0; //fail
return 2;
}
i++;
}
status=wifi_station_set_hostname((char*)hostname);
}
else
{
NODE_DBG("\n\tInvalid hostname!\n");
return 2; //Invalid hostname
return 2;
}
return status;
}
// Lua: wifi.sta.sethostname()
...
...
@@ -961,7 +957,7 @@ static int wifi_sta_sethostname_lua( lua_State* L )
size_t len;
const char *hostname = luaL_checklstring(L, 1, &len);
uint8 retval = wifi_sta_sethostname(hostname, len);
NODE_DBG("\n\twifi_sta_sethostname returned: %
d
\n", retval);
NODE_DBG("\n\t
string is: \"%s\"\n\tlength is: %u\t
wifi_sta_sethostname returned: %
u
\n",
hostname, len,
retval);
if(retval==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