WebGet & WebPost Utilities
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

webget.c 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @PROJECT WebGet Downloader
  3. * @COPYRIGHT See COPYING in the top level directory
  4. * @FILE webget.c
  5. * @PURPOSE Web To StdOut Downloader
  6. * @DEVELOPERS Al Globus <globus@nas.nasa.gov>
  7. * Rafal Kupiec <belliash@asiotec.eu.org>
  8. * Jef Poskanzer <jef@mail.acme.com>
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <signal.h>
  13. #include "libweb.h"
  14. int main(int argc, char** argv) {
  15. int argn;
  16. char* referer;
  17. char* user_agent;
  18. char* auth_token;
  19. int ncookies;
  20. char* cookies[MAX_COOKIES];
  21. char* header_name;
  22. char* header_value;
  23. int status;
  24. argv0 = argv[0];
  25. argn = 1;
  26. timeout = 60;
  27. referer = (char*) 0;
  28. user_agent = "http_get";
  29. auth_token = (char*) 0;
  30. ncookies = 0;
  31. header_name = (char*) 0;
  32. header_value = (char*) 0;
  33. verbose = 0;
  34. while(argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
  35. if(strcmp(argv[argn], "-t") == 0 && argn + 1 < argc) {
  36. ++argn;
  37. timeout = atoi(argv[argn]);
  38. } else if(strcmp(argv[argn], "-r") == 0 && argn + 1 < argc) {
  39. ++argn;
  40. referer = argv[argn];
  41. } else if(strcmp(argv[argn], "-u") == 0 && argn + 1 < argc) {
  42. ++argn;
  43. user_agent = argv[argn];
  44. } else if(strcmp(argv[argn], "-a") == 0 && argn + 1 < argc) {
  45. ++argn;
  46. auth_token = argv[argn];
  47. } else if(strcmp(argv[argn], "-c") == 0 && argn + 1 < argc) {
  48. if(ncookies >= MAX_COOKIES) {
  49. (void) fprintf(stderr, "%s: too many cookies\n", argv0);
  50. exit (1);
  51. }
  52. ++argn;
  53. cookies[ncookies++] = argv[argn];
  54. } else if(strcmp(argv[argn], "-h") == 0 && argn + 2 < argc) {
  55. ++argn;
  56. header_name = argv[argn];
  57. ++argn;
  58. header_value = argv[argn];
  59. } else if(strcmp(argv[argn], "-v") == 0) {
  60. verbose = 1;
  61. } else {
  62. usage();
  63. }
  64. ++argn;
  65. }
  66. if(argn >= argc) {
  67. usage();
  68. }
  69. url = argv[argn];
  70. ++argn;
  71. if(argn != argc) {
  72. usage();
  73. }
  74. (void) signal(SIGALRM, sigcatch);
  75. status = getURL(url, referer, user_agent, auth_token, ncookies, cookies, header_name, header_value);
  76. if(status == 200) {
  77. exit(0);
  78. } else if(status == 0) {
  79. exit(1);
  80. } else {
  81. exit(status);
  82. }
  83. }