BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, BYTE* buffer, size_t size) { int length; char* line; char* type; char* context; char *d1, *d2; char *beg, *end; char *name, *value; line = strtok_s((char*) buffer, "\r\n", &context); while (line) { length = strlen(line); if (length > 1) { beg = line; end = &line[length - 1]; if (beg[0] == '/') { freerdp_client_parse_rdp_file_option_ascii(file, line); goto next_line; /* FreeRDP option */ } d1 = strchr(line, ':'); if (!d1) goto next_line; /* not first delimiter */ type = &d1[1]; d2 = strchr(type, ':'); if (!d2) goto next_line; /* no second delimiter */ if ((d2 - d1) != 2) goto next_line; /* improper type length */ if (d2 == end) goto next_line; /* no value */ *d1 = 0; *d2 = 0; name = beg; value = &d2[1]; if (*type == 'i') { /* integer type */ freerdp_client_parse_rdp_file_integer_ascii(file, name, value); } else if (*type == 's') { /* string type */ freerdp_client_parse_rdp_file_string_ascii(file, name, value); } else if (*type == 'b') { /* binary type */ } } next_line: line = strtok_s(NULL, "\r\n", &context); } return TRUE; }
static BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, const BYTE* buffer, size_t size) { BOOL rc = FALSE; int index; int length; char* line; char* type; char* context; char* d1, *d2; char* beg; char* name, *value; char* copy = calloc(1, size + sizeof(BYTE)); if (!copy) return FALSE; memcpy(copy, buffer, size); index = 0; line = strtok_s(copy, "\r\n", &context); while (line) { length = (int) strlen(line); if (length > 1) { beg = line; if (!freerdp_client_parse_rdp_file_add_line_ascii(file, line, index)) return FALSE; if (beg[0] == '/') { if (!freerdp_client_parse_rdp_file_option_ascii(file, line, index)) return FALSE; goto next_line; /* FreeRDP option */ } d1 = strchr(line, ':'); if (!d1) goto next_line; /* not first delimiter */ type = &d1[1]; d2 = strchr(type, ':'); if (!d2) goto next_line; /* no second delimiter */ if ((d2 - d1) != 2) goto next_line; /* improper type length */ *d1 = 0; *d2 = 0; name = beg; value = &d2[1]; if (*type == 'i') { /* integer type */ if (!freerdp_client_parse_rdp_file_integer_ascii(file, name, value, index)) goto fail; } else if (*type == 's') { /* string type */ if (!freerdp_client_parse_rdp_file_string_ascii(file, name, value, index)) goto fail; } else if (*type == 'b') { /* binary type */ } } next_line: line = strtok_s(NULL, "\r\n", &context); index++; } rc = TRUE; fail: free(copy); return rc; }