-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathutils.c
More file actions
63 lines (50 loc) · 1.26 KB
/
utils.c
File metadata and controls
63 lines (50 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// utils.c - Assorted utilities for networking plugin - some sourced from internet and possibly modified (public domain)
//
// Part of grblHAL
//
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include "grbl/plugins.h"
#include "grbl/nuts_bolts.h"
#include "utils.h"
bool is_valid_port (uint16_t port)
{
return port > 0;
}
bool is_valid_hostname (const char *hostname)
{
bool ok = true;
char *s = (char *)hostname;
int c;
size_t len = 0;
while(ok) {
if((c = *s++) == '\0')
break;
len++;
ok = c == '-' || isdigit(c) || (isalpha(c) && c != ' ');
}
return ok && len >= HOSTNAME_LENGTH_MIN && len <= HOSTNAME_LENGTH_MAX;
}
bool is_valid_ssid (const char *ssid)
{
bool ok = true;
char *s = (char *)ssid;
int c;
size_t len = 0;
while(ok) {
if((c = *s++) == '\0')
break;
len++;
ok = isprint(c);
}
return ok && len >= SSID_LENGTH_MIN && len <= SSID_LENGTH_MAX;
}
bool is_valid_password (const char *password)
{
size_t len = strlen(password);
if(len == strlen(HIDDEN_PASSWORD) && memcmp(password, HIDDEN_PASSWORD, len) == 0)
len = PASSWORD_LENGTH_MAX + 1;
return len >= PASSWORD_LENGTH_MIN && len <= PASSWORD_LENGTH_MAX;
}