本文整理汇总了C++中os_strncmp函数的典型用法代码示例。如果您正苦于以下问题:C++ os_strncmp函数的具体用法?C++ os_strncmp怎么用?C++ os_strncmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了os_strncmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: httpdProcessRequest
//This is called when the headers have been received and the connection is ready to send
//the result headers and data.
//We need to find the CGI function to call, call it, and dependent on what it returns either
//find the next cgi function, wait till the cgi data is sent or close up the connection.
static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) {
int r;
int i=0;
if (conn->url==NULL) {
os_printf("WtF? url = NULL\n");
return; //Shouldn't happen
}
//See if we can find a CGI that's happy to handle the request.
while (1) {
//Look up URL in the built-in URL table.
while (builtInUrls[i].url!=NULL) {
int match=0;
//See if there's a literal match
if (os_strcmp(builtInUrls[i].url, conn->url)==0) match=1;
//See if there's a wildcard match
if (builtInUrls[i].url[os_strlen(builtInUrls[i].url)-1]=='*' &&
os_strncmp(builtInUrls[i].url, conn->url, os_strlen(builtInUrls[i].url)-1)==0) match=1;
if (match) {
os_printf("Is url index %d\n", i);
conn->cgiData=NULL;
conn->cgi=builtInUrls[i].cgiCb;
conn->cgiArg=builtInUrls[i].cgiArg;
break;
}
i++;
}
if (builtInUrls[i].url==NULL) {
//Drat, we're at the end of the URL table. This usually shouldn't happen. Well, just
//generate a built-in 404 to handle this.
os_printf("%s not found. 404!\n", conn->url);
httpdSend(conn, httpNotFoundHeader, -1);
xmitSendBuff(conn);
conn->cgi=NULL; //mark for destruction
return;
}
//Okay, we have a CGI function that matches the URL. See if it wants to handle the
//particular URL we're supposed to handle.
r=conn->cgi(conn);
if (r==HTTPD_CGI_MORE) {
//Yep, it's happy to do so and has more data to send.
xmitSendBuff(conn);
return;
} else if (r==HTTPD_CGI_DONE) {
//Yep, it's happy to do so and already is done sending data.
xmitSendBuff(conn);
conn->cgi=NULL; //mark conn for destruction
return;
} else if (r==HTTPD_CGI_NOTFOUND || r==HTTPD_CGI_AUTHENTICATED) {
//URL doesn't want to handle the request: either the data isn't found or there's no
//need to generate a login screen.
i++; //look at next url the next iteration of the loop.
}
}
}
示例2: start_resolve_dh_server
LOCAL void ICACHE_FLASH_ATTR start_resolve_dh_server() {
static ip_addr_t ip;
const char *server = dhrequest_current_server();
char host[os_strlen(server) + 1];
const char *fr = server;
while(*fr != ':') {
fr++;
if(*fr == 0) {
fr = 0;
break;
}
}
if(fr) {
fr++;
if(*fr != '/')
fr = 0;
}
if (fr) {
while (*fr == '/')
fr++;
int i = 0;
while (*fr != '/' && *fr != ':' && *fr != 0)
host[i++] = *fr++;
// read port if present
int port = 0;
if(*fr == ':') {
unsigned char d;
fr++;
while ( (d = *fr - 0x30) < 10) {
fr++;
port = port*10 + d;
if(port > 0xFFFF)
break;
}
}
if(port && port < 0xFFFF)
mDHConnector.proto.tcp->remote_port = port;
else if (os_strncmp(dhrequest_current_server(), "https", 5) == 0)
mDHConnector.proto.tcp->remote_port = 443; // HTTPS default port
else
mDHConnector.proto.tcp->remote_port = 80; //HTTP default port
host[i] = 0;
dhdebug("Resolving %s", host);
err_t r = espconn_gethostbyname(&mDHConnector, host, &ip, resolve_cb);
if(r == ESPCONN_OK) {
resolve_cb(host, &ip, NULL);
} else if(r != ESPCONN_INPROGRESS) {
dhesperrors_espconn_result("Resolving failed:", r);
arm_repeat_timer(RETRY_CONNECTION_INTERVAL_MS);
}
} else {
dhdebug("Can not find scheme in server url");
}
}
示例3: os_strstr
char * os_strstr(const char *haystack, const char *needle)
{
size_t len = os_strlen(needle);
while (*haystack) {
if (os_strncmp(haystack, needle, len) == 0)
return (char *) haystack;
haystack++;
}
return NULL;
}
示例4: eap_sim_db_open_socket
static int eap_sim_db_open_socket(struct eap_sim_db_data *data)
{
struct sockaddr_un addr;
static int counter = 0;
if (os_strncmp(data->fname, "unix:", 5) != 0)
return -1;
data->sock = socket(PF_UNIX, SOCK_DGRAM, 0);
if (data->sock < 0) {
wpa_printf(MSG_INFO, "socket(eap_sim_db): %s", strerror(errno));
return -1;
}
os_memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
os_snprintf(addr.sun_path, sizeof(addr.sun_path),
"/tmp/eap_sim_db_%d-%d", getpid(), counter++);
os_free(data->local_sock);
data->local_sock = os_strdup(addr.sun_path);
if (data->local_sock == NULL) {
close(data->sock);
data->sock = -1;
return -1;
}
if (bind(data->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
wpa_printf(MSG_INFO, "bind(eap_sim_db): %s", strerror(errno));
close(data->sock);
data->sock = -1;
return -1;
}
os_memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
os_strlcpy(addr.sun_path, data->fname + 5, sizeof(addr.sun_path));
if (connect(data->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
wpa_printf(MSG_INFO, "connect(eap_sim_db): %s",
strerror(errno));
wpa_hexdump_ascii(MSG_INFO, "HLR/AuC GW socket",
(u8 *) addr.sun_path,
os_strlen(addr.sun_path));
close(data->sock);
data->sock = -1;
unlink(data->local_sock);
os_free(data->local_sock);
data->local_sock = NULL;
return -1;
}
eloop_register_read_sock(data->sock, eap_sim_db_receive, data, NULL);
return 0;
}
示例5: tcpserver_recv_callback
static void ICACHE_FLASH_ATTR
tcpserver_recv_callback(void *arg, char *pdata, uint16_t length)
{
if(os_strncmp(OTA_UPGRADE_COMMAND, pdata, length) == 0)
{
remot_info *phost_info = NULL;
os_printf("Upgrade command received.\r\n");
espconn_get_connection_info(&tcp_server, &phost_info, 0);
ota_upgrade(phost_info);
}
}
示例6: wpa_supplicant_ctrl_iface_blacklist
static int wpa_supplicant_ctrl_iface_blacklist(
struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
{
struct wpa_ssid *ssid;
u8 bssid[ETH_ALEN];
struct wpa_blacklist *e;
char *pos, *end;
int ret;
/* cmd: "BLACKLIST [<BSSID>]" */
if (*cmd == '\0') {
pos = buf;
end = buf + buflen;
e = wpa_s->blacklist;
while (e) {
ret = os_snprintf(pos, end-pos,
"%02x:%02x:%02x:%02x:%02x:%02x\n",
e->bssid[0],
e->bssid[1],
e->bssid[2],
e->bssid[3],
e->bssid[4],
e->bssid[5]);
if (ret < 0 || ret >= end - pos)
return pos - buf;
pos += ret;
e = e->next;
}
return pos - buf;
}
wpa_printf(MSG_DEBUG, "CTRL_IFACE: bssid='%s'", cmd);
++cmd;
if (os_strncmp(cmd, "clear", 5) == 0) {
wpa_blacklist_clear(wpa_s);
return 0;
}
if (hwaddr_aton(cmd, bssid)) {
wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", cmd);
return -1;
}
/*
* Add the BSSID twice, so its count will be 2, causing it to be
* skipped when processing scan results.
*/
ret = wpa_blacklist_add(wpa_s, bssid);
if (ret != 0)
return ret;
return wpa_blacklist_add(wpa_s, bssid);
}
示例7: user_udp_recv
LOCAL void ICACHE_FLASH_ATTR
user_udp_recv(void *arg, char *pusrdata, unsigned short length)
{
char DeviceBuffer[40] = { 0 };
char Device_mac_buffer[60] = { 0 };
char hwaddr[6];
struct ip_info ipconfig;
if (wifi_get_opmode() != STATION_MODE) {
wifi_get_ip_info(SOFTAP_IF, &ipconfig);
wifi_get_macaddr(SOFTAP_IF, hwaddr);
if (!ip_addr_netcmp
((struct ip_addr *)ptrespconn.proto.udp->remote_ip,
&ipconfig.ip, &ipconfig.netmask)) {
//udp packet is received from ESP8266 station
wifi_get_ip_info(STATION_IF, &ipconfig);
wifi_get_macaddr(STATION_IF, hwaddr);
} else {
//udp packet is received from ESP8266 softAP
}
} else {
//udp packet is received from ESP8266 station
wifi_get_ip_info(STATION_IF, &ipconfig);
wifi_get_macaddr(STATION_IF, hwaddr);
}
if (pusrdata == NULL)
return;
if (length == os_strlen(device_find_request) &&
os_strncmp(pusrdata, device_find_request,
os_strlen(device_find_request)) == 0) {
//received device find message
os_sprintf(DeviceBuffer, "%s" MACSTR " " IPSTR,
device_find_response_ok, MAC2STR(hwaddr),
IP2STR(&ipconfig.ip));
os_printf("%s\n", DeviceBuffer);
length = os_strlen(DeviceBuffer);
//if received "Are You ESP8266 ?" ,
//response "Yes,I'm ESP8266!" + ESP8266 mac + ESP8266 ip
espconn_sent(&ptrespconn, DeviceBuffer, length);
} else {
//received some other data
}
}
示例8: p2p_wfa_service_adv
static int p2p_wfa_service_adv(struct p2p_data *p2p)
{
struct p2ps_advertisement *adv;
for (adv = p2p->p2ps_adv_list; adv; adv = adv->next) {
if (os_strncmp(adv->svc_name, P2PS_WILD_HASH_STR,
os_strlen(P2PS_WILD_HASH_STR)) == 0)
return 1;
}
return 0;
}
示例9: httpdParseHeader
static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
int i;
char first_line = false;
if (os_strncmp(h, "GET ", 4)==0) {
conn->requestType = HTTPD_METHOD_GET;
first_line = true;
} else if (os_strncmp(h, "Host:", 5)==0) {
i=5;
while (h[i]==' ') i++;
conn->hostName=&h[i];
} else if (os_strncmp(h, "POST ", 5)==0) {
conn->requestType = HTTPD_METHOD_POST;
first_line = true;
}
if (first_line) {
char *e;
//Skip past the space after POST/GET
i=0;
while (h[i]!=' ') i++;
conn->url=h+i+1;
//Figure out end of url.
e=(char*)os_strstr(conn->url, " ");
if (e==NULL) return; // ?
*e=0; //terminate url part
//Parse out the URL part before the GET parameters.
conn->getArgs=(char*)os_strstr(conn->url, "?");
if (conn->getArgs!=0) {
*conn->getArgs=0;
conn->getArgs++;
TESTP("GET args = %s\n", conn->getArgs);
} else {
conn->getArgs=NULL;
}
}
}
示例10: httpdParseHeader
//Parse a line of header data and modify the connection data accordingly.
static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) {
int i;
// os_printf("Got header %s\n", h);
if (os_strncmp(h, "GET ", 4)==0 || os_strncmp(h, "POST ", 5)==0) {
char *e;
//Skip past the space after POST/GET
i=0;
while (h[i]!=' ') i++;
conn->url=h+i+1;
//Figure out end of url.
e=(char*)os_strstr(conn->url, " ");
if (e==NULL) return; //wtf?
*e=0; //terminate url part
os_printf("URL = %s\n", conn->url);
//Parse out the URL part before the GET parameters.
conn->getArgs=(char*)os_strstr(conn->url, "?");
if (conn->getArgs!=0) {
*conn->getArgs=0;
conn->getArgs++;
os_printf("GET args = %s\n", conn->getArgs);
} else {
conn->getArgs=NULL;
}
} else if (os_strncmp(h, "Content-Length: ", 16)==0) {
i=0;
//Skip trailing spaces
while (h[i]!=' ') i++;
//Get POST data length
conn->postLen=atoi(h+i+1);
//Clamp if too big. Hmm, maybe we should error out instead?
if (conn->postLen>MAX_POST) conn->postLen=MAX_POST;
os_printf("Mallocced buffer for %d bytes of post data.\n", conn->postLen);
//Alloc the memory.
conn->postBuff=(char*)os_malloc(conn->postLen+1);
conn->priv->postPos=0;
}
}
示例11: wpas_dbus_new_decompose_object_path
/**
* wpas_dbus_new_decompose_object_path - Decompose an interface object path into parts
* @path: The dbus object path
* @sep: Separating part (e.g., "Networks" or "PersistentGroups")
* @item: (out) The part following the specified separator, if any
* Returns: The object path of the interface this path refers to
*
* For a given object path, decomposes the object path into object id and
* requested part, if those parts exist. The caller is responsible for freeing
* the returned value. The *item pointer points to that allocated value and must
* not be freed separately.
*
* As an example, path = "/fi/w1/wpa_supplicant1/Interfaces/1/Networks/0" and
* sep = "Networks" would result in "/fi/w1/wpa_supplicant1/Interfaces/1"
* getting returned and *items set to point to "0".
*/
char * wpas_dbus_new_decompose_object_path(const char *path, const char *sep,
char **item)
{
const unsigned int dev_path_prefix_len =
os_strlen(WPAS_DBUS_NEW_PATH_INTERFACES "/");
char *obj_path_only;
char *pos;
size_t sep_len;
*item = NULL;
/* Verify that this starts with our interface prefix */
if (os_strncmp(path, WPAS_DBUS_NEW_PATH_INTERFACES "/",
dev_path_prefix_len) != 0)
return NULL; /* not our path */
/* Ensure there's something at the end of the path */
if ((path + dev_path_prefix_len)[0] == '\0')
return NULL;
obj_path_only = os_strdup(path);
if (obj_path_only == NULL)
return NULL;
pos = obj_path_only + dev_path_prefix_len;
pos = os_strchr(pos, '/');
if (pos == NULL)
return obj_path_only; /* no next item on the path */
/* Separate network interface prefix from the path */
*pos++ = '\0';
sep_len = os_strlen(sep);
if (os_strncmp(pos, sep, sep_len) != 0 || pos[sep_len] != '/')
return obj_path_only; /* no match */
/* return a pointer to the requested item */
*item = pos + sep_len + 1;
return obj_path_only;
}
示例12: eap_sim_ext_sim_result
static int eap_sim_ext_sim_result(struct eap_sm *sm, struct eap_sim_data *data,
struct eap_peer_config *conf)
{
char *resp, *pos;
size_t i;
wpa_printf(MSG_DEBUG,
"EAP-SIM: Use result from external SIM processing");
resp = conf->external_sim_resp;
conf->external_sim_resp = NULL;
if (os_strncmp(resp, "GSM-AUTH:", 9) != 0) {
wpa_printf(MSG_DEBUG, "EAP-SIM: Unrecognized external SIM processing response");
os_free(resp);
return -1;
}
pos = resp + 9;
for (i = 0; i < data->num_chal; i++) {
wpa_hexdump(MSG_DEBUG, "EAP-SIM: RAND",
data->rand[i], GSM_RAND_LEN);
if (hexstr2bin(pos, data->kc[i], EAP_SIM_KC_LEN) < 0)
goto invalid;
wpa_hexdump_key(MSG_DEBUG, "EAP-SIM: Kc",
data->kc[i], EAP_SIM_KC_LEN);
pos += EAP_SIM_KC_LEN * 2;
if (*pos != ':')
goto invalid;
pos++;
if (hexstr2bin(pos, data->sres[i], EAP_SIM_SRES_LEN) < 0)
goto invalid;
wpa_hexdump_key(MSG_DEBUG, "EAP-SIM: SRES",
data->sres[i], EAP_SIM_SRES_LEN);
pos += EAP_SIM_SRES_LEN * 2;
if (i + 1 < data->num_chal) {
if (*pos != ':')
goto invalid;
pos++;
}
}
os_free(resp);
return 0;
invalid:
wpa_printf(MSG_DEBUG, "EAP-SIM: Invalid external SIM processing GSM-AUTH response");
os_free(resp);
return -1;
}
示例13: WEBFSOpen
/*****************************************************************************
Function:
WEBFS_HANDLE WEBFSOpen(uint8* cFile)
Description:
Opens a file in the WEBFS2 file system.
Precondition:
None
Parameters:
cFile - a null terminated file name to open
Returns:
An WEBFS_HANDLE to the opened file if found, or WEBFS_INVALID_HANDLE
if the file could not be found or no free handles exist.
***************************************************************************/
WEBFS_HANDLE ICACHE_FLASH_ATTR WEBFSOpen(uint8* cFile)
{
WEBFS_HANDLE hWEBFS;
uint16 nameHash;
int i, len = 0;
uint16 hashCache[16];
uint8 bufname[MAX_FILE_NAME_LEN];
uint8 *ptr;
// Make sure WEBFS is unlocked and we got a filename
if(*cFile == '\0' || isWEBFSLocked == true)
return WEBFS_INVALID_HANDLE;
// Calculate the name hash to speed up searching
for(nameHash = 0, ptr = cFile; *ptr != '\0'; ptr++)
{
nameHash += *ptr;
nameHash <<= 1;
len++;
}
// Find a free file handle to use
for(hWEBFS = 1; hWEBFS <= MAX_WEBFS_OPENFILES; hWEBFS++)
if(WEBFSStubs[hWEBFS].addr == WEBFS_INVALID) break;
if(hWEBFS == MAX_WEBFS_OPENFILES)
return WEBFS_INVALID_HANDLE;
// Read in hashes, and check remainder on a match. Store 8 in cache for performance
for(i = 0; i < numFiles; i++) {
// For new block of 8, read in data
if((i & 0x0F) == 0) {
WEBFSStubs[0].addr = 12 + i*2;
WEBFSStubs[0].bytesRem = 32;
WEBFSGetArray(0, (uint8*)hashCache, 32);
}
// If the hash matches, compare the full filename
if(hashCache[i&0x0F] == nameHash)
{
GetFATRecord(i);
// filename comparison
WEBFSStubs[0].addr = fatCache.string;
WEBFSStubs[0].bytesRem = MAX_FILE_NAME_LEN;
WEBFSGetArray(0, bufname, MAX_FILE_NAME_LEN);
if(os_strncmp(cFile, bufname, len) == 0) { // Filename matches, so return true
WEBFSStubs[hWEBFS].addr = fatCache.data;
WEBFSStubs[hWEBFS].bytesRem = fatCache.len;
WEBFSStubs[hWEBFS].fatID = i;
return hWEBFS;
}
}
}
// No file name matched, so return nothing
return WEBFS_INVALID_HANDLE;
}
示例14: find_json_path
/******************************************************************************
* FunctionName : find_json_path
* Description : find the JSON format tree's path
* Parameters : json -- A pointer to a JSON set up
* path -- A pointer to the JSON format tree's path
* Returns : A pointer to the JSON format tree
*******************************************************************************/
struct jsontree_value *ICACHE_FLASH_ATTR
find_json_path(struct jsontree_context *json, const char *path)
{
struct jsontree_value *v;
const char *start;
const char *end;
int len;
v = json->values[0];
start = path;
do {
end = (const char *)os_strstr(start, "/");
if (end == start) {
break;
}
if (end != NULL) {
len = end - start;
end++;
} else {
len = os_strlen(start);
}
if (v->type != JSON_TYPE_OBJECT) {
v = NULL;
} else {
struct jsontree_object *o;
int i;
o = (struct jsontree_object *)v;
v = NULL;
for (i = 0; i < o->count; i++) {
if (os_strncmp(start, o->pairs[i].name, len) == 0) {
v = o->pairs[i].value;
json->index[json->depth] = i;
json->depth++;
json->values[json->depth] = v;
json->index[json->depth] = 0;
break;
}
}
}
start = end;
} while (end != NULL && *end != '\0' && v != NULL);
json->callback_state = 0;
return v;
}
示例15: wrapd_hostapd_ctrl_iface_process
void
wrapd_hostapd_ctrl_iface_process(struct wrap_demon *aptr, char *msg, char *child_ifname)
{
int addr_off;
char parent_ifname[IFNAMSIZ] = {0};
u_int32_t flags = 0;
if (os_strncmp(msg + HOSTAPD_MSG_ADDR_OFF, "AP-STA-CONNECTED ", 17) == 0) {
flags |= WRAPD_PSTA_FLAG_MAT ;
addr_off = HOSTAPD_MSG_ADDR_OFF + 17;
if (char2addr(msg + addr_off) != 0) {
wrapd_printf("Invalid MAC addr");
return;
}
if (dbdc_ifname) {
os_strncpy(parent_ifname, dbdc_ifname, IFNAMSIZ);
parent_ifname[IFNAMSIZ - 1] = '\0';
flags &= ~WRAPD_PSTA_FLAG_MAT;
} else {
wrapd_ifname_to_parent_ifname(aptr, child_ifname, parent_ifname);
}
wrapd_psta_add(aptr, parent_ifname, child_ifname, (u8 *)(msg + addr_off), flags);
} else if (os_strncmp(msg + HOSTAPD_MSG_ADDR_OFF, "AP-STA-DISCONNECTED ", 20) == 0) {
addr_off = HOSTAPD_MSG_ADDR_OFF + 20;
if (char2addr(msg + addr_off) != 0) {
wrapd_printf("Invalid MAC addr");
return;
}
wrapd_psta_remove(aptr, (u8 *)(msg + addr_off));
} else {
wrapd_printf("Unknow msg(%s)", msg);
}
}