Guest User

Untitled

a guest
Apr 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. // Erica Sadun, 24 March 2008
  2. //
  3. // cc panda.c -w -lcurl -o panda
  4. //
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <sys/socket.h>
  9. #include <string.h>
  10. #include <netdb.h>
  11. #include <curl/curl.h>
  12.  
  13. #define ITMSSITE "phobos.apple.com"
  14. #define SLEN 4096
  15. #define MLEN 50000
  16.  
  17. main(argc, argv)
  18. int argc;
  19. char **argv;
  20. {
  21. char headertext[SLEN], mtext[MLEN];
  22. char *c;
  23. int riz, i;
  24.  
  25. if (argc < 2) {
  26. printf("usage: %s # | gunzip\n", argv[0]);
  27. printf("1: view panda updates\n");
  28. printf("2: top 50\n");
  29. printf("3: featured genres\n");
  30. printf("4: view panda storefront\n");
  31. printf("5: top tens\n");
  32. exit(0);
  33. }
  34.  
  35. int whichRequest = atoi(argv[1]);
  36. if ((whichRequest < 1) || (whichRequest > 5)) {
  37. printf("Error: request must be within 1-5\n");
  38. exit(-1);
  39. }
  40.  
  41. // Create Headers
  42.  
  43. if (whichRequest == 1)
  44. sprintf(headertext, "GET /WebObjects/MZStore.woa/wa/viewPandaUpdates HTTP/1.1\n");
  45. else if (whichRequest == 2)
  46. sprintf(headertext, "GET /WebObjects/MZStore.woa/wa/viewTopFifty HTTP/1.1\n");
  47. else if (whichRequest == 3)
  48. sprintf(headertext, "GET /WebObjects/MZStore.woa/wa/viewFeaturedGenres HTTP/1.1\n");
  49. else if (whichRequest == 4)
  50. sprintf(headertext, "GET /WebObjects/MZStore.woa/wa/pandaStoreFront HTTP/1.1\n");
  51. else if (whichRequest == 5)
  52. sprintf(headertext, "GET /WebObjects/MZStore.woa/wa/viewTopTensList HTTP/1.1\n");
  53.  
  54. #define IPHONE12 "iTunes-iPhone/1.2.0"
  55. sprintf(headertext, "%sUser-Agent: %s\n", headertext, IPHONE12);
  56.  
  57. sprintf(headertext, "%sAccept-Language: en-us, en;q=1.0\n", headertext);
  58. sprintf(headertext, "%sX-Apple-Store-Front: 143441-1,2\n", headertext);
  59. sprintf(headertext, "%sCookie: countryVerified=1\n", headertext);
  60. sprintf(headertext, "%sAccept-Encoding: gzip, x-aes-cbc\n", headertext);
  61. sprintf(headertext, "%sConnection: close\n", headertext);
  62. sprintf(headertext, "%sHost: phobos.apple.com\n", headertext);
  63.  
  64. sprintf(headertext, "%s\n", headertext);
  65.  
  66. // Send the message
  67. if ((riz = dosend(headertext, mtext)) == 0)
  68. {
  69. printf("Could not connect properly. Sorry.\n");
  70. exit(1);
  71. }
  72.  
  73. // skip header & output results
  74. for (i = 0; (!((mtext[i] == '\n') && (mtext[i+2] == '\n'))); i++) ;
  75. i += 3;
  76. for (i; i < riz; i++) printf("%c", mtext[i]);
  77. }
  78.  
  79. int dosend(s, mtext)
  80. char *s, *mtext;
  81. {
  82. struct hostent *hp;
  83. struct sockaddr_in sin;
  84. struct msghdr *msg;
  85. char buff[4096];
  86. int sd, i, offset;
  87. int ngot, flags;
  88.  
  89. if ((hp = gethostbyname(ITMSSITE)) == 0)
  90. {
  91. printf("Could not attach to host %s. Try again later.\n",
  92. ITMSSITE); exit(-1);
  93. }
  94.  
  95. /* Host Received */
  96. bzero(&sin, sizeof(sin));
  97. sin.sin_family = AF_INET;
  98. sin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
  99. sin.sin_port = htons(80);
  100. if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
  101. {
  102. printf("Socket failed\n"); exit(-1);
  103. }
  104.  
  105. /* Perform Connection */
  106. if (connect(sd, (const struct sockaddr *) &sin, sizeof(sin)) == -1)
  107. {printf("Connection Error\n"); close(sd); return 0;}
  108.  
  109. /* Send Request */
  110. if ((ngot = send(sd, s, strlen(s), 0)) < 0)
  111. {printf("Could not send msg\n"); return 0;}
  112.  
  113. /* Retrieve Results */
  114. sprintf(mtext, ""); offset = 0;
  115. while ((ngot = recv(sd, buff, 4096, 0)) > 0)
  116. {
  117. for (i = 0; i < ngot; i++) mtext[offset+i] = buff[i];
  118. offset += ngot;
  119. }
  120.  
  121. /* Tidy up */
  122. close(sd);
  123. return offset;
  124. }
Add Comment
Please, Sign In to add comment