/* incomming command string receives here */ char * htxd_receive_command(int new_fd) /* note: have to change for error handling */ { int result; char *command_details_buffer = NULL; char temp_buffer[20]; int command_length; char trace_string[256]; memset(temp_buffer, 0, sizeof(temp_buffer) ); /* receiving command length from incomming commend */ result = htxd_receive_bytes(new_fd, temp_buffer, 10); if(result == -1) { sprintf(trace_string, "htxd_receive_bytes returned -1"); HTXD_TRACE(LOG_ON, trace_string); return NULL; } temp_buffer[COMMAND_STRING_LENGTH] = '\0'; command_length = atoi(temp_buffer); /* now we are ready to receive the command string */ command_details_buffer = malloc(command_length + 10); if(command_details_buffer == NULL) { sprintf(trace_string, "malloc() failed while allocating command_details_buffer"); HTXD_TRACE(LOG_ON, trace_string) return NULL; }
/* incoming command string receives here */ char * htxd_receive_command(int new_fd) /* note: have to change for error handling */ { int result; char * command_details_buffer = NULL; char temp_buffer[20]; int command_length; memset(temp_buffer, 0, sizeof(temp_buffer) ); /* receiving command length from incoming commend */ result = htxd_receive_bytes(new_fd, temp_buffer, 10); if(result == -1) { return NULL; } temp_buffer[COMMAND_STRING_LENGTH] = '\0'; command_length = atoi(temp_buffer); /* now we are ready to receive the command string */ command_details_buffer = malloc(command_length + 10); if(command_details_buffer == NULL) { printf("[DEBUG] : malloc() failed while allocating command_details_buffer"); fflush(stdout); return NULL; } memset(command_details_buffer, 0, command_length + 10); /* receiving the command string */ result = htxd_receive_bytes(new_fd, command_details_buffer, command_length); if(result == -1) { return NULL; } command_details_buffer[command_length] = '\0'; return command_details_buffer; }
command_length = atoi(temp_buffer); /* now we are ready to receive the command string */ command_details_buffer = malloc(command_length + 10); if(command_details_buffer == NULL) { sprintf(trace_string, "malloc() failed while allocating command_details_buffer"); HTXD_TRACE(LOG_ON, trace_string) return NULL; } memset(command_details_buffer, 0, command_length + 10); /* receiving the command string */ result = htxd_receive_bytes(new_fd, command_details_buffer, command_length); if(result == -1) { sprintf(trace_string, "htxd_receive_command: htxd_receive_bytes returned with <%d>", result); HTXD_TRACE(LOG_ON, trace_string) return NULL; } command_details_buffer[command_length] = '\0'; return command_details_buffer; } /* send response to a client */