testserver.c 722 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <scgi.h>
  2. static void callback(scgi_socket_t server_sock, scgi_socket_t *client_sock, struct sockaddr_in *addr)
  3. {
  4. scgi_handle_t handle = { 0 };
  5. if (scgi_parse(*client_sock, &handle) == SCGI_SUCCESS) {
  6. scgi_param_t *pp;
  7. *client_sock = SCGI_SOCK_INVALID;
  8. for(pp = handle.params; pp; pp = pp->next) {
  9. printf("HEADER: [%s] VALUE: [%s]\n", pp->name, pp->value);
  10. }
  11. if (handle.body) {
  12. printf("\n\nBODY:\n%s\n\n", handle.body);
  13. }
  14. scgi_disconnect(&handle);
  15. }
  16. }
  17. int main(int argc, char *argv[])
  18. {
  19. char *ip;
  20. int port = 0;
  21. if (argc < 2) {
  22. fprintf(stderr, "usage: testserver <ip> <port>\n");
  23. exit(-1);
  24. }
  25. ip = argv[1];
  26. port = atoi(argv[2]);
  27. scgi_listen(ip, port, callback);
  28. }