int blk_get_device_part_str(const char *ifname, const char *dev_part_str, struct blk_desc **dev_desc, disk_partition_t *info, int allow_whole_dev) { int ret = -1; const char *part_str; char *dup_str = NULL; const char *dev_str; int dev; char *ep; int p; int part; disk_partition_t tmpinfo; #ifdef CONFIG_SANDBOX /* * Special-case a pseudo block device "hostfs", to allow access to the * host's own filesystem. */ if (0 == strcmp(ifname, "hostfs")) { *dev_desc = NULL; info->start = 0; info->size = 0; info->blksz = 0; info->bootable = 0; strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "Sandbox host"); #ifdef CONFIG_PARTITION_UUIDS info->uuid[0] = 0; #endif #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif return 0; } #endif #ifdef CONFIG_CMD_UBIFS /* * Special-case ubi, ubi goes through a mtd, rathen then through * a regular block device. */ if (0 == strcmp(ifname, "ubi")) { if (!ubifs_is_mounted()) { printf("UBIFS not mounted, use ubifsmount to mount volume first!\n"); return -1; } *dev_desc = NULL; memset(info, 0, sizeof(*info)); strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "UBI"); #ifdef CONFIG_PARTITION_UUIDS info->uuid[0] = 0; #endif return 0; } #endif /* If no dev_part_str, use bootdevice environment variable */ if (!dev_part_str || !strlen(dev_part_str) || !strcmp(dev_part_str, "-")) dev_part_str = getenv("bootdevice"); /* If still no dev_part_str, it's an error */ if (!dev_part_str) { printf("** No device specified **\n"); goto cleanup; } /* Separate device and partition ID specification */ part_str = strchr(dev_part_str, ':'); if (part_str) { dup_str = strdup(dev_part_str); dup_str[part_str - dev_part_str] = 0; dev_str = dup_str; part_str++; } else { dev_str = dev_part_str; } /* Look up the device */ dev = blk_get_device_by_str(ifname, dev_str, dev_desc); if (dev < 0) goto cleanup; /* Convert partition ID string to number */ if (!part_str || !*part_str) { part = PART_UNSPECIFIED; } else if (!strcmp(part_str, "auto")) { part = PART_AUTO; } else { /* Something specified -> use exactly that */ part = (int)simple_strtoul(part_str, &ep, 16); /* * Less than whole string converted, * or request for whole device, but caller requires partition. */ if (*ep || (part == 0 && !allow_whole_dev)) { printf("** Bad partition specification %s %s **\n", ifname, dev_part_str); goto cleanup; } } /* * No partition table on device, * or user requested partition 0 (entire device). */ if (((*dev_desc)->part_type == PART_TYPE_UNKNOWN) || (part == 0)) { if (!(*dev_desc)->lba) { printf("** Bad device size - %s %s **\n", ifname, dev_str); goto cleanup; } /* * If user specified a partition ID other than 0, * or the calling command only accepts partitions, * it's an error. */ if ((part > 0) || (!allow_whole_dev)) { printf("** No partition table - %s %s **\n", ifname, dev_str); goto cleanup; } (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); info->start = 0; info->size = (*dev_desc)->lba; info->blksz = (*dev_desc)->blksz; info->bootable = 0; strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "Whole Disk"); #ifdef CONFIG_PARTITION_UUIDS info->uuid[0] = 0; #endif #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif ret = 0; goto cleanup; } /* * Now there's known to be a partition table, * not specifying a partition means to pick partition 1. */ if (part == PART_UNSPECIFIED) part = 1; /* * If user didn't specify a partition number, or did specify something * other than "auto", use that partition number directly. */ if (part != PART_AUTO) { ret = part_get_info(*dev_desc, part, info); if (ret) { printf("** Invalid partition %d **\n", part); goto cleanup; } } else { /* * Find the first bootable partition. * If none are bootable, fall back to the first valid partition. */ part = 0; for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) { ret = part_get_info(*dev_desc, p, info); if (ret) continue; /* * First valid partition, or new better partition? * If so, save partition ID. */ if (!part || info->bootable) part = p; /* Best possible partition? Stop searching. */ if (info->bootable) break; /* * We now need to search further for best possible. * If we what we just queried was the best so far, * save the info since we over-write it next loop. */ if (part == p) tmpinfo = *info; } /* If we found any acceptable partition */ if (part) { /* * If we searched all possible partition IDs, * return the first valid partition we found. */ if (p == MAX_SEARCH_PARTITIONS + 1) *info = tmpinfo; } else { printf("** No valid partitions found **\n"); ret = -1; goto cleanup; } } if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 0) { printf("** Invalid partition type \"%.32s\"" " (expect \"" BOOT_PART_TYPE "\")\n", info->type); ret = -1; goto cleanup; } (*dev_desc)->log2blksz = LOG2((*dev_desc)->blksz); ret = part; goto cleanup; cleanup: free(dup_str); return ret; }
int newtGetKey(void) { int key; char buf[10], * chptr = buf; const struct keymap * curr; do { key = SLang_getkey(); if (key == 0xFFFF) { if (needResize) return NEWT_KEY_RESIZE; /* ignore other signals */ continue; } if (key == NEWT_KEY_SUSPEND && suspendCallback) suspendCallback(suspendCallbackData); } while (key == NEWT_KEY_SUSPEND); switch (key) { case 'v' | 0x80: case 'V' | 0x80: return NEWT_KEY_PGUP; case 22: return NEWT_KEY_PGDN; return NEWT_KEY_BKSPC; case 0x7f: return NEWT_KEY_BKSPC; case 0x08: return NEWT_KEY_BKSPC; default: if (key != keyPrefix) return key; } memset(buf, 0, sizeof(buf)); *chptr++ = key; while (SLang_input_pending(5)) { key = SLang_getkey(); if (key == keyPrefix) { /* he hit unknown keys too many times -- start over */ memset(buf, 0, sizeof(buf)); chptr = buf; } *chptr++ = key; /* this search should use bsearch(), but when we only look through a list of 20 (or so) keymappings, it's probably faster just to do a inline linear search */ for (curr = keymap; curr->code; curr++) { if (curr->str) { if (!strcmp(curr->str, buf)) return curr->code; } } } for (curr = keymap; curr->code; curr++) { if (curr->str) { if (!strcmp(curr->str, buf)) return curr->code; } } /* Looks like we were a bit overzealous in reading characters. Return just the first character, and put everything else back in the buffer for later */ chptr--; while (chptr > buf) SLang_ungetkey(*chptr--); return *chptr; }
int main (int argc, char **argv) { int s; int c; int r; int localport = 8888; size_t sinsize; struct sockaddr_in sin; fd_set fds; char *host = NAP_SERVER; int port = NAP_PORT; while ((r = getopt (argc, argv, "hs:p:l:")) != EOF) { switch (r) { case 'l': localport = atoi (optarg); break; case 's': host = optarg; break; case 'p': port = atoi (optarg); break; default: usage (); } } /* accept connection from client */ s = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s < 0) { perror ("socket"); exit (1); } c = 1; if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &c, sizeof (c)) != 0) { perror ("setsockopt"); exit (1); } memset (&sin, 0, sizeof (sin)); sin.sin_port = htons (localport); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; if (bind (s, &sin, sizeof (sin)) < 0) { perror ("bind"); exit (1); } if (listen (s, 1) < 0) { perror ("listen"); exit (1); } puts ("waiting for client"); if (select (s + 1, &fds, 0, 0, 0) < 0) { perror ("select"); exit (1); } sinsize = sizeof (sin); c = accept (s, &sin, &sinsize); if (c < 0) { perror ("accept"); exit (1); } puts ("got client"); /* make connection to server */ printf ("connecting to server..."); fflush (stdout); r = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); if (r < 0) { perror ("socket"); exit (1); } memset (&sin, 0, sizeof (sin)); sin.sin_port = htons (port); sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr (host); if (connect (r, &sin, sizeof (sin)) < 0) { perror ("connect"); exit (1); } puts ("connected to server"); for (;;) { FD_ZERO (&fds); FD_SET (r, &fds); FD_SET (c, &fds); if (select (((r > c) ? r : c) + 1, &fds, 0, 0, 0) < 0) { perror ("select"); break; } if (FD_ISSET (r, &fds)) { if (pass_message ("server", r, c) != 0) break; } if (FD_ISSET (c, &fds)) { if (pass_message ("client", c, r) != 0) break; } } close (r); close (s); close (c); exit (0); }
MY_DIR *my_dir(const char *path, myf MyFlags) { char *buffer; MY_DIR *result= 0; FILEINFO finfo; DYNAMIC_ARRAY *dir_entries_storage; MEM_ROOT *names_storage; struct _finddata_t find; ushort mode; char tmp_path[FN_REFLEN],*tmp_file,attrib; #ifdef _WIN64 __int64 handle; #else long handle; #endif DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); /* Put LIB-CHAR as last path-character if not there */ tmp_file=tmp_path; if (!*path) *tmp_file++ ='.'; /* From current dir */ tmp_file= my_stpnmov(tmp_file, path, FN_REFLEN-5); if (tmp_file[-1] == FN_DEVCHAR) *tmp_file++= '.'; /* From current dev-dir */ if (tmp_file[-1] != FN_LIBCHAR) *tmp_file++ =FN_LIBCHAR; tmp_file[0]='*'; /* Windows needs this !??? */ tmp_file[1]='.'; tmp_file[2]='*'; tmp_file[3]='\0'; if (!(buffer= my_malloc(key_memory_MY_DIR, ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + sizeof(MEM_ROOT), MyFlags))) goto error; dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); if (my_init_dynamic_array(dir_entries_storage, key_memory_MY_DIR, sizeof(FILEINFO), NULL, /* init_buffer */ ENTRIES_START_SIZE, ENTRIES_INCREMENT)) { my_free(buffer); goto error; } init_alloc_root(key_memory_MY_DIR, names_storage, NAMES_START_SIZE, NAMES_START_SIZE); /* MY_DIR structure is allocated and completly initialized at this point */ result= (MY_DIR*)buffer; if ((handle=_findfirst(tmp_path,&find)) == -1L) { DBUG_PRINT("info", ("findfirst returned error, errno: %d", errno)); if (errno != EINVAL) goto error; /* Could not read the directory, no read access. Probably because by "chmod -r". continue and return zero files in dir */ } else { do { attrib= find.attrib; /* Do not show hidden and system files which Windows sometimes create. Note. Because Borland's findfirst() is called with the third argument = 0 hidden/system files are excluded from the search. */ if (attrib & (_A_HIDDEN | _A_SYSTEM)) continue; if (!(finfo.name= strdup_root(names_storage, find.name))) goto error; if (MyFlags & MY_WANT_STAT) { if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, sizeof(MY_STAT)))) goto error; memset(finfo.mystat, 0, sizeof(MY_STAT)); finfo.mystat->st_size=find.size; mode= MY_S_IREAD; if (!(attrib & _A_RDONLY)) mode|= MY_S_IWRITE; if (attrib & _A_SUBDIR) mode|= MY_S_IFDIR; finfo.mystat->st_mode= mode; finfo.mystat->st_mtime= ((uint32) find.time_write); } else finfo.mystat= NULL; if (insert_dynamic(dir_entries_storage, (uchar*)&finfo)) goto error; } while (_findnext(handle,&find) == 0); _findclose(handle); } result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; result->number_off_files= dir_entries_storage->elements; if (!(MyFlags & MY_DONT_SORT)) my_qsort((void *) result->dir_entry, result->number_off_files, sizeof(FILEINFO), (qsort_cmp) comp_names); DBUG_PRINT("exit", ("found %d files", result->number_off_files)); DBUG_RETURN(result); error: set_my_errno(errno); if (handle != -1) _findclose(handle); my_dirend(result); if (MyFlags & MY_FAE+MY_WME) { char errbuf[MYSYS_STRERROR_SIZE]; my_error(EE_DIR, MYF(0), path, errno, my_strerror(errbuf, sizeof(errbuf), errno)); } DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */
MY_DIR *my_dir(const char *path, myf MyFlags) { char *buffer; MY_DIR *result= 0; FILEINFO finfo; DYNAMIC_ARRAY *dir_entries_storage; MEM_ROOT *names_storage; DIR *dirp; char tmp_path[FN_REFLEN + 2], *tmp_file; const struct dirent *dp; DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags)); dirp = opendir(directory_file_name(tmp_path,(char *) path)); if (dirp == NULL || ! (buffer= my_malloc(key_memory_MY_DIR, ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + sizeof(MEM_ROOT), MyFlags))) goto error; dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); if (my_init_dynamic_array(dir_entries_storage, key_memory_MY_DIR, sizeof(FILEINFO), NULL, /* init_buffer */ ENTRIES_START_SIZE, ENTRIES_INCREMENT)) { my_free(buffer); goto error; } init_alloc_root(key_memory_MY_DIR, names_storage, NAMES_START_SIZE, NAMES_START_SIZE); /* MY_DIR structure is allocated and completly initialized at this point */ result= (MY_DIR*)buffer; tmp_file=strend(tmp_path); for (dp= readdir(dirp) ; dp; dp= readdir(dirp)) { if (!(finfo.name= strdup_root(names_storage, dp->d_name))) goto error; if (MyFlags & MY_WANT_STAT) { if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, sizeof(MY_STAT)))) goto error; memset(finfo.mystat, 0, sizeof(MY_STAT)); (void) my_stpcpy(tmp_file,dp->d_name); (void) my_stat(tmp_path, finfo.mystat, MyFlags); if (!(finfo.mystat->st_mode & MY_S_IREAD)) continue; } else finfo.mystat= NULL; if (insert_dynamic(dir_entries_storage, (uchar*)&finfo)) goto error; } (void) closedir(dirp); result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; result->number_off_files= dir_entries_storage->elements; if (!(MyFlags & MY_DONT_SORT)) my_qsort((void *) result->dir_entry, result->number_off_files, sizeof(FILEINFO), (qsort_cmp) comp_names); DBUG_RETURN(result); error: set_my_errno(errno); if (dirp) (void) closedir(dirp); my_dirend(result); if (MyFlags & (MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; my_error(EE_DIR, MYF(0), path, my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno())); } DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */
void Test_M2MResourceInstance::test_handle_get_request() { uint8_t value[] = {"name"}; sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); memset(coap_header, 0, sizeof(sn_coap_hdr_s)); coap_header->uri_path_ptr = value; coap_header->uri_path_len = sizeof(value); coap_header->msg_code = COAP_MSG_CODE_REQUEST_GET; String *name = new String("name"); common_stub::int_value = 0; m2mbase_stub::string_value = name; m2mbase_stub::operation = M2MBase::GET_ALLOWED; m2mbase_stub::uint8_value = 200; common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); coap_header->token_ptr = (uint8_t*)malloc(sizeof(value)); memcpy(coap_header->token_ptr, value, sizeof(value)); coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); coap_header->options_list_ptr->observe = 0; coap_header->content_type_ptr = (uint8_t*)malloc(1); coap_header->content_type_len = 1; *coap_header->content_type_ptr = 110; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(coap_header->content_type_ptr) { free(coap_header->content_type_ptr); coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } // Not OMA TLV or JSON m2mbase_stub::uint8_value = 110; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } // OMA TLV m2mbase_stub::uint8_value = 99; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } // OMA JSON m2mbase_stub::uint8_value = 100; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } coap_header->options_list_ptr->observe = 1; uint8_t obs = 0; coap_header->options_list_ptr->observe_ptr = (uint8_t*)malloc(sizeof(obs)); memcpy(coap_header->options_list_ptr->observe_ptr,&obs,sizeof(obs)); coap_header->options_list_ptr->observe_len = 0; m2mbase_stub::uint16_value = 0x1c1c; m2mbase_stub::bool_value = true; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->observe_ptr) { free(common_stub::coap_header->options_list_ptr->observe_ptr); common_stub::coap_header->options_list_ptr->observe_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } // Not observable m2mbase_stub::bool_value = false; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->observe_ptr) { free(common_stub::coap_header->options_list_ptr->observe_ptr); common_stub::coap_header->options_list_ptr->observe_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } m2mbase_stub::bool_value = true; coap_header->options_list_ptr->observe_len = 1; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->observe_ptr) { free(common_stub::coap_header->options_list_ptr->observe_ptr); common_stub::coap_header->options_list_ptr->observe_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } obs = 1; memcpy(coap_header->options_list_ptr->observe_ptr,&obs,sizeof(obs)); CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->observe_ptr) { free(common_stub::coap_header->options_list_ptr->observe_ptr); common_stub::coap_header->options_list_ptr->observe_ptr = NULL; } if(common_stub::coap_header->options_list_ptr->max_age_ptr) { free(common_stub::coap_header->options_list_ptr->max_age_ptr); common_stub::coap_header->options_list_ptr->max_age_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } m2mbase_stub::operation = M2MBase::NOT_ALLOWED; CHECK(resource_instance->handle_get_request(NULL,coap_header,handler) != NULL); CHECK(resource_instance->handle_get_request(NULL,NULL,handler) != NULL); if(coap_header->token_ptr) { free(coap_header->token_ptr); coap_header->token_ptr = NULL; } if(coap_header->content_type_ptr) { free(coap_header->content_type_ptr); coap_header->content_type_ptr = NULL; } if(coap_header->options_list_ptr->observe_ptr) { free(coap_header->options_list_ptr->observe_ptr); coap_header->options_list_ptr->observe_ptr = NULL; } if(coap_header->options_list_ptr) { free(coap_header->options_list_ptr); coap_header->options_list_ptr = NULL; } if(common_stub::coap_header){ if(common_stub::coap_header->content_type_ptr) { free(common_stub::coap_header->content_type_ptr); common_stub::coap_header->content_type_ptr = NULL; } if(common_stub::coap_header->options_list_ptr) { free(common_stub::coap_header->options_list_ptr); common_stub::coap_header->options_list_ptr = NULL; } free(common_stub::coap_header); common_stub::coap_header = NULL; } free(coap_header); coap_header = NULL; delete name; name = NULL; m2mbase_stub::clear(); common_stub::clear(); }
/* * We will eventually be called from inetd or via the rc scripts directly * Parse arguments and act appropiately. */ int main(int argc, char **argv) { extern char *optarg; FILE *fp; int c, *s, ns; struct pollfd *pfds; #if PROFILE moncontrol(0); #endif if ((progname = strrchr(*argv, '/')) != NULL) { progname++; } else progname = *argv; /* initialise global session data */ memset(&session, 0, sizeof(session)); session.peer = tac_strdup("unknown"); if (argc <= 1) { usage(); tac_exit(1); } while ((c = getopt(argc, argv, "B:C:d:hiPp:tGgvSsLw:u:")) != EOF) switch (c) { case 'B': /* bind() address*/ bind_address = optarg; break; case 'L': /* lookup peer names via DNS */ lookup_peer = 1; break; case 's': /* don't respond to sendpass */ sendauth_only = 1; break; case 'v': /* print version and exit */ vers(); tac_exit(1); case 't': console = 1; /* log to console too */ break; case 'P': /* Parse config file only */ parse_only = 1; break; case 'G': /* foreground */ opt_G = 1; break; case 'g': /* single threaded */ single = 1; break; case 'p': /* port */ port = atoi(optarg); portstr = optarg; break; case 'd': /* debug */ debug |= atoi(optarg); break; case 'C': /* config file name */ session.cfgfile = tac_strdup(optarg); break; case 'h': /* usage */ usage(); tac_exit(0); case 'i': /* inetd mode */ standalone = 0; break; case 'S': /* enable single-connection */ opt_S = 1; break; #ifdef MAXSESS case 'w': /* wholog file */ wholog = tac_strdup(optarg); break; #endif case 'u': wtmpfile = tac_strdup(optarg); break; default: fprintf(stderr, "%s: bad switch %c\n", progname, c); usage(); tac_exit(1); } parser_init(); /* read the configuration/etc */ init(); #if defined(REAPCHILD) && defined(REAPSIGIGN) client_count_init(); #endif open_logfile(); signal(SIGUSR1, handler); signal(SIGHUP, handler); signal(SIGUSR2, dump_clients_handler); signal(SIGTERM, die); signal(SIGPIPE, SIG_IGN); if (parse_only) tac_exit(0); if (debug) report(LOG_DEBUG, "tac_plus server %s starting", version); if (!standalone) { /* running under inetd */ char host[NI_MAXHOST]; int on; #ifdef IPV6 struct sockaddr_in6 name; #else struct sockaddr_in name; #endif socklen_t name_len; name_len = sizeof(name); session.flags |= SESS_NO_SINGLECONN; session.sock = 0; #ifdef IPV6 if (getpeername(session.sock, (struct sockaddr6 *)&name, &name_len)) { report(LOG_ERR, "getpeername failure %s", strerror(errno)); #else if (getpeername(session.sock, (struct sockaddr *)&name, &name_len)) { report(LOG_ERR, "getpeername failure %s", strerror(errno)); #endif } else { if (lookup_peer) on = 0; else on = NI_NUMERICHOST; #ifdef IPV6 if (getnameinfo((struct sockaddr6 *)&name, name_len, host, 128, NULL, 0, on)) { #else if (getnameinfo((struct sockaddr *)&name, name_len, host, 128, NULL, 0, on)) { #endif strncpy(host, "unknown", NI_MAXHOST - 1); host[NI_MAXHOST - 1] = '\0'; } if (session.peer) free(session.peer); session.peer = tac_strdup(host); if (session.peerip) free(session.peerip); #ifdef IPV6 session.peerip = tac_strdup((char *)inet_ntop(name.sin6_family, &name.sin6_addr, host, name_len)); #else session.peerip = tac_strdup((char *)inet_ntop(name.sin_family, &name.sin_addr, host, name_len)); #endif if (debug & DEBUG_AUTHEN_FLAG) report(LOG_INFO, "session.peerip is %s", session.peerip); } #ifdef FIONBIO on = 1; if (ioctl(session.sock, FIONBIO, &on) < 0) { report(LOG_ERR, "ioctl(FIONBIO) %s", strerror(errno)); tac_exit(1); } #endif start_session(); tac_exit(0); } if (single) { session.flags |= SESS_NO_SINGLECONN; } else { /* * Running standalone; background ourselves and release controlling * tty, unless -G option was specified to keep the parent in the * foreground. */ #ifdef SIGTTOU signal(SIGTTOU, SIG_IGN); #endif #ifdef SIGTTIN signal(SIGTTIN, SIG_IGN); #endif #ifdef SIGTSTP signal(SIGTSTP, SIG_IGN); #endif if (!opt_S) session.flags |= SESS_NO_SINGLECONN; if (!opt_G) { if ((childpid = fork()) < 0) report(LOG_ERR, "Can't fork first child"); else if (childpid > 0) exit(0); /* parent */ if (debug) report(LOG_DEBUG, "Backgrounded"); #if SETPGRP_VOID if (setpgrp() == -1) #else if (setpgrp(0, getpid()) == -1) #endif /* SETPGRP_VOID */ report(LOG_ERR, "Can't change process group: %s", strerror(errno)); /* XXX What does "REAPCHILD" have to do with TIOCNOTTY? */ #ifndef REAPCHILD c = open("/dev/tty", O_RDWR); if (c >= 0) { ioctl(c, TIOCNOTTY, (char *)0); (void) close(c); } #else /* REAPCHILD */ if ((childpid = fork()) < 0) report(LOG_ERR, "Can't fork second child"); else if (childpid > 0) exit(0); if (debug & DEBUG_FORK_FLAG) report(LOG_DEBUG, "Forked grandchild"); #endif /* REAPCHILD */ /* some systems require this */ closelog(); for (c = getdtablesize(); c >= 0; c--) (void)close(c); /* * make sure we can still log to syslog now that we have closed * everything */ open_logfile(); } } #if REAPCHILD #if REAPSIGIGN signal(SIGCHLD, reapchild); #else signal(SIGCHLD, SIG_IGN); #endif #endif ostream = NULL; /* chdir("/"); */ umask(022); errno = 0; get_socket(&s, &ns); #ifndef SOMAXCONN #define SOMAXCONN 5 #endif for (c = 0; c < ns; c++) { if (listen(s[c], SOMAXCONN) < 0) { console = 1; report(LOG_ERR, "listen: %s", strerror(errno)); tac_exit(1); } } if (port == TAC_PLUS_PORT) { if (bind_address == NULL) { strncpy(pidfilebuf, TACPLUS_PIDFILE, PIDSZ); if (pidfilebuf[PIDSZ - 1] != '\0') c = PIDSZ; else c = PIDSZ - 1; } else c = snprintf(pidfilebuf, PIDSZ, "%s.%s", TACPLUS_PIDFILE, bind_address); } else { if (bind_address == NULL) c = snprintf(pidfilebuf, PIDSZ, "%s.%d", TACPLUS_PIDFILE, port); else c = snprintf(pidfilebuf, PIDSZ, "%s.%s.%d", TACPLUS_PIDFILE, bind_address, port); } if (c >= PIDSZ) { pidfilebuf[PIDSZ - 1] = '\0'; report(LOG_ERR, "pid filename truncated: %s", pidfilebuf); childpid = 0; } else { /* write process id to pidfile */ if ((fp = fopen(pidfilebuf, "w")) != NULL) { fprintf(fp, "%d\n", (int)getpid()); fclose(fp); /* * After forking to disassociate; make sure we know we're the * mother so that we remove our pid file upon exit in die(). */ childpid = 1; } else { report(LOG_ERR, "Cannot write pid to %s %s", pidfilebuf, strerror(errno)); childpid = 0; } } #ifdef TACPLUS_GROUPID if (setgid(TACPLUS_GROUPID)) report(LOG_ERR, "Cannot set group id to %d %s", TACPLUS_GROUPID, strerror(errno)); #endif #ifdef TACPLUS_USERID if (setuid(TACPLUS_USERID)) report(LOG_ERR, "Cannot set user id to %d %s", TACPLUS_USERID, strerror(errno)); #endif #ifdef MAXSESS maxsess_loginit(); #endif /* MAXSESS */ report(LOG_DEBUG, "uid=%d euid=%d gid=%d egid=%d s=%d", getuid(), geteuid(), getgid(), getegid(), s); pfds = malloc(sizeof(struct pollfd) * ns); if (pfds == NULL) { report(LOG_ERR, "malloc failure: %s", strerror(errno)); tac_exit(1); } for (c = 0; c < ns; c++) { pfds[c].fd = s[c]; pfds[c].events = POLLIN | POLLERR | POLLHUP | POLLNVAL; } for (;;) { #if HAVE_PID_T pid_t pid; #else int pid; #endif char host[NI_MAXHOST]; #ifdef IPV6 struct sockaddr_in6 from; #else struct sockaddr_in from; #endif socklen_t from_len; int newsockfd, status; int flags; int procs_for_client; #if defined(REAPCHILD) && defined(REAPSIGIGN) if (reap_children) reapchildren(); #endif if (reinitialize) init(); if (dump_client_table) { report(LOG_ALERT, "Dumping Client Tables"); dump_client_tables(); dump_client_table = 0; } status = poll(pfds, ns, cfg_get_accepttimeout() * 1000); if (status == 0) continue; if (status == -1) if (errno == EINTR) continue; from_len = sizeof(from); memset((char *)&from, 0, from_len); for (c = 0; c < ns; c++) { if (pfds[c].revents & POLLIN) #ifdef IPV6 newsockfd = accept(s[c], (struct sockaddr6 *)&from, &from_len); #else newsockfd = accept(s[c], (struct sockaddr *)&from, &from_len); #endif else if (pfds[c].revents & (POLLERR | POLLHUP | POLLNVAL)) { report(LOG_ERR, "exception on listen FD %d", s[c]); tac_exit(1); } } if (newsockfd < 0) { if (errno == EINTR) continue; report(LOG_ERR, "accept: %s", strerror(errno)); continue; } if (lookup_peer) flags = 0; else flags = NI_NUMERICHOST; #ifdef IPV6 if (getnameinfo((struct sockaddr_in6 *)&from, from_len, host, 128, NULL, 0, flags)) { #else if (getnameinfo((struct sockaddr_in *)&from, from_len, host, 128, NULL, 0, flags)) { #endif strncpy(host, "unknown", NI_MAXHOST - 1); host[NI_MAXHOST - 1] = '\0'; } if (session.peer) free(session.peer); session.peer = tac_strdup(host); if (session.peerip) free(session.peerip); #ifdef IPV6 session.peerip = tac_strdup((char *)inet_ntop(from.sin6_family, &from.sin6_addr, host, INET6_ADDRSTRLEN)); #else session.peerip = tac_strdup((char *)inet_ntop(from.sin_family, &from.sin_addr, host, INET_ADDRSTRLEN)); #endif if (debug & DEBUG_PACKET_FLAG) report(LOG_DEBUG, "session request from %s sock=%d", session.peer, newsockfd); if (!single) { #if defined(REAPCHILD) && defined(REAPSIGIGN) /* first we check the tocal process count to see if we are at the limit */ if (total_child_count >= cfg_get_maxprocs()) { report(LOG_ALERT, "refused connection from %s [%s] at global max procs [%d]", session.peer, session.peerip, total_child_count); shutdown(newsockfd, 2); close(newsockfd); continue; } /* no we check the process count per client */ procs_for_client = get_client_count(session.peerip); report(LOG_ALERT, "connection [%d] from %s [%s]", procs_for_client + 1, session.peer, session.peerip); if (procs_for_client >= cfg_get_maxprocsperclt()) { report(LOG_ALERT, "refused connection from %s [%s] at client max procs [%d]", session.peer, session.peerip, procs_for_client); shutdown(newsockfd, 2); close(newsockfd); continue; } #endif pid = fork(); if (pid < 0) { report(LOG_ERR, "fork error"); tac_exit(1); } } else { pid = 0; } if (pid == 0) { /* child */ if (!single) { if (ns > 1) { for (c = 0; c < ns; c++) { close(s[c]); } } } session.sock = newsockfd; #ifdef LIBWRAP if (! hosts_ctl(progname,session.peer,session.peerip,progname)) { report(LOG_ALERT, "refused connection from %s [%s]", session.peer, session.peerip); shutdown(session.sock, 2); close(session.sock); if (!single) { tac_exit(0); } else { close(session.sock); continue; } } if (debug) report(LOG_DEBUG, "connect from %s [%s]", session.peer, session.peerip); #endif #if PROFILE moncontrol(1); #endif start_session(); shutdown(session.sock, 2); close(session.sock); if (!single) tac_exit(0); } else { /* parent */ #if defined(REAPCHILD) && defined(REAPSIGIGN) total_child_count++; procs_for_client = increment_client_count_for_proc(pid, session.peerip); snprintf(msgbuf, MSGBUFSZ, "forked %lu for %s, procs %d, procs for client %d", (long)pid, session.peerip, total_child_count, procs_for_client); report(LOG_DEBUG, msgbuf); #endif close(newsockfd); } } }
void FNI_InflateObject(JNIEnv *env, jobject wrapped_obj) { struct oobj *obj = FNI_UNWRAP_MASKED(wrapped_obj); FLEX_MUTEX_LOCK(&global_inflate_mutex); /* be careful in case someone inflates this guy while our back is turned */ if (!FNI_IS_INFLATED(wrapped_obj)) { /* all data in inflated_oobj is managed manually, so we can use malloc */ struct inflated_oobj *infl = #if defined(WITH_TRANSACTIONS) && defined(BDW_CONSERVATIVE_GC) #ifdef WITH_GC_STATS GC_malloc_uncollectable_stats #else GC_malloc_uncollectable /* transactions stores version info here */ #endif #else malloc #endif (sizeof(*infl)); #if (!defined(WITH_TRANSACTIONS)) || (!defined(BDW_CONSERVATIVE_GC)) INCREMENT_MEM_STATS(sizeof(*infl)); #endif /* initialize infl */ memset(infl, 0, sizeof(*infl)); #ifndef WITH_HASHLOCK_SHRINK infl->hashcode = HASHCODE_MASK(obj->hashunion.hashcode); #endif /* !WITH_HASHLOCK_SHRINK */ #if WITH_HEAVY_THREADS || WITH_PTH_THREADS || WITH_USER_THREADS # ifdef ERROR_CHECKING_LOCKS /* error checking locks are slower, but catch more bugs (maybe) */ { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_ERRORCHECK_NP); pthread_mutex_init(&(infl->mutex), &attr); pthread_mutexattr_destroy(&attr); } # else /* !ERROR_CHECKING_LOCKS */ pthread_mutex_init(&(infl->mutex), NULL); # endif /* ERROR_CHECKING_LOCKS || !ERROR_CHECKING_LOCKS */ pthread_cond_init(&(infl->cond), NULL); pthread_rwlock_init(&(infl->jni_data_lock), NULL); #endif #ifndef WITH_HASHLOCK_SHRINK #ifndef WITH_DYNAMIC_WB obj->hashunion.inflated = infl; #else /* WITH_DYNAMIC_WB */ obj->hashunion.inflated = (struct inflated_oobj *) ((ptroff_t) infl | (obj->hashunion.hashcode & 2)); #endif /* WITH_DYNAMIC_WB */ #else /* WITH_HASHLOCK_SHRINK */ infl_table_set(INFL_LOCK, obj, infl, NULL); #endif /* WITH_HASHLOCK_SHRINK */ assert(FNI_IS_INFLATED(wrapped_obj)); #ifdef WITH_PRECISE_GC #if defined(WITH_REALTIME_JAVA) && defined(WITH_NOHEAP_SUPPORT) /* Can't inflate a heap reference in a NoHeapRealtimeThread */ assert((!(((ptroff_t)FNI_UNWRAP(wrapped_obj))&1))|| (!((struct FNI_Thread_State*)env)->noheap)); if (((ptroff_t)FNI_UNWRAP(wrapped_obj))&1) /* register only if in heap */ #endif precise_register_inflated_obj(obj, #ifdef WITH_REALTIME_JAVA (void (*)(jobject_unwrapped, ptroff_t)) #endif deflate_object); #elif defined(BDW_CONSERVATIVE_GC) /* register finalizer to deallocate inflated_oobj on gc */ if (GC_base(obj)!=NULL) {// skip if this is not a heap-allocated object GC_register_finalizer_no_order(GC_base(obj), deflate_object, (GC_PTR) ((void*)obj-(void*)GC_base(obj)), &(infl->old_finalizer), &(infl->old_client_data)); } #endif #ifdef WITH_REALTIME_JAVA # ifdef BDW_CONSERVATIVE_GC /* XXX this test may be reversed? see v1.29 XXX */ if (GC_base(obj)!=NULL) /* skip if this is not a heap-allocated object */ # endif /* BDW_CONSERVATIVE_GC */ RTJ_register_finalizer(wrapped_obj, deflate_object); #endif } FLEX_MUTEX_UNLOCK(&global_inflate_mutex); }
void CWE134_Uncontrolled_Format_String__char_listen_socket_w32_vsnprintf_64_bad() { char * data; char dataBuffer[100] = ""; data = dataBuffer; { #ifdef _WIN32 WSADATA wsaData; int wsaDataInit = 0; #endif int recvResult; struct sockaddr_in service; char *replace; SOCKET listenSocket = INVALID_SOCKET; SOCKET acceptSocket = INVALID_SOCKET; size_t dataLen = strlen(data); do { #ifdef _WIN32 if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { break; } wsaDataInit = 1; #endif /* POTENTIAL FLAW: Read data using a listen socket */ listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (listenSocket == INVALID_SOCKET) { break; } memset(&service, 0, sizeof(service)); service.sin_family = AF_INET; service.sin_addr.s_addr = INADDR_ANY; service.sin_port = htons(TCP_PORT); if (bind(listenSocket, (struct sockaddr*)&service, sizeof(service)) == SOCKET_ERROR) { break; } if (listen(listenSocket, LISTEN_BACKLOG) == SOCKET_ERROR) { break; } acceptSocket = accept(listenSocket, NULL, NULL); if (acceptSocket == SOCKET_ERROR) { break; } /* Abort on error or the connection was closed */ recvResult = recv(acceptSocket, (char *)(data + dataLen), sizeof(char) * (100 - dataLen - 1), 0); if (recvResult == SOCKET_ERROR || recvResult == 0) { break; } /* Append null terminator */ data[dataLen + recvResult / sizeof(char)] = '\0'; /* Eliminate CRLF */ replace = strchr(data, '\r'); if (replace) { *replace = '\0'; } replace = strchr(data, '\n'); if (replace) { *replace = '\0'; } } while (0); if (listenSocket != INVALID_SOCKET) { CLOSE_SOCKET(listenSocket); } if (acceptSocket != INVALID_SOCKET) { CLOSE_SOCKET(acceptSocket); } #ifdef _WIN32 if (wsaDataInit) { WSACleanup(); } #endif } CWE134_Uncontrolled_Format_String__char_listen_socket_w32_vsnprintf_64b_badSink(&data); }
int main(int argc, char *argv[]) { int i, j, rtest, srcs; void *buf; u8 g1[TEST_SOURCES], g2[TEST_SOURCES], g3[TEST_SOURCES]; u8 g4[TEST_SOURCES], g5[TEST_SOURCES], *g_tbls; u8 *dest1, *dest2, *dest3, *dest4, *dest5, *buffs[TEST_SOURCES]; u8 *dest_ref1, *dest_ref2, *dest_ref3, *dest_ref4, *dest_ref5; u8 *dest_ptrs[5]; int align, size; unsigned char *efence_buffs[TEST_SOURCES]; unsigned int offset; u8 *ubuffs[TEST_SOURCES]; u8 *udest_ptrs[5]; printf(xstr(FUNCTION_UNDER_TEST) ": %dx%d ", TEST_SOURCES, TEST_LEN); // Allocate the arrays for (i = 0; i < TEST_SOURCES; i++) { if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } buffs[i] = buf; } if (posix_memalign(&buf, 16, 2 * (6 * TEST_SOURCES * 32))) { printf("alloc error: Fail"); return -1; } g_tbls = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest1 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest2 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest3 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest4 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest5 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest_ref1 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest_ref2 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest_ref3 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest_ref4 = buf; if (posix_memalign(&buf, 64, TEST_LEN)) { printf("alloc error: Fail"); return -1; } dest_ref5 = buf; dest_ptrs[0] = dest1; dest_ptrs[1] = dest2; dest_ptrs[2] = dest3; dest_ptrs[3] = dest4; dest_ptrs[4] = dest5; // Test of all zeros for (i = 0; i < TEST_SOURCES; i++) memset(buffs[i], 0, TEST_LEN); memset(dest1, 0, TEST_LEN); memset(dest2, 0, TEST_LEN); memset(dest3, 0, TEST_LEN); memset(dest4, 0, TEST_LEN); memset(dest5, 0, TEST_LEN); memset(dest_ref1, 0, TEST_LEN); memset(dest_ref2, 0, TEST_LEN); memset(dest_ref3, 0, TEST_LEN); memset(dest_ref4, 0, TEST_LEN); memset(dest_ref5, 0, TEST_LEN); memset(g1, 2, TEST_SOURCES); memset(g2, 1, TEST_SOURCES); memset(g3, 7, TEST_SOURCES); memset(g4, 9, TEST_SOURCES); memset(g5, 4, TEST_SOURCES); for (i = 0; i < TEST_SOURCES; i++) { gf_vect_mul_init(g1[i], &g_tbls[i * 32]); gf_vect_mul_init(g2[i], &g_tbls[32 * TEST_SOURCES + i * 32]); gf_vect_mul_init(g3[i], &g_tbls[64 * TEST_SOURCES + i * 32]); gf_vect_mul_init(g4[i], &g_tbls[96 * TEST_SOURCES + i * 32]); gf_vect_mul_init(g5[i], &g_tbls[128 * TEST_SOURCES + i * 32]); } gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs, dest_ref2); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs, dest_ref3); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES], buffs, dest_ref4); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES], buffs, dest_ref5); FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs); if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) { printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test1\n"); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref1, 25); printf("dprod_dut:"); dump(dest1, 25); return -1; } if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) { printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test2\n"); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref2, 25); printf("dprod_dut:"); dump(dest2, 25); return -1; } if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) { printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test3\n"); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref3, 25); printf("dprod_dut:"); dump(dest3, 25); return -1; } if (0 != memcmp(dest_ref4, dest4, TEST_LEN)) { printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test4\n"); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref4, 25); printf("dprod_dut:"); dump(dest4, 25); return -1; } if (0 != memcmp(dest_ref5, dest5, TEST_LEN)) { printf("Fail zero " xstr(FUNCTION_UNDER_TEST) " test5\n"); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref5, 25); printf("dprod_dut:"); dump(dest5, 25); return -1; } putchar('.'); // Rand data test for (rtest = 0; rtest < RANDOMS; rtest++) { for (i = 0; i < TEST_SOURCES; i++) for (j = 0; j < TEST_LEN; j++) buffs[i][j] = rand(); for (i = 0; i < TEST_SOURCES; i++) { g1[i] = rand(); g2[i] = rand(); g3[i] = rand(); g4[i] = rand(); g5[i] = rand(); } for (i = 0; i < TEST_SOURCES; i++) { gf_vect_mul_init(g1[i], &g_tbls[i * 32]); gf_vect_mul_init(g2[i], &g_tbls[(32 * TEST_SOURCES) + (i * 32)]); gf_vect_mul_init(g3[i], &g_tbls[(64 * TEST_SOURCES) + (i * 32)]); gf_vect_mul_init(g4[i], &g_tbls[(96 * TEST_SOURCES) + (i * 32)]); gf_vect_mul_init(g5[i], &g_tbls[(128 * TEST_SOURCES) + (i * 32)]); } gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[0], buffs, dest_ref1); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], buffs, dest_ref2); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], buffs, dest_ref3); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES], buffs, dest_ref4); gf_vect_dot_prod_base(TEST_LEN, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES], buffs, dest_ref5); FUNCTION_UNDER_TEST(TEST_LEN, TEST_SOURCES, g_tbls, buffs, dest_ptrs); if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test1 %d\n", rtest); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref1, 25); printf("dprod_dut:"); dump(dest1, 25); return -1; } if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test2 %d\n", rtest); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref2, 25); printf("dprod_dut:"); dump(dest2, 25); return -1; } if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test3 %d\n", rtest); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref3, 25); printf("dprod_dut:"); dump(dest3, 25); return -1; } if (0 != memcmp(dest_ref4, dest4, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test4 %d\n", rtest); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref4, 25); printf("dprod_dut:"); dump(dest4, 25); return -1; } if (0 != memcmp(dest_ref5, dest5, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test5 %d\n", rtest); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref5, 25); printf("dprod_dut:"); dump(dest5, 25); return -1; } putchar('.'); } // Rand data test with varied parameters for (rtest = 0; rtest < RANDOMS; rtest++) { for (srcs = TEST_SOURCES; srcs > 0; srcs--) { for (i = 0; i < srcs; i++) for (j = 0; j < TEST_LEN; j++) buffs[i][j] = rand(); for (i = 0; i < srcs; i++) { g1[i] = rand(); g2[i] = rand(); g3[i] = rand(); g4[i] = rand(); g5[i] = rand(); } for (i = 0; i < srcs; i++) { gf_vect_mul_init(g1[i], &g_tbls[i * 32]); gf_vect_mul_init(g2[i], &g_tbls[(32 * srcs) + (i * 32)]); gf_vect_mul_init(g3[i], &g_tbls[(64 * srcs) + (i * 32)]); gf_vect_mul_init(g4[i], &g_tbls[(96 * srcs) + (i * 32)]); gf_vect_mul_init(g5[i], &g_tbls[(128 * srcs) + (i * 32)]); } gf_vect_dot_prod_base(TEST_LEN, srcs, &g_tbls[0], buffs, dest_ref1); gf_vect_dot_prod_base(TEST_LEN, srcs, &g_tbls[32 * srcs], buffs, dest_ref2); gf_vect_dot_prod_base(TEST_LEN, srcs, &g_tbls[64 * srcs], buffs, dest_ref3); gf_vect_dot_prod_base(TEST_LEN, srcs, &g_tbls[96 * srcs], buffs, dest_ref4); gf_vect_dot_prod_base(TEST_LEN, srcs, &g_tbls[128 * srcs], buffs, dest_ref5); FUNCTION_UNDER_TEST(TEST_LEN, srcs, g_tbls, buffs, dest_ptrs); if (0 != memcmp(dest_ref1, dest1, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test1 srcs=%d\n", srcs); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref1, 25); printf("dprod_dut:"); dump(dest1, 25); return -1; } if (0 != memcmp(dest_ref2, dest2, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test2 srcs=%d\n", srcs); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref2, 25); printf("dprod_dut:"); dump(dest2, 25); return -1; } if (0 != memcmp(dest_ref3, dest3, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test3 srcs=%d\n", srcs); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref3, 25); printf("dprod_dut:"); dump(dest3, 25); return -1; } if (0 != memcmp(dest_ref4, dest4, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test4 srcs=%d\n", srcs); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref4, 25); printf("dprod_dut:"); dump(dest4, 25); return -1; } if (0 != memcmp(dest_ref5, dest5, TEST_LEN)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test5 srcs=%d\n", srcs); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref5, 25); printf("dprod_dut:"); dump(dest5, 25); return -1; } putchar('.'); } } // Run tests at end of buffer for Electric Fence align = (LEN_ALIGN_CHK_B != 0) ? 1 : 16; for (size = TEST_MIN_SIZE; size <= TEST_SIZE; size += align) { for (i = 0; i < TEST_SOURCES; i++) for (j = 0; j < TEST_LEN; j++) buffs[i][j] = rand(); for (i = 0; i < TEST_SOURCES; i++) // Line up TEST_SIZE from end efence_buffs[i] = buffs[i] + TEST_LEN - size; for (i = 0; i < TEST_SOURCES; i++) { g1[i] = rand(); g2[i] = rand(); g3[i] = rand(); g4[i] = rand(); g5[i] = rand(); } for (i = 0; i < TEST_SOURCES; i++) { gf_vect_mul_init(g1[i], &g_tbls[i * 32]); gf_vect_mul_init(g2[i], &g_tbls[(32 * TEST_SOURCES) + (i * 32)]); gf_vect_mul_init(g3[i], &g_tbls[(64 * TEST_SOURCES) + (i * 32)]); gf_vect_mul_init(g4[i], &g_tbls[(96 * TEST_SOURCES) + (i * 32)]); gf_vect_mul_init(g5[i], &g_tbls[(128 * TEST_SOURCES) + (i * 32)]); } gf_vect_dot_prod_base(size, TEST_SOURCES, &g_tbls[0], efence_buffs, dest_ref1); gf_vect_dot_prod_base(size, TEST_SOURCES, &g_tbls[32 * TEST_SOURCES], efence_buffs, dest_ref2); gf_vect_dot_prod_base(size, TEST_SOURCES, &g_tbls[64 * TEST_SOURCES], efence_buffs, dest_ref3); gf_vect_dot_prod_base(size, TEST_SOURCES, &g_tbls[96 * TEST_SOURCES], efence_buffs, dest_ref4); gf_vect_dot_prod_base(size, TEST_SOURCES, &g_tbls[128 * TEST_SOURCES], efence_buffs, dest_ref5); FUNCTION_UNDER_TEST(size, TEST_SOURCES, g_tbls, efence_buffs, dest_ptrs); if (0 != memcmp(dest_ref1, dest1, size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test1 %d\n", rtest); dump_matrix(efence_buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref1, align); printf("dprod_dut:"); dump(dest1, align); return -1; } if (0 != memcmp(dest_ref2, dest2, size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test2 %d\n", rtest); dump_matrix(efence_buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref2, align); printf("dprod_dut:"); dump(dest2, align); return -1; } if (0 != memcmp(dest_ref3, dest3, size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test3 %d\n", rtest); dump_matrix(efence_buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref3, align); printf("dprod_dut:"); dump(dest3, align); return -1; } if (0 != memcmp(dest_ref4, dest4, size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test4 %d\n", rtest); dump_matrix(efence_buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref4, align); printf("dprod_dut:"); dump(dest4, align); return -1; } if (0 != memcmp(dest_ref5, dest5, size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test5 %d\n", rtest); dump_matrix(efence_buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref5, align); printf("dprod_dut:"); dump(dest5, align); return -1; } putchar('.'); } // Test rand ptr alignment if available for (rtest = 0; rtest < RANDOMS; rtest++) { size = (TEST_LEN - PTR_ALIGN_CHK_B) & ~(TEST_MIN_SIZE - 1); srcs = rand() % TEST_SOURCES; if (srcs == 0) continue; offset = (PTR_ALIGN_CHK_B != 0) ? 1 : PTR_ALIGN_CHK_B; // Add random offsets for (i = 0; i < srcs; i++) ubuffs[i] = buffs[i] + (rand() & (PTR_ALIGN_CHK_B - offset)); udest_ptrs[0] = dest1 + (rand() & (PTR_ALIGN_CHK_B - offset)); udest_ptrs[1] = dest2 + (rand() & (PTR_ALIGN_CHK_B - offset)); udest_ptrs[2] = dest3 + (rand() & (PTR_ALIGN_CHK_B - offset)); udest_ptrs[3] = dest4 + (rand() & (PTR_ALIGN_CHK_B - offset)); udest_ptrs[4] = dest5 + (rand() & (PTR_ALIGN_CHK_B - offset)); memset(dest1, 0, TEST_LEN); // zero pad to check write-over memset(dest2, 0, TEST_LEN); memset(dest3, 0, TEST_LEN); memset(dest4, 0, TEST_LEN); memset(dest5, 0, TEST_LEN); for (i = 0; i < srcs; i++) for (j = 0; j < size; j++) ubuffs[i][j] = rand(); for (i = 0; i < srcs; i++) { g1[i] = rand(); g2[i] = rand(); g3[i] = rand(); g4[i] = rand(); g5[i] = rand(); } for (i = 0; i < srcs; i++) { gf_vect_mul_init(g1[i], &g_tbls[i * 32]); gf_vect_mul_init(g2[i], &g_tbls[(32 * srcs) + (i * 32)]); gf_vect_mul_init(g3[i], &g_tbls[(64 * srcs) + (i * 32)]); gf_vect_mul_init(g4[i], &g_tbls[(96 * srcs) + (i * 32)]); gf_vect_mul_init(g5[i], &g_tbls[(128 * srcs) + (i * 32)]); } gf_vect_dot_prod_base(size, srcs, &g_tbls[0], ubuffs, dest_ref1); gf_vect_dot_prod_base(size, srcs, &g_tbls[32 * srcs], ubuffs, dest_ref2); gf_vect_dot_prod_base(size, srcs, &g_tbls[64 * srcs], ubuffs, dest_ref3); gf_vect_dot_prod_base(size, srcs, &g_tbls[96 * srcs], ubuffs, dest_ref4); gf_vect_dot_prod_base(size, srcs, &g_tbls[128 * srcs], ubuffs, dest_ref5); FUNCTION_UNDER_TEST(size, srcs, g_tbls, ubuffs, udest_ptrs); if (memcmp(dest_ref1, udest_ptrs[0], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign srcs=%d\n", srcs); dump_matrix(ubuffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref1, 25); printf("dprod_dut:"); dump(udest_ptrs[0], 25); return -1; } if (memcmp(dest_ref2, udest_ptrs[1], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign srcs=%d\n", srcs); dump_matrix(ubuffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref2, 25); printf("dprod_dut:"); dump(udest_ptrs[1], 25); return -1; } if (memcmp(dest_ref3, udest_ptrs[2], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign srcs=%d\n", srcs); dump_matrix(ubuffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref3, 25); printf("dprod_dut:"); dump(udest_ptrs[2], 25); return -1; } if (memcmp(dest_ref4, udest_ptrs[3], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign srcs=%d\n", srcs); dump_matrix(ubuffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref4, 25); printf("dprod_dut:"); dump(udest_ptrs[3], 25); return -1; } if (memcmp(dest_ref5, udest_ptrs[4], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign srcs=%d\n", srcs); dump_matrix(ubuffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref5, 25); printf("dprod_dut:"); dump(udest_ptrs[4], 25); return -1; } // Confirm that padding around dests is unchanged memset(dest_ref1, 0, PTR_ALIGN_CHK_B); // Make reference zero buff offset = udest_ptrs[0] - dest1; if (memcmp(dest1, dest_ref1, offset)) { printf("Fail rand ualign pad1 start\n"); return -1; } if (memcmp(dest1 + offset + size, dest_ref1, PTR_ALIGN_CHK_B - offset)) { printf("Fail rand ualign pad1 end\n"); return -1; } offset = udest_ptrs[1] - dest2; if (memcmp(dest2, dest_ref1, offset)) { printf("Fail rand ualign pad2 start\n"); return -1; } if (memcmp(dest2 + offset + size, dest_ref1, PTR_ALIGN_CHK_B - offset)) { printf("Fail rand ualign pad2 end\n"); return -1; } offset = udest_ptrs[2] - dest3; if (memcmp(dest3, dest_ref1, offset)) { printf("Fail rand ualign pad3 start\n"); return -1; } if (memcmp(dest3 + offset + size, dest_ref1, PTR_ALIGN_CHK_B - offset)) { printf("Fail rand ualign pad3 end\n"); return -1; } offset = udest_ptrs[3] - dest4; if (memcmp(dest4, dest_ref1, offset)) { printf("Fail rand ualign pad4 start\n"); return -1; } if (memcmp(dest4 + offset + size, dest_ref1, PTR_ALIGN_CHK_B - offset)) { printf("Fail rand ualign pad4 end\n"); return -1; } offset = udest_ptrs[4] - dest5; if (memcmp(dest5, dest_ref1, offset)) { printf("Fail rand ualign pad5 start\n"); return -1; } if (memcmp(dest5 + offset + size, dest_ref1, PTR_ALIGN_CHK_B - offset)) { printf("Fail rand ualign pad5 end\n"); return -1; } putchar('.'); } // Test all size alignment align = (LEN_ALIGN_CHK_B != 0) ? 1 : 16; for (size = TEST_LEN; size >= TEST_MIN_SIZE; size -= align) { srcs = TEST_SOURCES; for (i = 0; i < srcs; i++) for (j = 0; j < size; j++) buffs[i][j] = rand(); for (i = 0; i < srcs; i++) { g1[i] = rand(); g2[i] = rand(); g3[i] = rand(); g4[i] = rand(); g5[i] = rand(); } for (i = 0; i < srcs; i++) { gf_vect_mul_init(g1[i], &g_tbls[i * 32]); gf_vect_mul_init(g2[i], &g_tbls[(32 * srcs) + (i * 32)]); gf_vect_mul_init(g3[i], &g_tbls[(64 * srcs) + (i * 32)]); gf_vect_mul_init(g4[i], &g_tbls[(96 * srcs) + (i * 32)]); gf_vect_mul_init(g5[i], &g_tbls[(128 * srcs) + (i * 32)]); } gf_vect_dot_prod_base(size, srcs, &g_tbls[0], buffs, dest_ref1); gf_vect_dot_prod_base(size, srcs, &g_tbls[32 * srcs], buffs, dest_ref2); gf_vect_dot_prod_base(size, srcs, &g_tbls[64 * srcs], buffs, dest_ref3); gf_vect_dot_prod_base(size, srcs, &g_tbls[96 * srcs], buffs, dest_ref4); gf_vect_dot_prod_base(size, srcs, &g_tbls[128 * srcs], buffs, dest_ref5); FUNCTION_UNDER_TEST(size, srcs, g_tbls, buffs, dest_ptrs); if (memcmp(dest_ref1, dest_ptrs[0], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign len=%d\n", size); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref1, 25); printf("dprod_dut:"); dump(dest_ptrs[0], 25); return -1; } if (memcmp(dest_ref2, dest_ptrs[1], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign len=%d\n", size); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref2, 25); printf("dprod_dut:"); dump(dest_ptrs[1], 25); return -1; } if (memcmp(dest_ref3, dest_ptrs[2], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign len=%d\n", size); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref3, 25); printf("dprod_dut:"); dump(dest_ptrs[2], 25); return -1; } if (memcmp(dest_ref4, dest_ptrs[3], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign len=%d\n", size); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref4, 25); printf("dprod_dut:"); dump(dest_ptrs[3], 25); return -1; } if (memcmp(dest_ref5, dest_ptrs[4], size)) { printf("Fail rand " xstr(FUNCTION_UNDER_TEST) " test ualign len=%d\n", size); dump_matrix(buffs, 5, TEST_SOURCES); printf("dprod_base:"); dump(dest_ref5, 25); printf("dprod_dut:"); dump(dest_ptrs[4], 25); return -1; } } printf("Pass\n"); return 0; }
// Split from the basic MakePet to allow backward compatiblity with existing code while also // making it possible for petpower to be retained without the focus item having to // stay equipped when the character zones. petpower of -1 means that the currently equipped petfocus // of a client is searched for and used instead. void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower, const char *petname, float in_size) { // Sanity and early out checking first. if(HasPet() || pettype == nullptr) return; int16 act_power = 0; // The actual pet power we'll use. if (petpower == -1) { if (this->IsClient()) { act_power = CastToClient()->GetFocusEffect(focusPetPower, spell_id);//Client only act_power = CastToClient()->mod_pet_power(act_power, spell_id); } #ifdef BOTS else if (this->IsBot()) act_power = CastToBot()->GetBotFocusEffect(Bot::BotfocusPetPower, spell_id); #endif } else if (petpower > 0) act_power = petpower; // optional rule: classic style variance in pets. Achieve this by // adding a random 0-4 to pet power, since it only comes in increments // of five from focus effects. //lookup our pets table record for this type PetRecord record; if(!database.GetPoweredPetEntry(pettype, act_power, &record)) { Message(13, "Unable to find data for pet %s", pettype); Log.Out(Logs::General, Logs::Error, "Unable to find data for pet %s, check pets table.", pettype); return; } //find the NPC data for the specified NPC type const NPCType *base = database.LoadNPCTypesData(record.npc_type); if(base == nullptr) { Message(13, "Unable to load NPC data for pet %s", pettype); Log.Out(Logs::General, Logs::Error, "Unable to load NPC data for pet %s (NPC ID %d), check pets and npc_types tables.", pettype, record.npc_type); return; } //we copy the npc_type data because we need to edit it a bit NPCType *npc_type = new NPCType; memcpy(npc_type, base, sizeof(NPCType)); // If pet power is set to -1 in the DB, use stat scaling if ((this->IsClient() #ifdef BOTS || this->IsBot() #endif ) && record.petpower == -1) { float scale_power = (float)act_power / 100.0f; if(scale_power > 0) { npc_type->max_hp *= (1 + scale_power); npc_type->cur_hp = npc_type->max_hp; npc_type->AC *= (1 + scale_power); npc_type->level += 1 + ((int)act_power / 25) > npc_type->level + RuleR(Pets, PetPowerLevelCap) ? RuleR(Pets, PetPowerLevelCap) : 1 + ((int)act_power / 25); // gains an additional level for every 25 pet power npc_type->min_dmg = (npc_type->min_dmg * (1 + (scale_power / 2))); npc_type->max_dmg = (npc_type->max_dmg * (1 + (scale_power / 2))); npc_type->size = npc_type->size * (1 + (scale_power / 2)) > npc_type->size * 3 ? npc_type->size * 3 : (1 + (scale_power / 2)); } record.petpower = act_power; } //Live AA - Elemental Durability int16 MaxHP = aabonuses.PetMaxHP + itembonuses.PetMaxHP + spellbonuses.PetMaxHP; if (MaxHP){ npc_type->max_hp += (npc_type->max_hp*MaxHP)/100; npc_type->cur_hp = npc_type->max_hp; } //TODO: think about regen (engaged vs. not engaged) // Pet naming: // 0 - `s pet // 1 - `s familiar // 2 - `s Warder // 3 - Random name if client, `s pet for others // 4 - Keep DB name if (petname != nullptr) { // Name was provided, use it. strn0cpy(npc_type->name, petname, 64); } else if (record.petnaming == 0) { strcpy(npc_type->name, this->GetCleanName()); npc_type->name[25] = '\0'; strcat(npc_type->name, "`s_pet"); } else if (record.petnaming == 1) { strcpy(npc_type->name, this->GetName()); npc_type->name[19] = '\0'; strcat(npc_type->name, "`s_familiar"); } else if (record.petnaming == 2) { strcpy(npc_type->name, this->GetName()); npc_type->name[21] = 0; strcat(npc_type->name, "`s_Warder"); } else if (record.petnaming == 4) { // Keep the DB name } else if (record.petnaming == 3 && IsClient()) { strcpy(npc_type->name, GetRandPetName()); } else { strcpy(npc_type->name, this->GetCleanName()); npc_type->name[25] = '\0'; strcat(npc_type->name, "`s_pet"); } //handle beastlord pet appearance if(record.petnaming == 2) { switch(GetBaseRace()) { case VAHSHIR: npc_type->race = TIGER; npc_type->size *= 0.8f; break; case TROLL: npc_type->race = ALLIGATOR; npc_type->size *= 2.5f; break; case OGRE: npc_type->race = BEAR; npc_type->texture = 3; npc_type->gender = 2; break; case BARBARIAN: npc_type->race = WOLF; npc_type->texture = 2; break; case IKSAR: npc_type->race = WOLF; npc_type->texture = 0; npc_type->gender = 1; npc_type->size *= 2.0f; npc_type->luclinface = 0; break; default: npc_type->race = WOLF; npc_type->texture = 0; } } // handle monster summoning pet appearance if(record.monsterflag) { uint32 monsterid = 0; // get a random npc id from the spawngroups assigned to this zone auto query = StringFormat("SELECT npcID " "FROM (spawnentry INNER JOIN spawn2 ON spawn2.spawngroupID = spawnentry.spawngroupID) " "INNER JOIN npc_types ON npc_types.id = spawnentry.npcID " "WHERE spawn2.zone = '%s' AND npc_types.bodytype NOT IN (11, 33, 66, 67) " "AND npc_types.race NOT IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 44, " "55, 67, 71, 72, 73, 77, 78, 81, 90, 92, 93, 94, 106, 112, 114, 127, 128, " "130, 139, 141, 183, 236, 237, 238, 239, 254, 266, 329, 330, 378, 379, " "380, 381, 382, 383, 404, 522) " "ORDER BY RAND() LIMIT 1", zone->GetShortName()); auto results = database.QueryDatabase(query); if (!results.Success()) { return; } if (results.RowCount() != 0) { auto row = results.begin(); monsterid = atoi(row[0]); } // since we don't have any monsters, just make it look like an earth pet for now if (monsterid == 0) monsterid = 567; // give the summoned pet the attributes of the monster we found const NPCType* monster = database.LoadNPCTypesData(monsterid); if(monster) { npc_type->race = monster->race; npc_type->size = monster->size; npc_type->texture = monster->texture; npc_type->gender = monster->gender; npc_type->luclinface = monster->luclinface; npc_type->helmtexture = monster->helmtexture; npc_type->herosforgemodel = monster->herosforgemodel; } else Log.Out(Logs::General, Logs::Error, "Error loading NPC data for monster summoning pet (NPC ID %d)", monsterid); } //this takes ownership of the npc_type data Pet *npc = new Pet(npc_type, this, (PetType)record.petcontrol, spell_id, record.petpower); // Now that we have an actual object to interact with, load // the base items for the pet. These are always loaded // so that a rank 1 suspend minion does not kill things // like the special back items some focused pets may receive. uint32 petinv[EmuConstants::EQUIPMENT_SIZE]; memset(petinv, 0, sizeof(petinv)); const Item_Struct *item = 0; if (database.GetBasePetItems(record.equipmentset, petinv)) { for (int i = 0; i<EmuConstants::EQUIPMENT_SIZE; i++) if (petinv[i]) { item = database.GetItem(petinv[i]); npc->AddLootDrop(item, &npc->itemlist, 0, 1, 127, true, true); } } npc->UpdateEquipmentLight(); // finally, override size if one was provided if (in_size > 0.0f) npc->size = in_size; entity_list.AddNPC(npc, true, true); SetPetID(npc->GetID()); // We need to handle PetType 5 (petHatelist), add the current target to the hatelist of the pet if (record.petcontrol == petTargetLock) { Mob* target = GetTarget(); if (target){ npc->AddToHateList(target, 1); npc->SetPetTargetLockID(target->GetID()); npc->SetSpecialAbility(IMMUNE_AGGRO, 1); } else npc->Kill(); //On live casts spell 892 Unsummon (Kayen - Too limiting to use that for emu since pet can have more than 20k HP) } }
static int fail_this_path(int fd, int lun, int use_6_byte) { unsigned char fail_paths_pg[308]; struct rdac_legacy_page *rdac_page; struct rdac_expanded_page *rdac_page_exp; struct rdac_page_common *rdac_common = NULL; int res; char b[80]; if (use_6_byte && lun > 32) { pr2serr("must use 10 byte cdb to fail luns over 32\n"); return -1; } memset(fail_paths_pg, 0, 308); if (use_6_byte) { memcpy(fail_paths_pg, mode6_hdr, 4); memcpy(fail_paths_pg + 4, block_descriptor, 8); rdac_page = (struct rdac_legacy_page *)(fail_paths_pg + 4 + 8); rdac_page->page_code = RDAC_CONTROLLER_PAGE; rdac_page->page_length = RDAC_CONTROLLER_PAGE_LEN; rdac_common = &rdac_page->attr; memset(rdac_page->lun_table, 0x0, 32); rdac_page->lun_table[lun] = 0x81; } else { memcpy(fail_paths_pg, mode10_hdr, 8); rdac_page_exp = (struct rdac_expanded_page *) (fail_paths_pg + 8); rdac_page_exp->page_code = RDAC_CONTROLLER_PAGE | 0x40; rdac_page_exp->subpage_code = 0x1; sg_put_unaligned_be16(EXPANDED_LUN_SPACE_PAGE_LEN, rdac_page_exp->page_length + 0); rdac_common = &rdac_page_exp->attr; memset(rdac_page_exp->lun_table, 0x0, 256); rdac_page_exp->lun_table[lun] = 0x81; } rdac_common->current_mode_lsb = RDAC_FAIL_SELECTED_PATHS; rdac_common->quiescence = RDAC_QUIESCENCE_TIME; rdac_common->options = RDAC_FORCE_QUIESCENCE; if (use_6_byte) { res = sg_ll_mode_select6(fd, 1 /* pf */, 0 /* sp */, fail_paths_pg, 118, 1, (do_verbose ? 2 : 0)); } else { res = sg_ll_mode_select10(fd, 1 /* pf */, 0 /* sp */, fail_paths_pg, 308, 1, (do_verbose ? 2: 0)); } switch (res) { case 0: if (do_verbose) pr2serr("fail paths successful\n"); break; default: sg_get_category_sense_str(res, sizeof(b), b, do_verbose); pr2serr("fail paths page (lun=%d) failed: %s\n", lun, b); break; } return res; }
/* Compile - compile a program */ int Compile(ParseContext *c, uint8_t *imageSpace, size_t imageSize, size_t textMax, size_t dataMax) { ImageHdr *image = (ImageHdr *)imageSpace; VMUVALUE textSize; /* setup an error target */ if (setjmp(c->errorTarget) != 0) return -1; /* initialize the image */ if (imageSize < sizeof(ImageHdr) + textMax + dataMax) return -1; memset(image, 0, sizeof(ImageHdr)); c->image = image; /* empty the heap */ c->localFree = c->heapBase; c->globalFree = c->heapTop; /* initialize the image */ c->textBase = c->textFree = imageSpace + sizeof(ImageHdr); c->textTop = c->textBase + textMax; c->dataBase = c->dataFree = c->textBase + textMax; c->dataTop = c->dataBase + dataMax; /* initialize the code buffer */ c->codeFree = c->codeBuf; c->codeTop = c->codeBuf + sizeof(c->codeBuf); /* initialize block nesting table */ c->btop = (Block *)((char *)c->blockBuf + sizeof(c->blockBuf)); c->bptr = c->blockBuf - 1; /* initialize the global symbol table and string table */ InitSymbolTable(&c->globals); /* enter the built-in functions */ EnterBuiltInFunction(c, "delayMs", bi_delayms, sizeof(bi_delayms)); EnterBuiltInFunction(c, "updateLeds", bi_updateleds, sizeof(bi_updateleds)); /* enter the built-in variables */ /* typedef struct { int32_t triggerTop; int32_t triggerBottom; int32_t numLeds; int32_t led[RGB_SIZE]; int32_t patternnum; } VM_variables; */ EnterBuiltInVariable(c, "triggerTop", sizeof(VMVALUE)); EnterBuiltInVariable(c, "triggerBottom", sizeof(VMVALUE)); EnterBuiltInVariable(c, "numLeds", sizeof(VMVALUE)); EnterBuiltInVariable(c, "led", sizeof(VMVALUE) * RGB_SIZE); EnterBuiltInVariable(c, "patternNum", sizeof(VMVALUE)); /* initialize the string table */ c->strings = NULL; /* initialize the label table */ c->labels = NULL; /* start in the main code */ c->codeType = CODE_TYPE_MAIN; /* initialize scanner */ c->inComment = VMFALSE; c->lineNumber = 0; /* compile each line */ while (GetLine(c)) { int tkn; if ((tkn = GetToken(c)) != T_EOL) ParseStatement(c, tkn); } /* end the main code with a halt */ putcbyte(c, OP_HALT); /* write the main code */ StartCode(c, CODE_TYPE_MAIN); image->entry = StoreCode(c); /* determine the text size */ textSize = c->textFree - c->textBase; /* fill in the image header */ image->dataOffset = sizeof(ImageHdr) + textSize; image->dataSize = c->dataFree - c->dataBase; image->imageSize = image->dataOffset + image->dataSize; /* make the data contiguous with the code */ memcpy(&imageSpace[image->dataOffset], c->dataBase, image->dataSize); #ifdef COMPILER_DEBUG VM_printf("entry "); PrintValue(image->entry); VM_printf("\n"); VM_printf("imageSize "); PrintValue(image->imageSize); VM_printf("\n"); VM_printf("textSize "); PrintValue(textSize); VM_printf("\n"); VM_printf("dataOffset "); PrintValue(image->dataOffset); VM_printf("\n"); VM_printf("dataSize "); PrintValue(image->dataSize); VM_printf("\n"); DumpSymbols(&c->globals, "symbols"); #endif /* return successfully */ return 0; }
static void work_a_0977831778_3212880686_p_3(char *t0) { char *t1; char *t2; char *t3; char *t4; char *t5; char *t6; char *t7; unsigned char t8; unsigned char t9; unsigned char t10; unsigned char t11; unsigned char t12; unsigned int t13; char *t14; char *t15; char *t16; char *t17; char *t18; int t19; int t20; int t21; int t22; int t23; unsigned int t24; unsigned int t25; static char *nl0[] = {&&LAB3, &&LAB4, &&LAB5, &&LAB6, &&LAB7, &&LAB8, &&LAB9, &&LAB10}; LAB0: xsi_set_current_line(318, ng0); t1 = (t0 + 193416); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)2; xsi_driver_first_trans_fast(t1); xsi_set_current_line(319, ng0); t1 = xsi_get_transient_memory(256U); memset(t1, 0, 256U); t2 = t1; memset(t2, (unsigned char)2, 256U); t3 = (t0 + 193480); t4 = (t3 + 56U); t5 = *((char **)t4); t6 = (t5 + 56U); t7 = *((char **)t6); memcpy(t7, t1, 256U); xsi_driver_first_trans_fast(t3); xsi_set_current_line(320, ng0); t1 = (t0 + 142600U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t1 = (t0 + 193544); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = t8; xsi_driver_first_trans_fast(t1); xsi_set_current_line(321, ng0); t1 = (t0 + 137960U); t2 = *((char **)t1); t1 = (t0 + 193608); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 2048U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(322, ng0); t1 = (t0 + 140680U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t1 = (t0 + 193672); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = t8; xsi_driver_first_trans_fast(t1); xsi_set_current_line(323, ng0); t1 = (t0 + 139560U); t2 = *((char **)t1); t1 = (t0 + 193736); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(324, ng0); t1 = (t0 + 138600U); t2 = *((char **)t1); t1 = (t0 + 193800); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(325, ng0); t1 = (t0 + 138920U); t2 = *((char **)t1); t1 = (t0 + 193864); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(326, ng0); t1 = (t0 + 142600U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t1 = (char *)((nl0) + t8); goto **((char **)t1); LAB2: t1 = (t0 + 192536); *((int *)t1) = 1; LAB1: return; LAB3: xsi_set_current_line(329, ng0); t3 = (t0 + 136520U); t4 = *((char **)t3); t10 = *((unsigned char *)t4); t11 = (t10 == (unsigned char)3); if (t11 == 1) goto LAB15; LAB16: t9 = (unsigned char)0; LAB17: if (t9 != 0) goto LAB12; LAB14: LAB13: goto LAB2; LAB4: xsi_set_current_line(334, ng0); t1 = (t0 + 136520U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t9 = (t8 == (unsigned char)3); if (t9 != 0) goto LAB24; LAB26: LAB25: goto LAB2; LAB5: xsi_set_current_line(352, ng0); t1 = (t0 + 136520U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t9 = (t8 == (unsigned char)3); if (t9 != 0) goto LAB40; LAB42: LAB41: goto LAB2; LAB6: xsi_set_current_line(358, ng0); t1 = (t0 + 136520U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t9 = (t8 == (unsigned char)3); if (t9 != 0) goto LAB43; LAB45: LAB44: goto LAB2; LAB7: xsi_set_current_line(365, ng0); t1 = (t0 + 193672); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)2; xsi_driver_first_trans_fast(t1); xsi_set_current_line(366, ng0); t1 = (t0 + 140680U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t9 = (t8 == (unsigned char)3); if (t9 != 0) goto LAB46; LAB48: LAB47: xsi_set_current_line(369, ng0); t1 = (t0 + 136520U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t9 = (t8 == (unsigned char)3); if (t9 != 0) goto LAB49; LAB51: LAB50: goto LAB2; LAB8: xsi_set_current_line(375, ng0); t1 = (t0 + 136520U); t2 = *((char **)t1); t8 = *((unsigned char *)t2); t9 = (t8 == (unsigned char)3); if (t9 != 0) goto LAB52; LAB54: LAB53: goto LAB2; LAB9: xsi_set_current_line(381, ng0); t1 = (t0 + 142280U); t2 = *((char **)t1); t19 = *((int *)t2); t20 = (t19 - 0); t13 = (t20 * 1); t24 = (1 * t13); t25 = (0U + t24); t1 = (t0 + 193480); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = (unsigned char)3; xsi_driver_first_trans_delta(t1, t25, 1, 0LL); xsi_set_current_line(382, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB2; LAB10: xsi_set_current_line(385, ng0); t1 = (t0 + 193672); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)3; xsi_driver_first_trans_fast(t1); xsi_set_current_line(386, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB2; LAB11: xsi_set_current_line(389, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB2; LAB12: xsi_set_current_line(330, ng0); t14 = (t0 + 193544); t15 = (t14 + 56U); t16 = *((char **)t15); t17 = (t16 + 56U); t18 = *((char **)t17); *((unsigned char *)t18) = (unsigned char)1; xsi_driver_first_trans_fast(t14); goto LAB13; LAB15: t3 = (t0 + 136680U); t5 = *((char **)t3); t3 = (t0 + 155536U); t6 = *((char **)t3); t12 = 1; if (8U == 8U) goto LAB18; LAB19: t12 = 0; LAB20: t9 = t12; goto LAB17; LAB18: t13 = 0; LAB21: if (t13 < 8U) goto LAB22; else goto LAB20; LAB22: t3 = (t5 + t13); t7 = (t6 + t13); if (*((unsigned char *)t3) != *((unsigned char *)t7)) goto LAB19; LAB23: t13 = (t13 + 1); goto LAB21; LAB24: xsi_set_current_line(335, ng0); t1 = (t0 + 136680U); t3 = *((char **)t1); t1 = (t0 + 155656U); t4 = *((char **)t1); t19 = xsi_mem_cmp(t4, t3, 8U); if (t19 == 1) goto LAB28; LAB34: t1 = (t0 + 155776U); t5 = *((char **)t1); t20 = xsi_mem_cmp(t5, t3, 8U); if (t20 == 1) goto LAB29; LAB35: t1 = (t0 + 155896U); t6 = *((char **)t1); t21 = xsi_mem_cmp(t6, t3, 8U); if (t21 == 1) goto LAB30; LAB36: t1 = (t0 + 156016U); t7 = *((char **)t1); t22 = xsi_mem_cmp(t7, t3, 8U); if (t22 == 1) goto LAB31; LAB37: t1 = (t0 + 156136U); t14 = *((char **)t1); t23 = xsi_mem_cmp(t14, t3, 8U); if (t23 == 1) goto LAB32; LAB38: LAB33: xsi_set_current_line(347, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); LAB27: goto LAB25; LAB28: xsi_set_current_line(337, ng0); t1 = (t0 + 193544); t15 = (t1 + 56U); t16 = *((char **)t15); t17 = (t16 + 56U); t18 = *((char **)t17); *((unsigned char *)t18) = (unsigned char)2; xsi_driver_first_trans_fast(t1); goto LAB27; LAB29: xsi_set_current_line(339, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)4; xsi_driver_first_trans_fast(t1); goto LAB27; LAB30: xsi_set_current_line(341, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)5; xsi_driver_first_trans_fast(t1); goto LAB27; LAB31: xsi_set_current_line(343, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)6; xsi_driver_first_trans_fast(t1); goto LAB27; LAB32: xsi_set_current_line(345, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)7; xsi_driver_first_trans_fast(t1); goto LAB27; LAB39:; LAB40: xsi_set_current_line(353, ng0); t1 = (t0 + 136680U); t3 = *((char **)t1); t1 = (t0 + 193736); t4 = (t1 + 56U); t5 = *((char **)t4); t6 = (t5 + 56U); t7 = *((char **)t6); memcpy(t7, t3, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(354, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)3; xsi_driver_first_trans_fast(t1); goto LAB41; LAB43: xsi_set_current_line(359, ng0); t1 = (t0 + 136680U); t3 = *((char **)t1); t1 = (t0 + 141960U); t4 = *((char **)t1); t19 = *((int *)t4); t20 = (t19 - 0); t13 = (t20 * 1); t24 = (8U * t13); t25 = (0U + t24); t1 = (t0 + 193608); t5 = (t1 + 56U); t6 = *((char **)t5); t7 = (t6 + 56U); t14 = *((char **)t7); memcpy(t14, t3, 8U); xsi_driver_first_trans_delta(t1, t25, 8U, 0LL); xsi_set_current_line(360, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB44; LAB46: xsi_set_current_line(367, ng0); t1 = (t0 + 193416); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = (unsigned char)3; xsi_driver_first_trans_fast(t1); goto LAB47; LAB49: xsi_set_current_line(370, ng0); t1 = (t0 + 136680U); t3 = *((char **)t1); t1 = (t0 + 193800); t4 = (t1 + 56U); t5 = *((char **)t4); t6 = (t5 + 56U); t7 = *((char **)t6); memcpy(t7, t3, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(371, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB50; LAB52: xsi_set_current_line(376, ng0); t1 = (t0 + 136680U); t3 = *((char **)t1); t1 = (t0 + 193864); t4 = (t1 + 56U); t5 = *((char **)t4); t6 = (t5 + 56U); t7 = *((char **)t6); memcpy(t7, t3, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(377, ng0); t1 = (t0 + 193544); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB53; } static void work_a_0977831778_3212880686_p_4(char *t0) { char t24[16]; char t25[16]; char *t1; char *t2; char *t3; char *t4; char *t5; char *t6; unsigned char t7; char *t8; char *t9; char *t10; unsigned char t11; int t12; int t13; unsigned int t14; unsigned int t15; unsigned int t16; int t17; int t18; char *t19; char *t20; char *t21; char *t22; char *t23; static char *nl0[] = {&&LAB3, &&LAB4, &&LAB5, &&LAB6, &&LAB7, &&LAB8, &&LAB9, &&LAB10}; LAB0: xsi_set_current_line(398, ng0); t1 = (t0 + 139240U); t2 = *((char **)t1); t1 = (t0 + 193928); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(399, ng0); t1 = (t0 + 137480U); t2 = *((char **)t1); t1 = (t0 + 193992); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 256U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(400, ng0); t1 = (t0 + 140200U); t2 = *((char **)t1); t1 = (t0 + 194056); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 2U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(401, ng0); t1 = (t0 + 142920U); t2 = *((char **)t1); t7 = *((unsigned char *)t2); t1 = (t0 + 194120); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = t7; xsi_driver_first_trans_fast(t1); xsi_set_current_line(402, ng0); t1 = (t0 + 142920U); t2 = *((char **)t1); t7 = *((unsigned char *)t2); t1 = (char *)((nl0) + t7); goto **((char **)t1); LAB2: t1 = (t0 + 192552); *((int *)t1) = 1; LAB1: return; LAB3: xsi_set_current_line(405, ng0); t3 = xsi_get_transient_memory(2U); memset(t3, 0, 2U); t4 = t3; memset(t4, (unsigned char)2, 2U); t5 = (t0 + 194056); t6 = (t5 + 56U); t8 = *((char **)t6); t9 = (t8 + 56U); t10 = *((char **)t9); memcpy(t10, t3, 2U); xsi_driver_first_trans_fast(t5); xsi_set_current_line(406, ng0); t1 = xsi_get_transient_memory(256U); memset(t1, 0, 256U); t2 = t1; memset(t2, (unsigned char)2, 256U); t3 = (t0 + 193992); t4 = (t3 + 56U); t5 = *((char **)t4); t6 = (t5 + 56U); t8 = *((char **)t6); memcpy(t8, t1, 256U); xsi_driver_first_trans_fast(t3); xsi_set_current_line(407, ng0); t1 = (t0 + 138920U); t2 = *((char **)t1); t1 = (t0 + 193928); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); memcpy(t6, t2, 8U); xsi_driver_first_trans_fast(t1); xsi_set_current_line(409, ng0); t1 = (t0 + 141000U); t2 = *((char **)t1); t7 = *((unsigned char *)t2); t11 = (t7 == (unsigned char)3); if (t11 != 0) goto LAB12; LAB14: LAB13: goto LAB2; LAB4: xsi_set_current_line(414, ng0); t1 = (t0 + 142120U); t2 = *((char **)t1); t12 = *((int *)t2); t13 = (t12 - 0); t14 = (t13 * 1); t15 = (1 * t14); t16 = (0U + t15); t1 = (t0 + 193992); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = (unsigned char)3; xsi_driver_first_trans_delta(t1, t16, 1, 0LL); xsi_set_current_line(415, ng0); t1 = (t0 + 137800U); t2 = *((char **)t1); t1 = (t0 + 142120U); t3 = *((char **)t1); t12 = *((int *)t3); t13 = (t12 - 0); t14 = (t13 * 1); xsi_vhdl_check_range_of_index(0, 255, 1, t12); t15 = (2U * t14); t16 = (0 + t15); t1 = (t2 + t16); t4 = (t0 + 194056); t5 = (t4 + 56U); t6 = *((char **)t5); t8 = (t6 + 56U); t9 = *((char **)t8); memcpy(t9, t1, 2U); xsi_driver_first_trans_fast(t4); xsi_set_current_line(416, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)2; xsi_driver_first_trans_fast(t1); goto LAB2; LAB5: xsi_set_current_line(420, ng0); t1 = (t0 + 139240U); t2 = *((char **)t1); t1 = (t0 + 302784U); t3 = (t0 + 138600U); t4 = *((char **)t3); t3 = (t0 + 302784U); t7 = ieee_p_1242562249_sub_1434220770680401498_1035706684(IEEE_P_1242562249, t2, t1, t4, t3); if (t7 != 0) goto LAB15; LAB17: xsi_set_current_line(434, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)7; xsi_driver_first_trans_fast(t1); LAB16: goto LAB2; LAB6: xsi_set_current_line(438, ng0); t1 = (t0 + 139240U); t2 = *((char **)t1); t1 = (t0 + 302784U); t3 = (t0 + 312088); t5 = (t25 + 0U); t6 = (t5 + 0U); *((int *)t6) = 0; t6 = (t5 + 4U); *((int *)t6) = 4; t6 = (t5 + 8U); *((int *)t6) = 1; t12 = (4 - 0); t14 = (t12 * 1); t14 = (t14 + 1); t6 = (t5 + 12U); *((unsigned int *)t6) = t14; t6 = ieee_p_1242562249_sub_1701011461141789389_1035706684(IEEE_P_1242562249, t24, t2, t1, t3, t25); t8 = (t24 + 12U); t14 = *((unsigned int *)t8); t15 = (1U * t14); t7 = (8U != t15); if (t7 == 1) goto LAB29; LAB30: t9 = (t0 + 193928); t10 = (t9 + 56U); t19 = *((char **)t10); t20 = (t19 + 56U); t21 = *((char **)t20); memcpy(t21, t6, 8U); xsi_driver_first_trans_fast(t9); xsi_set_current_line(439, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)1; xsi_driver_first_trans_fast(t1); goto LAB2; LAB7: xsi_set_current_line(442, ng0); t1 = (t0 + 139240U); t2 = *((char **)t1); t1 = (t0 + 302784U); t3 = (t0 + 312093); t5 = (t25 + 0U); t6 = (t5 + 0U); *((int *)t6) = 0; t6 = (t5 + 4U); *((int *)t6) = 4; t6 = (t5 + 8U); *((int *)t6) = 1; t12 = (4 - 0); t14 = (t12 * 1); t14 = (t14 + 1); t6 = (t5 + 12U); *((unsigned int *)t6) = t14; t6 = ieee_p_1242562249_sub_1701011461141717515_1035706684(IEEE_P_1242562249, t24, t2, t1, t3, t25); t8 = (t24 + 12U); t14 = *((unsigned int *)t8); t15 = (1U * t14); t7 = (8U != t15); if (t7 == 1) goto LAB31; LAB32: t9 = (t0 + 193928); t10 = (t9 + 56U); t19 = *((char **)t10); t20 = (t19 + 56U); t21 = *((char **)t20); memcpy(t21, t6, 8U); xsi_driver_first_trans_fast(t9); xsi_set_current_line(443, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)1; xsi_driver_first_trans_fast(t1); goto LAB2; LAB8: xsi_set_current_line(446, ng0); t1 = (t0 + 139240U); t2 = *((char **)t1); t1 = (t0 + 302784U); t3 = (t0 + 312098); t5 = (t25 + 0U); t6 = (t5 + 0U); *((int *)t6) = 0; t6 = (t5 + 4U); *((int *)t6) = 4; t6 = (t5 + 8U); *((int *)t6) = 1; t12 = (4 - 0); t14 = (t12 * 1); t14 = (t14 + 1); t6 = (t5 + 12U); *((unsigned int *)t6) = t14; t6 = ieee_p_1242562249_sub_1701011461141717515_1035706684(IEEE_P_1242562249, t24, t2, t1, t3, t25); t8 = (t24 + 12U); t14 = *((unsigned int *)t8); t15 = (1U * t14); t7 = (8U != t15); if (t7 == 1) goto LAB33; LAB34: t9 = (t0 + 193928); t10 = (t9 + 56U); t19 = *((char **)t10); t20 = (t19 + 56U); t21 = *((char **)t20); memcpy(t21, t6, 8U); xsi_driver_first_trans_fast(t9); xsi_set_current_line(447, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)1; xsi_driver_first_trans_fast(t1); goto LAB2; LAB9: xsi_set_current_line(450, ng0); t1 = (t0 + 139240U); t2 = *((char **)t1); t1 = (t0 + 302784U); t3 = (t0 + 312103); t5 = (t25 + 0U); t6 = (t5 + 0U); *((int *)t6) = 0; t6 = (t5 + 4U); *((int *)t6) = 4; t6 = (t5 + 8U); *((int *)t6) = 1; t12 = (4 - 0); t14 = (t12 * 1); t14 = (t14 + 1); t6 = (t5 + 12U); *((unsigned int *)t6) = t14; t6 = ieee_p_1242562249_sub_1701011461141789389_1035706684(IEEE_P_1242562249, t24, t2, t1, t3, t25); t8 = (t24 + 12U); t14 = *((unsigned int *)t8); t15 = (1U * t14); t7 = (8U != t15); if (t7 == 1) goto LAB35; LAB36: t9 = (t0 + 193928); t10 = (t9 + 56U); t19 = *((char **)t10); t20 = (t19 + 56U); t21 = *((char **)t20); memcpy(t21, t6, 8U); xsi_driver_first_trans_fast(t9); xsi_set_current_line(451, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)1; xsi_driver_first_trans_fast(t1); goto LAB2; LAB10: xsi_set_current_line(454, ng0); t1 = (t0 + 140520U); t2 = *((char **)t1); t7 = *((unsigned char *)t2); t11 = (t7 == (unsigned char)3); if (t11 != 0) goto LAB37; LAB39: LAB38: goto LAB2; LAB11: xsi_set_current_line(459, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB2; LAB12: xsi_set_current_line(410, ng0); t1 = (t0 + 194120); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = (unsigned char)1; xsi_driver_first_trans_fast(t1); goto LAB13; LAB15: xsi_set_current_line(421, ng0); t5 = (t0 + 194120); t6 = (t5 + 56U); t8 = *((char **)t6); t9 = (t8 + 56U); t10 = *((char **)t9); *((unsigned char *)t10) = (unsigned char)1; xsi_driver_first_trans_fast(t5); xsi_set_current_line(422, ng0); t1 = (t0 + 140200U); t2 = *((char **)t1); t1 = (t0 + 312080); t12 = xsi_mem_cmp(t1, t2, 2U); if (t12 == 1) goto LAB19; LAB24: t4 = (t0 + 312082); t13 = xsi_mem_cmp(t4, t2, 2U); if (t13 == 1) goto LAB20; LAB25: t6 = (t0 + 312084); t17 = xsi_mem_cmp(t6, t2, 2U); if (t17 == 1) goto LAB21; LAB26: t9 = (t0 + 312086); t18 = xsi_mem_cmp(t9, t2, 2U); if (t18 == 1) goto LAB22; LAB27: LAB23: xsi_set_current_line(431, ng0); LAB18: goto LAB16; LAB19: xsi_set_current_line(424, ng0); t19 = (t0 + 194120); t20 = (t19 + 56U); t21 = *((char **)t20); t22 = (t21 + 56U); t23 = *((char **)t22); *((unsigned char *)t23) = (unsigned char)3; xsi_driver_first_trans_fast(t19); goto LAB18; LAB20: xsi_set_current_line(426, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)4; xsi_driver_first_trans_fast(t1); goto LAB18; LAB21: xsi_set_current_line(428, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)5; xsi_driver_first_trans_fast(t1); goto LAB18; LAB22: xsi_set_current_line(430, ng0); t1 = (t0 + 194120); t2 = (t1 + 56U); t3 = *((char **)t2); t4 = (t3 + 56U); t5 = *((char **)t4); *((unsigned char *)t5) = (unsigned char)6; xsi_driver_first_trans_fast(t1); goto LAB18; LAB28:; LAB29: xsi_size_not_matching(8U, t15, 0); goto LAB30; LAB31: xsi_size_not_matching(8U, t15, 0); goto LAB32; LAB33: xsi_size_not_matching(8U, t15, 0); goto LAB34; LAB35: xsi_size_not_matching(8U, t15, 0); goto LAB36; LAB37: xsi_set_current_line(455, ng0); t1 = (t0 + 194120); t3 = (t1 + 56U); t4 = *((char **)t3); t5 = (t4 + 56U); t6 = *((char **)t5); *((unsigned char *)t6) = (unsigned char)0; xsi_driver_first_trans_fast(t1); goto LAB38; } static void work_a_0977831778_3212880686_p_5(char *t0) { char *t1; char *t2; char *t3; int t4; int t5; unsigned int t6; unsigned int t7; unsigned int t8; unsigned char t9; char *t10; char *t11; char *t12; char *t13; char *t14; LAB0: xsi_set_current_line(466, ng0); t1 = (t0 + 137480U); t2 = *((char **)t1); t1 = (t0 + 141800U); t3 = *((char **)t1); t4 = *((int *)t3); t5 = (t4 - 0); t6 = (t5 * 1); xsi_vhdl_check_range_of_index(0, 255, 1, t4); t7 = (1U * t6); t8 = (0 + t7); t1 = (t2 + t8); t9 = *((unsigned char *)t1); t10 = (t0 + 194184); t11 = (t10 + 56U); t12 = *((char **)t11); t13 = (t12 + 56U); t14 = *((char **)t13); *((unsigned char *)t14) = t9; xsi_driver_first_trans_fast_port(t10); xsi_set_current_line(467, ng0); t1 = (t0 + 138280U); t2 = *((char **)t1); t1 = (t0 + 141800U); t3 = *((char **)t1); t4 = *((int *)t3); t5 = (t4 - 0); t6 = (t5 * 1); xsi_vhdl_check_range_of_index(0, 255, 1, t4); t7 = (8U * t6); t8 = (0 + t7); t1 = (t2 + t8); t10 = (t0 + 194248); t11 = (t10 + 56U); t12 = *((char **)t11); t13 = (t12 + 56U); t14 = *((char **)t13); memcpy(t14, t1, 8U); xsi_driver_first_trans_fast_port(t10); t1 = (t0 + 192568); *((int *)t1) = 1; LAB1: return; }
int main() { void *lib; void *lib_struct; // declaration for the external functions used void *(*init)(const char *); void (*free)(); uint64_t (*get_ahash)(void *, const char *); uint64_t (*get_dhash)(void *, const char *); uint64_t (*get_phash)(void *, const char *); //test image locations static const char image1PathStr[] = u8"../test_images/sample_01_"; static const char image2PathStr[] = u8"../test_images/sample_02_"; static const char image3PathStr[] = u8"../test_images/sample_03_"; static const char image4PathStr[] = u8"../test_images/sample_04_"; // Array of pointers to the base image paths to test //static const char *imagesSet[] = { image1PathStr, image2PathStr, image3PathStr }; static const char *imagesSet[] = { image1PathStr, image2PathStr, image3PathStr, image4PathStr }; static const int imageSetSize = 4; // designators for the image sizes static const char largeImageSizeStr[] = u8"large"; static const char mediumImageSizeStr[] = u8"medium"; static const char smallImageSizeStr[] = u8"small"; // Array of pointers to the images sizes static const char *imageSizesSet[] = { largeImageSizeStr, mediumImageSizeStr, smallImageSizeStr }; static int imageSizesSetSize = 3; // Image extension static const char imageExtensionStr[] = u8".jpg"; // Loading the external library lib = dlopen("./libpihash.so", RTLD_LAZY); //Registering the external functions *(void **)(&init) = dlsym(lib,"ext_init"); *(void **)(&free) = dlsym(lib,"ext_free"); *(void **)(&get_ahash) = dlsym(lib,"ext_get_ahash"); *(void **)(&get_dhash) = dlsym(lib,"ext_get_dhash"); *(void **)(&get_phash) = dlsym(lib,"ext_get_phash"); // Init the shared library lib_struct = init(u8"./.hash_cache"); //temp buffer for the path char *imagePathBuffer = malloc(100); // loop over the images and sizes to test for (int i = 0; i < imageSetSize; i++) { for (int j = 0; j < imageSizesSetSize; j++) { // Make sure the buffer is clean before using it memset(imagePathBuffer,0,100); // Getting the correct path strcat(imagePathBuffer, imagesSet[i]); strcat(imagePathBuffer, imageSizesSet[j]); strcat(imagePathBuffer, imageExtensionStr); //printf("Path: %s\n", imagePath); // Visually proving that the bytes stored are the correct representation //print_ustr_bytes(imagePath); printf("Image: %s\n",imagePathBuffer); // Printing information about the hashes of the provided images uint64_t imageAhash = get_ahash(lib_struct, imagePathBuffer); uint64_t imageDhash = get_dhash(lib_struct, imagePathBuffer); uint64_t imagePhash = get_phash(lib_struct, imagePathBuffer); printf("ahash: %llu \n", imageAhash); printf("dhash: %llu \n", imageDhash); printf("phash: %llu \n", imagePhash); } } //cleanup and close the buffer memset(imagePathBuffer,0,100); free(imagePathBuffer); // Closing the shared library reference if (lib != NULL ) dlclose(lib); return EXIT_SUCCESS; }
/* This function configures an extended boot record at the beginning of an * extended partition. This creates a logical partition and a pointer to * the next EBR. * * ext_lba == The start of the toplevel extended partition (pointed to by the * entry in the MBR). */ static struct write_list * mk_ext_pentry(struct disk_info *dinfo, struct part_info *pinfo, uint32_t *lba, uint32_t ext_lba, struct part_info *pnext) { struct write_list *item; struct pc_boot_record *ebr; uint32_t len; /* in lba units */ if (!(item = alloc_wl(sizeof(struct pc_boot_record)))) { ALOGE("Unable to allocate memory for EBR."); return NULL; } /* we are going to write the ebr at the current LBA, and then bump the * lba counter since that is where the logical data partition will start */ item->offset = (*lba) * dinfo->sect_size; (*lba)++; ebr = (struct pc_boot_record *) &item->data; memset(ebr, 0, sizeof(struct pc_boot_record)); ebr->mbr_sig = PC_BIOS_BOOT_SIG; if (pinfo->len_kb != (uint32_t)-1) len = kb_to_lba(pinfo->len_kb, dinfo->sect_size); else { if (pnext) { ALOGE("Only the last partition can be specified to fill the disk " "(name = '%s')", pinfo->name); goto fail; } len = dinfo->num_lba - *lba; /* update the pinfo structure to reflect the new size, for * bookkeeping */ pinfo->len_kb = (uint32_t)(((uint64_t)len * (uint64_t)dinfo->sect_size) / ((uint64_t)1024)); } cfg_pentry(&ebr->ptable[PC_EBR_LOGICAL_PART], PC_PART_NORMAL, pinfo->type, 1, len); pinfo->start_lba = *lba; *lba += len; /* If this is not the last partition, we have to create a link to the * next extended partition. * * Otherwise, there's nothing to do since the "pointer entry" is * already zero-filled. */ if (pnext) { /* The start lba for next partition is an offset from the beginning * of the top-level extended partition */ uint32_t next_start_lba = *lba - ext_lba; uint32_t next_len_lba; if (pnext->len_kb != (uint32_t)-1) next_len_lba = 1 + kb_to_lba(pnext->len_kb, dinfo->sect_size); else next_len_lba = dinfo->num_lba - *lba; cfg_pentry(&ebr->ptable[PC_EBR_NEXT_PTR_PART], PC_PART_NORMAL, PC_PART_TYPE_EXTENDED, next_start_lba, next_len_lba); } return item; fail: free_wl(item); return NULL; }
void Test_M2MResourceInstance::test_set_value() { u_int8_t value[] = {"value2"}; resource_instance->_value = (u_int8_t*)malloc(sizeof(u_int8_t)); m2mbase_stub::bool_value = true; CHECK(resource_instance->set_value(value,(u_int32_t)sizeof(value)) == true); CHECK( resource_instance->_value_length == sizeof(value)); CHECK( *resource_instance->_value == *value); m2mbase_stub::observe = (M2MObservationHandler*)handler; u_int8_t value2[] = {"12"}; CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true); u_int8_t value3[] = {"13"}; CHECK(resource_instance->set_value(value3,(u_int32_t)sizeof(value3)) == true); free(resource_instance->_value); resource_instance->_value_length = 0; CHECK(resource_instance->set_value(NULL,0) == false); CHECK(resource_instance->set_value(NULL,0) == false); m2mbase_stub::observation_level_value = M2MBase::R_Attribute; resource_instance->_value = (u_int8_t*)malloc(sizeof(value)+1); memset(resource_instance->_value,0,sizeof(value)+1); memcpy(resource_instance->_value,value,sizeof(value)); resource_instance->_value_length = sizeof(value); TestReportObserver obs; m2mbase_stub::report = new M2MReportHandler(obs); u_int8_t value4[] = {"value4"}; CHECK(resource_instance->set_value(value4,(u_int32_t)sizeof(value4)) == true); m2mbase_stub::base_type = M2MBase::ResourceInstance; m2mbase_stub::observation_level_value = M2MBase::O_Attribute; resource_instance->_resource_type = M2MResourceInstance::INTEGER; m2mbase_stub::mode_value = M2MBase::Dynamic; ResourceCallback *resource_cb = new ResourceCallback(); resource_instance->set_resource_observer(resource_cb); CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true); CHECK(resource_cb->visited == true); resource_cb->visited = false; m2mbase_stub::observation_level_value = M2MBase::R_Attribute; CHECK(resource_instance->set_value(value3,(u_int32_t)sizeof(value3)) == true); CHECK(resource_cb->visited == true); resource_instance->set_resource_observer(NULL); resource_cb->visited = false; m2mbase_stub::observation_level_value = M2MBase::R_Attribute; CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true); CHECK(resource_cb->visited == false); CHECK(resource_instance->set_value(value3,(u_int32_t)sizeof(value3)) == true); m2mbase_stub::observation_level_value = M2MBase::OI_Attribute; resource_instance->_resource_type = M2MResourceInstance::INTEGER; m2mbase_stub::mode_value = M2MBase::Dynamic; CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true); m2mbase_stub::observation_level_value = M2MBase::OOI_Attribute; resource_instance->_resource_type = M2MResourceInstance::INTEGER; m2mbase_stub::mode_value = M2MBase::Dynamic; CHECK(resource_instance->set_value(value2,(u_int32_t)sizeof(value2)) == true); delete m2mbase_stub::report; m2mbase_stub::report = NULL; delete resource_cb; }
struct write_list * config_mbr(struct disk_info *dinfo) { struct part_info *pinfo; uint32_t cur_lba = dinfo->skip_lba; uint32_t ext_lba = 0; struct write_list *wr_list = NULL; struct write_list *temp_wr = NULL; int cnt = 0; int extended = 0; if (!dinfo->part_lst) return NULL; for (cnt = 0; cnt < dinfo->num_parts; ++cnt) { pinfo = &dinfo->part_lst[cnt]; /* Should we create an extedned partition? */ if (cnt == (PC_NUM_BOOT_RECORD_PARTS - 1)) { if (cnt + 1 < dinfo->num_parts) { extended = 1; ext_lba = cur_lba; if ((temp_wr = mk_pri_pentry(dinfo, NULL, cnt, &cur_lba))) wlist_add(&wr_list, temp_wr); else { ALOGE("Cannot create primary extended partition."); goto fail; } } } /* if extended, need 1 lba for ebr */ if ((cur_lba + extended) >= dinfo->num_lba) goto nospace; else if (pinfo->len_kb != (uint32_t)-1) { uint32_t sz_lba = (pinfo->len_kb / dinfo->sect_size) * 1024; if ((cur_lba + sz_lba + extended) > dinfo->num_lba) goto nospace; } if (!extended) temp_wr = mk_pri_pentry(dinfo, pinfo, cnt, &cur_lba); else { struct part_info *pnext; pnext = cnt + 1 < dinfo->num_parts ? &dinfo->part_lst[cnt+1] : NULL; temp_wr = mk_ext_pentry(dinfo, pinfo, &cur_lba, ext_lba, pnext); } if (temp_wr) wlist_add(&wr_list, temp_wr); else { ALOGE("Cannot create partition %d (%s).", cnt, pinfo->name); goto fail; } } /* fill in the rest of the MBR with empty parts (if needed). */ for (; cnt < PC_NUM_BOOT_RECORD_PARTS; ++cnt) { struct part_info blank; cur_lba = 0; memset(&blank, 0, sizeof(struct part_info)); if (!(temp_wr = mk_pri_pentry(dinfo, &blank, cnt, &cur_lba))) { ALOGE("Cannot create blank partition %d.", cnt); goto fail; } wlist_add(&wr_list, temp_wr); } return wr_list; nospace: ALOGE("Not enough space to add parttion '%s'.", pinfo->name); fail: wlist_free(wr_list); return NULL; }
void Test_M2MResourceInstance::test_handle_put_request() { uint8_t value[] = {"name"}; sn_coap_hdr_s *coap_header = (sn_coap_hdr_s *)malloc(sizeof(sn_coap_hdr_s)); memset(coap_header, 0, sizeof(sn_coap_hdr_s)); coap_header->uri_path_ptr = value; coap_header->uri_path_len = sizeof(value); coap_header->msg_code = COAP_MSG_CODE_REQUEST_PUT; String *name = new String("name"); common_stub::int_value = 0; m2mbase_stub::string_value = name; m2mbase_stub::operation = M2MBase::PUT_ALLOWED; m2mbase_stub::uint8_value = 200; common_stub::coap_header = (sn_coap_hdr_ *)malloc(sizeof(sn_coap_hdr_)); memset(common_stub::coap_header,0,sizeof(sn_coap_hdr_)); coap_header->payload_ptr = (uint8_t*)malloc(1); coap_header->options_list_ptr = (sn_coap_options_list_s*)malloc(sizeof(sn_coap_options_list_s)); coap_header->options_list_ptr->uri_query_ptr = value; coap_header->options_list_ptr->uri_query_len = sizeof(value); coap_header->content_type_ptr = (uint8_t*)malloc(1); coap_header->content_type_len = 1; *coap_header->content_type_ptr = 99; m2mtlvdeserializer_stub::bool_value = true; m2mbase_stub::bool_value = false; sn_coap_hdr_s *coap_response = NULL; coap_response = resource_instance->handle_put_request(NULL,coap_header,handler); CHECK( coap_response != NULL); if(coap_response) { if(coap_response->content_type_ptr) { free(coap_response->content_type_ptr); coap_response->content_type_ptr = NULL; } } free(coap_header->options_list_ptr); coap_header->options_list_ptr = NULL; coap_response = resource_instance->handle_put_request(NULL,coap_header,handler); CHECK( coap_response != NULL); if(coap_response) { if(coap_response->content_type_ptr) { free(coap_response->content_type_ptr); coap_response->content_type_ptr = NULL; } } m2mtlvdeserializer_stub::bool_value = false; coap_response = resource_instance->handle_put_request(NULL,coap_header,handler); CHECK( coap_response != NULL); if(coap_response) { if(coap_response->content_type_ptr) { free(coap_response->content_type_ptr); coap_response->content_type_ptr = NULL; } } *coap_header->content_type_ptr = 100; coap_response = resource_instance->handle_put_request(NULL,coap_header,handler); CHECK( coap_response != NULL); if(coap_response) { if(coap_response->content_type_ptr) { free(coap_response->content_type_ptr); coap_response->content_type_ptr = NULL; } } m2mbase_stub::bool_value = true; coap_response = resource_instance->handle_put_request(NULL,coap_header,handler); CHECK( coap_response != NULL); if(coap_response) { if(coap_response->content_type_ptr) { free(coap_response->content_type_ptr); coap_response->content_type_ptr = NULL; } } m2mbase_stub::operation = M2MBase::NOT_ALLOWED; coap_response = resource_instance->handle_put_request(NULL,coap_header,handler); CHECK( coap_response != NULL); if(coap_response) { if(coap_response->content_type_ptr) { free(coap_response->content_type_ptr); coap_response->content_type_ptr = NULL; } } coap_response = resource_instance->handle_put_request(NULL,NULL,handler); CHECK( coap_response != NULL); if(coap_response) { if(coap_response->content_type_ptr) { free(coap_response->content_type_ptr); coap_response->content_type_ptr = NULL; } } free(coap_header->content_type_ptr); free(coap_header->options_list_ptr); free(coap_header->payload_ptr); free(common_stub::coap_header); delete name; free(coap_header); m2mtlvdeserializer_stub::clear(); common_stub::clear(); m2mbase_stub::clear(); }
/* * Return a socket bound to an appropriate port number/address. Exits * the program on failure. */ static int get_socket(int **sa, int *nsa) { char host[NI_MAXHOST], serv[NI_MAXHOST]; struct addrinfo hint, *res, *rp; u_long inaddr; int ecode, flag, kalive = 1, s; memset(&hint, 0, sizeof(struct addrinfo)); hint.ai_family = AF_UNSPEC; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = IPPROTO_TCP; hint.ai_flags = AI_PASSIVE; #ifdef AI_ADDRCONFIG hint.ai_flags |= AI_ADDRCONFIG; #endif if (bind_address) ecode = getaddrinfo(bind_address, portstr, &hint, &res); else ecode = getaddrinfo(NULL, portstr, &hint, &res); if (ecode != 0) { report(LOG_ERR, "getaddrinfo: %s\n", gai_strerror(ecode)); tac_exit(1); } *sa = NULL; *nsa = 0; for (rp = res; rp != NULL; rp = rp->ai_next) { s = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (s == -1) continue; if (1 || debug & DEBUG_PACKET_FLAG) report(LOG_DEBUG, "socket FD %d AF %d", s, rp->ai_family); flag = 1; if (rp->ai_family == AF_INET6) setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &flag, sizeof(flag)); #ifdef SO_REUSEADDR if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(flag)) < 0) perror("setsockopt - SO_REUSEADDR"); #endif if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&kalive, sizeof(kalive)) < 0) perror("setsockopt - SO_KEEPALIVE"); flag = 0; if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag)) < 0) perror("setsockopt - SO_NODELAY"); if (bind(s, rp->ai_addr, rp->ai_addrlen) < 0) { console = 1; ecode = errno; if (lookup_peer) flag = 0; else flag = NI_NUMERICHOST | NI_NUMERICSERV; if (getnameinfo(rp->ai_addr, rp->ai_addrlen, host, NI_MAXHOST, serv, NI_MAXHOST, flag)) { strncpy(host, "unknown", NI_MAXHOST - 1); host[NI_MAXHOST - 1] = '\0'; strncpy(serv, "unknown", NI_MAXHOST - 1); serv[NI_MAXHOST - 1] = '\0'; } report(LOG_ERR, "get_socket: bind %s:%s %s", host, serv, strerror(ecode)); console = 0; close(s); s = -1; continue; } if (*sa == NULL) *sa = malloc(sizeof(int) * ++(*nsa)); else *sa = realloc(*sa, sizeof(int) * ++(*nsa)); if (*sa == NULL) { report(LOG_ERR, "malloc failure: %s", strerror(errno)); tac_exit(1); } (*sa)[*nsa - 1] = s; } freeaddrinfo(res); if (*nsa < 1) { console = 1; report(LOG_ERR, "get_socket: could not bind a listening socket"); tac_exit(1); } return(0); }