| 2342 | } |
| 2343 | |
| 2344 | void* client_handler(void* arg) { |
| 2345 | int client_fd = *(int*)arg; |
| 2346 | char buffer[1024]; |
| 2347 | char *hextemp; |
| 2348 | int bytes_received; |
| 2349 | Tokenizer t; |
| 2350 | t.tokens = NULL; |
| 2351 | |
| 2352 | // Peek at the incoming data to determine its length |
| 2353 | bytes_received = recv(client_fd, buffer, sizeof(buffer) - 1, MSG_PEEK); |
| 2354 | if (bytes_received <= 0) { |
| 2355 | close(client_fd); |
| 2356 | pthread_exit(NULL); |
| 2357 | } |
| 2358 | |
| 2359 | |
| 2360 | char* newline = (char*) memchr(buffer, '\n', bytes_received); |
| 2361 | size_t line_length = newline ? (newline - buffer) + 1 : bytes_received; |
| 2362 | bytes_received = recv(client_fd, buffer, line_length, 0); |
| 2363 | if (bytes_received <= 0) { |
| 2364 | close(client_fd); |
| 2365 | pthread_exit(NULL); |
| 2366 | } |
| 2367 | |
| 2368 | // Process the received bytes here |
| 2369 | buffer[bytes_received] = '\0'; |
| 2370 | stringtokenizer(buffer, &t); |
| 2371 | if (t.n != 3) { |
| 2372 | printf("Invalid input format from client, tokens %i : %s\n",t.n, buffer); |
| 2373 | freetokenizer(&t); |
| 2374 | sendstr(client_fd,"400 Bad Request"); |
| 2375 | close(client_fd); |
| 2376 | pthread_exit(NULL); |
| 2377 | } |
| 2378 | |
| 2379 | if(!secp->ParsePublicKeyHex(t.tokens[0],OriginalPointsBSGS,OriginalPointsBSGScompressed)) { |
| 2380 | printf("Invalid publickey format from client %s\n",t.tokens[0]); |
| 2381 | freetokenizer(&t); |
| 2382 | sendstr(client_fd,"400 Bad Request"); |
| 2383 | close(client_fd); |
| 2384 | pthread_exit(NULL); |
| 2385 | } |
| 2386 | if(!(isValidHex(t.tokens[1]) && isValidHex(t.tokens[2]))) { |
| 2387 | printf("Invalid hexadecimal format from client %s:%s\n",t.tokens[1],t.tokens[2]); |
| 2388 | freetokenizer(&t); |
| 2389 | sendstr(client_fd,"400 Bad Request"); |
| 2390 | close(client_fd); |
| 2391 | pthread_exit(NULL); |
| 2392 | } |
| 2393 | |
| 2394 | n_range_start.SetBase16(t.tokens[1]); |
| 2395 | n_range_end.SetBase16(t.tokens[2]); |
| 2396 | |
| 2397 | freetokenizer(&t); |
| 2398 | |
| 2399 | BSGS_CURRENT.Set(&n_range_start); |
| 2400 | |
| 2401 | bool *threads_created; |
nothing calls this directly
no test coverage detected