diff --git a/lib/marshal/marshal.c b/lib/marshal/marshal.c index 54b04ca..3fc2727 100644 --- a/lib/marshal/marshal.c +++ b/lib/marshal/marshal.c @@ -1,4 +1,3 @@ - /* * @desc: The function does the marshing. Function does all the allocation. * It is caller's responsibility to free the memory allocated. @@ -56,6 +55,7 @@ gwkv_marshal_server(struct operation* data, int status, char** ascii) strcat(val,data->value); //. strcat(val,b3); //\r\n. strcat(val,b4); //END \r\n. + kvprintf("[!] server marshaling GET"); break; } *ascii = val; @@ -162,22 +162,16 @@ gwkv_marshal_client(struct operation* data, char** ascii) int gwkv_demarshal_server(char* ascii, struct operation** op) { - /*switch(data->method_type) { - case SET: - //convert ascii to operation - case GET: - //convert ascii to operation + /* SET: convert ascii to operation + GET: convert ascii to operation }*/ - //char s0[] = "VALUE"; char* traverse = ascii; struct operation *data = (struct operation*)malloc(sizeof(struct operation)); char s1[] = "set"; char s2[] = "get"; - /*if (strcmp(ascii, s0) >= strlen(s0)) { - - } else*/ if ( 0 == strncmp(ascii, s1, strlen(s1))) { + kvprintf("[!] server demarshal SET: %s\n", ascii); data->method_type = SET; traverse += strlen(s1) + 1; @@ -210,19 +204,11 @@ gwkv_demarshal_server(char* ascii, struct operation** op) assert(0); } - traverse = temp;//pointing to \r\n. + traverse = temp + 1;//pointing to \r\n. - /*temp = strchr(traverse, ' '); - if (NULL != temp) { - traverse = temp + 1; - assert(traverse[0] == '\r'); - assert(traverse[1] == '\n'); - } else { - assert(0); - }*/ - assert(traverse[1] == '\n'); + assert(traverse[0] == '\n'); - traverse += 2; // pointing to data + traverse += 1; // pointing to data temp = strchr(traverse, '\r'); if ( NULL != temp) { @@ -240,6 +226,8 @@ gwkv_demarshal_server(char* ascii, struct operation** op) } else if (0 == strncmp(ascii, s2, strlen(s2))) { + + kvprintf("[!] server demarshal GET: %s\n", ascii); data->method_type = GET; traverse += strlen(s2) + 1;//pointing key char* temp = strchr(traverse, '\r'); @@ -270,27 +258,34 @@ gwkv_demarshal_client(char* ascii, struct operation** op, int* status) char s1[]="NOT_STORED\r\n"; char s2[]="EXISTS\r\n"; char s3[]="NOT_FOUND\r\n"; + if(strcmp(ascii,s0)==0){ + kvprintf("[!] client demarshal SET: %s\n", ascii); data->method_type=SET; *status=0; return 0; } else if(strcmp(ascii,s1)==0){ + kvprintf("[!] client demarshal SET: %s\n", ascii); data->method_type=SET; *status=1; return 0; } else if(strcmp(ascii,s2)==0){ + kvprintf("[!] client demarshal SET: %s\n", ascii); data->method_type=SET; *status=2; return 0; } else if(strcmp(ascii,s3)==0){ + kvprintf("[!] client demarshal SET: %s\n", ascii); data->method_type=SET; *status=3; return 0; } + kvprintf("[!] client demarshal GET: %s\n", ascii); + char *value = "VALUE"; char* traverse = ascii; if( 0 != strncmp(traverse, value, strlen(value))) { @@ -329,68 +324,4 @@ gwkv_demarshal_client(char* ascii, struct operation** op, int* status) strncpy(data->value, traverse, data->value_length); } return 0; - -/* - int i=0; - int offset = 0; - char *a=ascii; - i=0; - char b[50]; - while(a[i]!=' ' && a[i]!='\0'){ - b[i]=a[i]; - i++; - } - b[i]='\0'; - - offset += i+1; - char c1[]="VALUE"; - if(strcmp(b,c1)!=0){ - return -1; - } - data->method_type = GET; - - //key - a = ascii + offset; - i=0; - - while(a[i]!=' '&& a[i]!='\0'){ - b[i]=a[i]; - i++; - } - b[i]='\0'; - offset += i+1; - data->key_length = i + 1; - data->key = malloc(data->key_length); - strcpy(data->key, b); - - //flag - i=0; - while(b[i]!=' '&&b[i]!='\0'){ - b[i]=a[i]; - i++; - } - b[i]='\0'; - offset += i+1; - //length - i=0; - while(b[i]!=' '&&b[i]!='\0'){ - b[i]=a[i]; - i++; - } - b[i]='\0'; - offset += i+1; - data->value_length = atoi(b); - //\r\n - offset += 2; - //data_value - i=0; - while(b[i]!='\r'&&b[i]!='\0'){ - b[i]=a[i]; - i++; - } - b[i]='\0'; - offset += i+1; - char *b2 = (char*)malloc(50*sizeof(char)); - strcat(b2,b); - data->value = b1;*/ }