lib556.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id$
  9. */
  10. #include "test.h"
  11. int test(char *URL)
  12. {
  13. CURLcode res;
  14. CURL *curl;
  15. if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  16. fprintf(stderr, "curl_global_init() failed\n");
  17. return TEST_ERR_MAJOR_BAD;
  18. }
  19. if ((curl = curl_easy_init()) == NULL) {
  20. fprintf(stderr, "curl_easy_init() failed\n");
  21. curl_global_cleanup();
  22. return TEST_ERR_MAJOR_BAD;
  23. }
  24. curl_easy_setopt(curl, CURLOPT_URL, URL);
  25. curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
  26. res = curl_easy_perform(curl);
  27. if(!res) {
  28. /* we are connected, now get a HTTP document the raw way */
  29. const char *request = "GET /556 HTTP/1.2\r\n"
  30. "Host: ninja\r\n\r\n";
  31. size_t iolen;
  32. char buf[1024];
  33. res = curl_easy_send(curl, request, strlen(request), &iolen);
  34. if(!res) {
  35. /* we assume that sending always work */
  36. int total=0;
  37. do {
  38. /* busy-read like crazy */
  39. res = curl_easy_recv(curl, buf, 1024, &iolen);
  40. if(iolen)
  41. /* send received stuff to stdout */
  42. write(STDOUT_FILENO, buf, iolen);
  43. total += iolen;
  44. } while(((res == CURLE_OK) || (res == CURLE_AGAIN)) && (total < 129));
  45. }
  46. }
  47. curl_easy_cleanup(curl);
  48. curl_global_cleanup();
  49. return (int)res;
  50. }