static bool uuid_matched(char *buf, uuid_entry_t *entry) { char uuid[KINETIC_UUID_LENGTH]; /* get UUID */ memset(uuid, 0x00, sizeof(uuid)); if (get_tag_value(buf, KINETIC_UUID_TAG, uuid, sizeof(uuid)) == NULL) return false; if (strncasecmp(uuid, entry->uuid, sizeof(uuid))) return false; memset(entry->ip, 0x00, sizeof(entry->ip)); if (get_tag_value(buf, KINETIC_IPV4_TAG, entry->ip, sizeof(entry->ip)) != NULL) return true; if (get_tag_value(buf, KINETIC_IPV6_TAG, entry->ip, sizeof(entry->ip)) != NULL) return true; return false; }
int handle_request(char *recv_ip, char *in, int in_len, char *out, int *out_len, int http) { char *action, *msgid, *body; int action_len, msgid_len; action = get_tag_value(in, wsd_discovery, sizeof(wsd_discovery)-1, &action_len); if (!action) action = get_tag_value(in, wsd_transfer, sizeof(wsd_transfer)-1, &action_len); if (!action) { if (http) return action_get(0, out, out_len, http); return -1; } msgid = get_tag_value(in, wsd_msgid, sizeof(wsd_msgid)-1, &msgid_len); if (!msgid) return -1; body = strstr(in, wsd_body); if (!msgid) return -1; action[action_len] = 0; msgid[msgid_len] = 0; wsdd_log(LOG_INFO, "Action %s", action); if (strcmp(action, wsd_act_probe) == 0) return action_probe(recv_ip, msgid, body, out, out_len, http); if (strcmp(action, wsd_act_resolve) == 0) return action_resolve(recv_ip, msgid, body, out, out_len, http); if (strcmp(action, wsd_act_get) == 0) return action_get(msgid, out, out_len, http); return -1; }
//simulate each memory operation void parse_buffer(cache *sim_cache, char *buffer, int s, int E, int b, int *hit, int *miss, int *evict){ int address; char opt; sscanf(buffer, " %s %x", &opt, &address); int seti = get_set_value(address, s, b); int tagi = get_tag_value(address, s, b); //simulate cache hit for(int i = 0; i < E; ++ i){ if((sim_cache->sets[seti].lines[i].valid == 1) && (sim_cache->sets[seti].lines[i].tag == tagi)){ ++ (*hit); if(opt == 'M') ++ (*hit); refresh_last_access(sim_cache->sets[seti].lines, E, i); return ; } } //simulate cache miss while there is no need to evict ++ (*miss); for(int i = 0; i < E; ++ i){ if(sim_cache->sets[seti].lines[i].valid == 0){ sim_cache->sets[seti].lines[i].valid = 1; sim_cache->sets[seti].lines[i].tag = tagi; if(opt == 'M') ++ (*hit); refresh_last_access(sim_cache->sets[seti].lines, E, i); return ; } } //simulate cache miss and there is need to evict ++ (*evict); for(int i = 0; i < E; ++ i){ if(sim_cache->sets[seti].lines[i].last_access == 1){ sim_cache->sets[seti].lines[i].tag = tagi; if(opt == 'M') ++ (*hit); refresh_last_access(sim_cache->sets[seti].lines, E, i); return; } } }
int action_resolve(char *recv_ip, char *src_msgid, char *body, char* out, int *out_len, int http) { static const char wsd_resolve_match[] = "<soap:Body>" "<wsd:ResolveMatches>" "<wsd:ResolveMatch>" "<wsa:EndpointReference>" "<wsa:Address>%s</wsa:Address>" "</wsa:EndpointReference>" "<wsd:Types>%s</wsd:Types>" "<wsd:XAddrs>http://%s:%d/wsd/</wsd:XAddrs>" "<wsd:MetadataVersion>2</wsd:MetadataVersion>" "</wsd:ResolveMatch>" "</wsd:ResolveMatches>" "</soap:Body>" "</soap:Envelope>"; char *endp; int endp_len, ret_len; endp = get_tag_value(body, wsd_addr, sizeof(wsd_addr)-1, &endp_len); if (!endp) { wsdd_log(LOG_INFO, "Endpoint not found"); return -1; } endp[endp_len] = 0; if (strcasecmp(endp, endpoint)) return -1; ret_len = *out_len; if (gen_soap_header(out, &ret_len, wsd_to_anon, wsd_discovery, wsd_act_resolve_matches, src_msgid, http) < 0) return -1; ret_len += snprintf(out+ret_len, (*out_len)-ret_len, wsd_resolve_match, endpoint, wsd_device, recv_ip, WSD_HTTP_PORT); *out_len = ret_len; return 0; }
int action_probe(char *recv_ip, char *src_msgid, char *body, char* out, int *out_len, int http) { static const char wsd_probe_match[] = "<soap:Body>" "<wsd:ProbeMatches>" "<wsd:ProbeMatch>" "<wsa:EndpointReference>" "<wsa:Address>%s</wsa:Address>" "</wsa:EndpointReference>" "<wsd:Types>%s</wsd:Types>" "<wsd:XAddrs>http://%s:%d/wsd/</wsd:XAddrs>" "<wsd:MetadataVersion>2</wsd:MetadataVersion>" "</wsd:ProbeMatch>" "</wsd:ProbeMatches>" "</soap:Body>" "</soap:Envelope>"; char *types; int types_len, ret_len; types = get_tag_value(body, wsd_types, sizeof(wsd_types)-1, &types_len); if (!types) return -1; types[types_len] = 0; if (strncmp(types, wsd_device, types_len)) return -1; ret_len = *out_len; if (gen_soap_header(out, &ret_len, wsd_to_anon, wsd_discovery, wsd_act_probe_matches, src_msgid, http) < 0) return -1; ret_len += snprintf(out+ret_len, (*out_len)-ret_len, wsd_probe_match, endpoint, wsd_device, recv_ip, WSD_HTTP_PORT); *out_len = ret_len; return 0; }
/* * Use /proc/bus/usb/devices or /dev/bus/usb/devices file to determine * host's USB devices. This is legacy support since many distributions * are moving to /sys/bus/usb */ static int usb_host_scan_dev(void *opaque, USBScanFunc *func) { FILE *f = 0; char line[1024]; char buf[1024]; int bus_num, addr, speed, device_count, class_id, product_id, vendor_id; char product_name[512]; int ret = 0; if (!usb_host_device_path) { perror("husb: USB Host Device Path not set"); goto the_end; } snprintf(line, sizeof(line), "%s/devices", usb_host_device_path); f = fopen(line, "r"); if (!f) { perror("husb: cannot open devices file"); goto the_end; } device_count = 0; bus_num = addr = speed = class_id = product_id = vendor_id = 0; for(;;) { if (fgets(line, sizeof(line), f) == NULL) break; if (strlen(line) > 0) line[strlen(line) - 1] = '\0'; if (line[0] == 'T' && line[1] == ':') { if (device_count && (vendor_id || product_id)) { /* New device. Add the previously discovered device. */ ret = func(opaque, bus_num, addr, class_id, vendor_id, product_id, product_name, speed); if (ret) goto the_end; } if (get_tag_value(buf, sizeof(buf), line, "Bus=", " ") < 0) goto fail; bus_num = atoi(buf); if (get_tag_value(buf, sizeof(buf), line, "Dev#=", " ") < 0) goto fail; addr = atoi(buf); if (get_tag_value(buf, sizeof(buf), line, "Spd=", " ") < 0) goto fail; if (!strcmp(buf, "480")) speed = USB_SPEED_HIGH; else if (!strcmp(buf, "1.5")) speed = USB_SPEED_LOW; else speed = USB_SPEED_FULL; product_name[0] = '\0'; class_id = 0xff; device_count++; product_id = 0; vendor_id = 0; } else if (line[0] == 'P' && line[1] == ':') { if (get_tag_value(buf, sizeof(buf), line, "Vendor=", " ") < 0) goto fail; vendor_id = strtoul(buf, NULL, 16); if (get_tag_value(buf, sizeof(buf), line, "ProdID=", " ") < 0) goto fail; product_id = strtoul(buf, NULL, 16); } else if (line[0] == 'S' && line[1] == ':') { if (get_tag_value(buf, sizeof(buf), line, "Product=", "") < 0) goto fail; pstrcpy(product_name, sizeof(product_name), buf); } else if (line[0] == 'D' && line[1] == ':') { if (get_tag_value(buf, sizeof(buf), line, "Cls=", " (") < 0) goto fail; class_id = strtoul(buf, NULL, 16); } fail: ; } if (device_count && (vendor_id || product_id)) { /* Add the last device. */ ret = func(opaque, bus_num, addr, class_id, vendor_id, product_id, product_name, speed); } the_end: if (f) fclose(f); return ret; }