void test_controller_create_str(void) { char *actual_str = NULL; const char *expected_str = "aaa"; create_str(&actual_str, strlen(expected_str)); TEST_ASSERT_EQUAL_STRING(expected_str, actual_str); free((void *)actual_str); }
extern void compress_lzw(FILE *orig, FILE *archf, unsigned int *orig_size, unsigned int *archf_size) { current_code_len = 8; dictionary_t *dict = create_dict(); string_t *str = create_str(); int i; for(i = 0; i < CHARS_NUM; i++) { assign(str, (char)i); add_to_dictionary(dict, str); } int prev_id, t, k = 7, code, bit; char c, prin_c = (char)0; fscanf(orig, "%c", &c); for(i = 0; (char)i != c; prev_id = ++i); rewind(orig); str->length = 0; while (!feof(orig)) { if (fscanf(orig, "%c", &c) <= 0) break; append(str, c); t = dict_str_id(dict, str); if (t == -1) { add_to_dictionary(dict, str); code = dict->code[prev_id]; for(i = dict->code_len[prev_id] - 1; i >= 0; i--) { bit = !!(code & (1 << i)); prin_c = prin_c | (bit << k); if (--k == -1) { fprintf(archf, "%c", prin_c); prin_c = (char)0; k = 7; ++*archf_size; } } assign(str, c); for(i = 0; (char)i != c; prev_id = ++i); } else prev_id = t; } if (k < 7) { fprintf(archf, "%c", prin_c); ++*archf_size; } printf("%d\n", dict->size); for(i = 256; i < dict->size; i++) printf("%s %d\n", dict->word[i], dict->word_len[i]); }
int main(void) { //struct t_parser parser; struct t_value *value; char *str; value = create_str("Foo bar"); str = value_to_s(value); printf("to_s: %s\n", str); return 0; }
int main(void) { libidmef_string_t *str1, *str2; create_str(&str1); assert(libidmef_string_clone(str1, &str2) == 0); assert(libidmef_string_compare(str1, str2) == 0); assert(libidmef_string_cat(str2, "won't match") >= 0); assert(libidmef_string_compare(str1, str2) != 0); libidmef_string_destroy(str1); libidmef_string_destroy(str2); exit(0); }
void main() { ListHead head; init(&head); FILE *stream; errno_t err; char a; err = fopen_s(&stream, "a.txt", "rb"); if (err == 0) { a = fgetc(stream); while (a != EOF) { add(&head, a); a = fgetc(stream); } add(&head, '\0'); char* utf8Str = create_str(&head); wchar_t* unicodeStr = convert2Unicode(utf8Str); writeFilterResult(unicodeStr); printf("size is %d\n", wcslen(unicodeStr)); } else { printf("not opened.\n"); } closeFile(stream); getchar(); }
void test_controller_attr_private_channel_name(void) { lagopus_result_t rc; controller_attr_t *attr = NULL; char *actual_channel_name = NULL; const char *expected_channel_name = ""; const char *set_channel_name1 = "channel_name"; char *set_channel_name2 = NULL; char *actual_set_channel_name1 = NULL; char *actual_set_channel_name2 = NULL; const char *expected_set_channel_name1 = set_channel_name1; const char *expected_set_channel_name2 = set_channel_name1; controller_initialize(); rc = controller_attr_create(&attr); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc); TEST_ASSERT_NOT_NULL_MESSAGE(attr, "attr_create() will create new controller"); // Normal case of getter { rc = controller_get_channel_name(attr, &actual_channel_name); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc); TEST_ASSERT_EQUAL_STRING(expected_channel_name, actual_channel_name); } // Abnormal case of getter { rc = controller_get_channel_name(NULL, &actual_channel_name); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc); rc = controller_get_channel_name(attr, NULL); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc); } // Normal case of setter { rc = controller_set_channel_name(attr, set_channel_name1); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc); rc = controller_get_channel_name(attr, &actual_set_channel_name1); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc); TEST_ASSERT_EQUAL_STRING(expected_set_channel_name1, actual_set_channel_name1); create_str(&set_channel_name2, DATASTORE_CHANNEL_FULLNAME_MAX + 1); rc = controller_set_channel_name(attr, set_channel_name2); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_TOO_LONG, rc); rc = controller_get_channel_name(attr, &actual_set_channel_name2); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, rc); TEST_ASSERT_EQUAL_STRING(expected_set_channel_name2, actual_set_channel_name2); } // Abnormal case of setter { rc = controller_set_channel_name(NULL, set_channel_name1); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc); rc = controller_set_channel_name(attr, NULL); TEST_ASSERT_EQUAL(LAGOPUS_RESULT_INVALID_ARGS, rc); } controller_attr_destroy(attr); free((void *)actual_channel_name); free((void *)set_channel_name2); free((void *)actual_set_channel_name1); free((void *)actual_set_channel_name2); controller_finalize(); }
int main(int argc, char **argv){ unsigned long* top_addr; unsigned long input_addr;//NOT pointer unsigned long* target_addr; unsigned long* input; unsigned int id; unsigned int size; unsigned long filesize; FILE *fp; int msize = 64;//hash size is 512bit=64byte //file open char *fname=(char* )malloc(strlen(argv[1])+1); strncpy(fname,argv[1],strlen(argv[1])+1); if((fp=fopen(fname,"rb")) == NULL){ fprintf(stderr,"Can't Open File\n"); exit(2); } //get filesize fseek(fp,0,SEEK_END); filesize=ftell(fp);//filesize[byte] printf("Filesize:%ld\n",filesize); fseek(fp,0,SEEK_SET); input = (unsigned long*)malloc(filesize); size=fread(input,sizeof(unsigned char),filesize,fp); //target addr setting target_addr = (unsigned long*)malloc(msize); //str1 setting cust5str_t* str1 = create_str(); char buf[9]; sprintf(buf,"%p",input); str1 -> top_addr = strtoul(buf,NULL,16); sprintf(buf,"%p",target_addr); str1 -> target_addr = strtoul(buf,NULL,16); str1 -> size = size; //debug printf("fp_addr:%p\n",fp); printf("input:%p\n",input); printf("size:%d\n",size); printf("buf:%s\n",buf); printf("contents of top_addr:%s\n",(char *)(str1->top_addr));//input file 1st 32bit printf("target_addr:%p\n",target_addr); //inline assembler int i = 0; int max = (int)size/4; int byte_num = size % 4; unsigned long zero = 0; unsigned long tmp = 0; unsigned long dummy1 = 0; unsigned long dummy2 = 0; unsigned long tmp1 = 0; unsigned long tmp2 = 0; unsigned long tmp3 = 0; unsigned long tmp4 = 0; unsigned long tmp5 = 0; unsigned long tmp6 = 0; unsigned long tmp7 = 0; unsigned long tmp8 = 0; unsigned long tmp9 = 0; unsigned long tmp10 = 0; unsigned long tmp11 = 0; unsigned long tmp12 = 0; unsigned long tmp13 = 0; unsigned long tmp14 = 0; unsigned long tmp15 = 0; unsigned long tmp16 = 0; /* //Initialize Keccak */ /* __asm__( */ /* "l.cust5 %0,%0,%0,0,0\n\t" */ /* : */ /* :"r"(tmp) */ /* : */ /* ); */ //Input for(i = 0; i <= max-1; i++){ input_addr = str1->top_addr + 4*i;//generate next input_addr if (i == 0){ __asm__( "l.lwz %0,0(%1)\n\t"//LOAD FROM input_addr to tmp "l.cust5 %2,%2,%2,0,0\n\t"//reset "l.cust5 %2,%0,%3,0,4\n\t" //start :"=r"(tmp) :"r"(input_addr),"r"(dummy1),"r"(dummy2) : ); printf("START:%d\t %08lx\n",i,tmp); } else if(i < max-1){
int main(int argc, char **argv){ unsigned long* top_addr; unsigned long input_addr;//NOT pointer unsigned long* target_addr; unsigned long* input; unsigned int id; unsigned int size; unsigned long filesize; FILE *fp; int msize = 64;//hash size is 512bit=64byte //file open char *fname=(char* )malloc(strlen(argv[1])+1); strncpy(fname,argv[1],strlen(argv[1])+1); if((fp=fopen(fname,"rb")) == NULL){ fprintf(stderr,"Can't Open File\n"); exit(2); } //get filesize fseek(fp,0,SEEK_END); filesize=ftell(fp);//filesize[byte] printf("Filesize:%ld\n",filesize); fseek(fp,0,SEEK_SET); input = (unsigned long*)malloc(filesize); size=fread(input,sizeof(unsigned char),filesize,fp); //target addr setting target_addr = (unsigned long*)malloc(msize); //str1 setting cust5str_t* str1 = create_str(); char buf[9]; sprintf(buf,"%p",input); str1 -> top_addr = strtoul(buf,NULL,16); sprintf(buf,"%p",target_addr); str1 -> target_addr = strtoul(buf,NULL,16); str1 -> size = size; strcpy((char*)target_addr,(char*)input); //debug printf("fp_addr:%p\n",fp); printf("input:%p\n",input); printf("size:%d\n",size); printf("buf:%s\n",buf); printf("contents of top_addr:%s\n",(char *)(str1->top_addr));//input file 1st 32bit printf("target_addr:%p\n",target_addr); //inline assembler int i = 0; int max = (int)size/4; unsigned long hash32 = 0; unsigned long tmp; input_addr = str1 -> top_addr;// input_addr set again //target_addr = target_addr -12;// target_addr set again //print hash printf("----------------------------------\n"); printf("SHA-3:KECCAK input\n"); printf("----------------------------------\n"); for(i=0;i<size/4;i++){ printf("%d:%08lx\n",i,(input_addr+4*i));//addr printf("%d:%s\n",i,(char*)(input_addr+4*i));//contents } //print hash printf("----------------------------------\n"); printf("SHA-3:KECCAK output 512bit hash...\n"); printf("----------------------------------\n"); for(i=0;i<16;i++){ printf("%d:%p\n",i,(target_addr+i));//addr printf("%d:%s\n",i,(char*)(target_addr+i));//content } printf("----------------------------------\n"); //file close fclose(fp); free(input); free(target_addr); destroy_str(str1); }
int main(int argc, char **argv){ unsigned long* top_addr; unsigned long input_addr;//NOT pointer unsigned long* target_addr; unsigned long* input; unsigned int id; unsigned int size; unsigned long filesize; FILE *fp; int msize = 64;//hash size is 512bit=64byte //file open char *fname=(char* )malloc(strlen(argv[1])+1); strncpy(fname,argv[1],strlen(argv[1])+1); if((fp=fopen(fname,"rb")) == NULL){ fprintf(stderr,"Can't Open File\n"); exit(2); } //get filesize fseek(fp,0,SEEK_END); filesize=ftell(fp);//filesize[byte] printf("Filesize:%ld\n",filesize); fseek(fp,0,SEEK_SET); input = (unsigned long*)malloc(filesize); size=fread(input,sizeof(unsigned char),filesize,fp); //target addr setting target_addr = (unsigned long*)malloc(msize); //str1 setting cust5str_t* str1 = create_str(); char buf[9]; sprintf(buf,"%p",input); str1 -> top_addr = strtoul(buf,NULL,16); sprintf(buf,"%p",target_addr); str1 -> target_addr = strtoul(buf,NULL,16); str1 -> size = size; //debug printf("fp_addr:%p\n",fp); printf("input:%p\n",input); printf("size:%d\n",size); printf("buf:%s\n",buf); printf("contents of top_addr:%s\n",(char *)(str1->top_addr));//input file 1st 32bit printf("target_addr:%p\n",target_addr); //inline assembler int i = 0; int max = (int)size/4; int byte_num = size % 4;//.txt file has unsigned long hash32 = 0; unsigned long tmp = 0; unsigned long dummy1 = 0; unsigned long dummy2 = 0; unsigned long tmp1 = 0; unsigned long tmp2 = 0; unsigned long tmp3 = 0; unsigned long tmp4 = 0; unsigned long tmp5 = 0; unsigned long tmp6 = 0; unsigned long tmp7 = 0; unsigned long tmp8 = 0; unsigned long tmp9 = 0; unsigned long tmp10 = 0; unsigned long tmp11 = 0; unsigned long tmp12 = 0; unsigned long tmp13 = 0; unsigned long tmp14 = 0; unsigned long tmp15 = 0; unsigned long tmp16 = 0; unsigned long reg1 = 0; unsigned long reg2 = 0; unsigned long reg3 = 0; unsigned long reg4 = 0; //Initialize Keccak /* __asm__( */ /* "l.cust5 %0,%0,%0,0,0\n\t" */ /* : */ /* :"r"(tmp) */ /* : */ /* ); */ printf("Initialize Keccak\n"); //Input input_addr = str1 -> top_addr; __asm__( "l.lwz %0,0(%4)\n\t" "l.lwz %1,4(%4)\n\t" "l.lwz %2,8(%4)\n\t" "l.lwz %3,12(%4)\n\t" "l.cust5 %5,%5,%5,0,0\n\t" "l.cust5 %5,%0,%6,%7,4\n\t" "l.cust5 %5,%1,%6,0,2\n\t" "l.cust5 %5,%2,%6,0,2\n\t" "l.cust5 %5,%3,%6,0,1\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" :"=r"(reg1),"=r"(reg2),"=r"(reg3),"=r"(reg4) :"r"(input_addr),"r"(dummy1),"r"(dummy2),"i"(byte_num) : ); // printf("reg1:%08lx\n",reg1); //printf("reg2:%08lx\n",reg2); //printf("reg3:%08lx\n",reg3); //printf("reg4:%08lx\n",reg4); /* for(i = 0; i <= max-1; i++){ */ /* input_addr = str1->top_addr + 4*i;//generate next input_addr */ /* if (i == 0){ */ /* __asm__( */ /* "l.lwz %0,0(%1)\n\t"//LOAD FROM input_addr to tmp */ /* "l.cust5 %2,%0,%3,0,4\n\t" //start */ /* :"=r"(tmp) */ /* :"r"(input_addr),"r"(dummy1),"r"(dummy2) */ /* : */ /* ); printf("START:%d\t %08lx\n",i,tmp); */ /* } */ /* else if(i < max-1){ */ /* __asm__( */ /* "l.lwz %0,0(%1)\n\t"//LOAD FROM input_addr to tmp */ /* "l.cust5 %2,%0,%3,0,2\n\t" //middle */ /* :"=r"(tmp) */ /* :"r"(input_addr),"r"(dummy1),"r"(dummy2) */ /* : */ /* ); printf("MIDDLE:%d\t %08lx\n",i,tmp); */ /* } */ /* else if(i == max-1){ */ /* __asm__( */ /* "l.lwz %0,0(%1)\n\t"//LOAD FROM input_addr to tmp */ /* "l.cust5 %2,%0,%3,0,1\n\t" //end */ /* :"=r"(tmp) */ /* :"r"(input_addr),"r"(dummy1),"r"(dummy2) */ /* : */ /* ); printf("END:%d\t %08lx\n",i,tmp); */ /* } */ /* }//End of "for" loop */ // sleep(10); /* //devide ; output ;rotate */ /* //l.cust5 hash32 XX,XX, hash_num,storemode */ /* //l.sw 0,target_addr,hash32,0; */ __asm__( "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %1,%18,%19,15,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %2,%18,%18, 14,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %3,%18,%18, 13,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %4,%18,%18, 12,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %5,%18,%18, 11,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %6,%18,%18, 10,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %7,%18,%18, 9,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %8,%18,%18, 8,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %9,%18,%18, 7,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %10,%18,%18, 6,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %11,%18,%18, 5,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %12,%18,%18, 4,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %13,%18,%18, 3,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %14,%18,%18, 2,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %15,%18,%18, 1,8\n\t" "l.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\tl.nop \n\t" "l.cust5 %16,%18,%18, 0,8\n\t" "l.sw 0(%17),%1\n\t" "l.sw 4(%17),%2\n\t" "l.sw 8(%17),%3\n\t" "l.sw 12(%17),%4\n\t" "l.sw 16(%17),%5\n\t" "l.sw 20(%17),%6\n\t" "l.sw 24(%17),%7\n\t" "l.sw 28(%17),%8\n\t" "l.sw 32(%17),%9\n\t" "l.sw 36(%17),%10\n\t" "l.sw 40(%17),%11\n\t" "l.sw 44(%17),%12\n\t" "l.sw 48(%17),%13\n\t" "l.sw 52(%17),%14\n\t" "l.sw 56(%17),%15\n\t" "l.sw 60(%17),%16\n\t" :"=r"(hash32),"=r"(tmp1),"=r"(tmp2),"=r"(tmp3),"=r"(tmp4),"=r"(tmp5),"=r"(tmp6),"=r"(tmp7),"=r"(tmp8),"=r"(tmp9),"=r"(tmp10),"=r"(tmp11),"=r"(tmp12),"=r"(tmp13),"=r"(tmp14),"=r"(tmp15),"=r"(tmp16) :"r"(target_addr),"r"(dummy1),"r"(dummy2) ://"memory" ); printf("tmp1:%08lx\n",tmp1); printf("tmp2:%08lx\n",tmp2); printf("tmp3:%08lx\n",tmp3); printf("tmp4:%08lx\n",tmp4); printf("tmp5:%08lx\n",tmp5); printf("tmp6:%08lx\n",tmp6); printf("tmp7:%08lx\n",tmp7); printf("tmp8:%08lx\n",tmp8); printf("tmp9:%08lx\n",tmp9); printf("tmp10:%08lx\n",tmp10); printf("tmp11:%08lx\n",tmp11); printf("tmp12:%08lx\n",tmp12); printf("tmp13:%08lx\n",tmp13); printf("tmp14:%08lx\n",tmp14); printf("tmp15:%08lx\n",tmp15); printf("tmp16:%08lx\n",tmp16); //test input_addr = str1 -> top_addr;// input_addr set again //target_addr = target_addr -12;// target_addr set again //print hash printf("----------------------------------\n"); printf("SHA-3:KECCAK input\n"); printf("----------------------------------\n"); for(i=0;i<size/4;i++){ printf("%d:%08lx\n",i,(input_addr+4*i));//addr printf("%d:%s\n",i,(char*)(input_addr+4*i));//contents } //print hash printf("----------------------------------\n"); printf("SHA-3:KECCAK output 512bit hash...\n"); printf("----------------------------------\n"); for(i=0;i<16;i++){ printf("%d:\t%p %08lx\n",i,(target_addr+i),*(target_addr+i));//addr & contents } printf("----------------------------------\n"); //file close fclose(fp); free(input); free(target_addr); destroy_str(str1); }
uint32_t handle_PATCH( int fd, phttp_request phr ) { uint32_t retval = 0; uint32_t length = 0; uint8_t *file = NULL; uint32_t urllen = 0; pstr of = NULL; uint8_t *out = NULL; pstr response = NULL; pstr outdata = NULL; uint32_t start = 0; if ( phr == NULL ) { goto end; } if ( phr->root == NULL ) { DEBUG_PRINT("[ERROR] No root directory.\n"); goto end; } if ( phr->url == NULL ) { goto end; } if ( phr->content_data == NULL ) { goto end; } if ( phr->content_length == NULL ) { goto end; } outdata = malloc( sizeof(str) ); if ( outdata == NULL ) { goto end; } if ( phr->url[0] == '/' && ( phr->url[1] == ' ' || phr->url[1] == '\x00') ) { phr->url = (uint8_t*)"/index.html"; } while ( phr->root[length] != 0 ) { length++; } while ( phr->url[urllen] != 0x00 ) { urllen++; } // The + two is for the possibility of adding a '/' // plus the final null byte file = (uint8_t*)malloc( length + urllen + 2 ); if ( file == NULL ) { goto end; } memset( file, 0x00, length + urllen + 2); if ( memcmp( phr->url, "/index.html", urllen ) != 0 #ifndef VONE && memcmp( phr->url, "/index.ydg", urllen ) != 0 #endif ) { send_error( fd, 415); goto end; } // Copy the root directory memcpy( file, phr->root, length ); // check for starting '/' if (phr->url[0] != '/' ) { file[length] = '/'; length++; } memcpy( file + length, phr->url, urllen ); of = read_file( file ); if ( of == NULL ) { send_error( fd, 404 ); goto end; } start = 0; if ( phr->xoffset != NULL ) { start = catoi( phr->xoffset ); } urllen = catoi( phr->content_length ); if ( start + urllen > of->max ) { urllen += start; } else { urllen = of->max; } out = alloca( urllen ); outdata = init_str( outdata, out, urllen ); if ( outdata == NULL ) { goto end; } // Write the initial data if ( overwrite_data( outdata, of->str, 0, of->max ) == 0 ) { goto end; } if ( overwrite_data( outdata, phr->content_data, start, catoi(phr->content_length)) == 0 ) { send_error( fd, 400 ); goto end; } if ( write_file( outdata, file ) == 0 ) { send_error( fd, 400 ); goto end; } response = create_str( (uint8_t*)"HTTP/1.1 200 OK\r\n" ); if ( response == NULL ) { DEBUG_PRINT("[ERROR] Failed to initialize response string\n"); goto end; } AddConnection( response, 0 ); AddServer( response ); AddSetCookie( response ); if ( append_str( response, (uint8_t*)"\r\n" ) == 0 ) { DEBUG_PRINT("[ERROR] Failed to append crlf crlf\n"); goto end; } send( fd, response->str, response->max, 0 ); retval = 1; end: if ( outdata ) { free(outdata); } if ( file ) { free( file ); file = NULL; } if ( of ) { free_str( of ); } if ( response ) { free_str( response ); } return retval; }