Advertisement
BaSs_HaXoR

BLB C++ (SPRX Web Request)

Aug 7th, 2014
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.75 KB | None | 0 0
  1. /*Credits: BadLuckBrian
  2. http://www.nextgenupdate.com/forums/showthread.php?t=754367
  3. ==============================================================
  4. IN YOUR HEADER: #include "webFunctions.h"
  5. Now you will need to add the stub to your project so go in :
  6. Project -> Properties -> Linker
  7. Click on the arrow in 'Additional dependecies' and click on edit.
  8. Now add this
  9. Code:
  10. */
  11. $(SCE_PS3_ROOT)\target\ppu\lib\libhttp_stub.a
  12. $(SCE_PS3_ROOT)\target\ppu\lib\libhttp_util_stub.a
  13. $(SCE_PS3_ROOT)\target\ppu\lib\libnet_stub.a
  14. /*
  15. It should look like this: (Of course mine might look a bit different due to some other stuff that i added to my project)
  16. http://puu.sh/aIaB8/7ac6b1d1ac.png
  17.  
  18. Then you're ready to test it  !
  19. You can call it like this:
  20. Code:
  21. */
  22. /*
  23. char response[255];
  24. SendRequest("http://www.google.com/", response, 255);
  25. */
  26.  
  27. //Put this in your project as "webFunctions.h"
  28.  
  29. #include <string.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <cell/http.h>
  33. #include <netex/net.h>
  34.  
  35.  
  36.  
  37. #define HTTP_POOL_SIZE      (64 * 1024)
  38. #define HTTP_POOL_BUFFER 0x2110000            //change this to an address with a free size of 0x10000 bytes ! This one is for ghosts 1.14
  39. static char r_buffer[0x6000];  //MAX is 0x6000
  40.  
  41.  
  42. /*Some function remade due to them making the sprx freeze for some reasons, might fix eventually*/
  43.  
  44. void memCpy(void * destination, const void * source, size_t num){for(int i = 0; i < num; i++){ *((char*)destination+i) = *((char*)source+i); } }
  45. void memFree(char* ptr, int len){       for(int i=0;i < len; i++) { *(char*)(ptr+i) = 0x00;}}
  46. int strCmp(const char* str1, const char* str2)
  47. {
  48.         int diff = 0;
  49.  
  50.         if(*(str1) == 0x00 || *(str2) == 0x00) {return -1;}
  51.  
  52.      for(int i = 0; i < 0x600; i++)
  53.      {
  54.                  if(*(str1+i) == 0x00 || *(str2+i) == 0x00) {break;}
  55.                  if(*(str1+i) != *(str2+i)) {diff++;}
  56.      }
  57.  
  58.          return diff;
  59. }
  60. void SendRequest(char* url,  char* retBuffer, int bufMaxLen) //url = url to request ("http://www.google.com/")    | retBuffer = ptr where the answer will be written to  | bufMaxLen = Max length of the buffer
  61. {
  62.         if(bufMaxLen > 0x6000) {return;} //ERROR, bufMaxLen is TOO BIG
  63.  
  64.                 size_t numBuf = 0;
  65.                 CellHttpClientId client = 0;
  66.                 CellHttpTransId trans = 0;
  67.                 CellHttpUri uri;
  68.                 int ret;
  69.                 bool has_cl = true;
  70.                 uint64_t length = 0;
  71.                 uint64_t recvd;
  72.                 size_t poolSize = 0;
  73.                 void *uriPool = NULL;
  74.                         void *httpPool = NULL;
  75.                         const char *serverName;
  76.                         size_t localRecv = 0;
  77.  
  78.             serverName = url;  //set url
  79.                         memFree(r_buffer, bufMaxLen);
  80.  
  81.                         sys_net_initialize_network(); //init network
  82.  
  83.                         httpPool = (void*)HTTP_POOL_BUFFER; //address to: 0x10000 free bytes
  84.                         if (httpPool == NULL) { ret = -1; goto end; }
  85.  
  86.                         ret = cellHttpInit(httpPool, HTTP_POOL_SIZE);
  87.                         if (ret < 0) { goto end; }
  88.        
  89.                         ret = cellHttpCreateClient(&client);
  90.                         if (ret < 0) { goto end; }
  91.  
  92.                         ret = cellHttpUtilParseUri(NULL, serverName, NULL, 0, &poolSize);
  93.                         if (ret < 0) { goto end; }
  94.        
  95.                         char uriPoolAlloc[0x1024]; //allocate some space for the uri (a bit too much but eh)
  96.                         uriPool = uriPoolAlloc;
  97.                         if (NULL == uriPool) { goto end; } //fail
  98.        
  99.                         ret = cellHttpUtilParseUri(&uri, serverName, uriPool, poolSize, NULL);
  100.                         if (ret < 0) {memFree((char*)uriPool, sizeof(uriPool)); goto end; }  
  101.  
  102.                         ret = cellHttpCreateTransaction(&trans, client, CELL_HTTP_METHOD_GET, &uri);
  103.                         memFree((char*)uriPool, sizeof(uriPool));
  104.                         if (ret < 0) { goto end; }
  105.  
  106.                         ret = cellHttpSendRequest(trans, NULL, 0, NULL); //send it :D
  107.  
  108.                         {//make a new scope for the status
  109.                                 int code = 0;
  110.                                 ret = cellHttpResponseGetStatusCode(trans, &code);
  111.                                 if (ret < 0) { goto end; }
  112.                
  113.                         }//end of status scope
  114.  
  115.                         ret = cellHttpResponseGetContentLength(trans, &length);
  116.                         if (ret < 0) {
  117.                                 if (ret == CELL_HTTP_ERROR_NO_CONTENT_LENGTH) { has_cl = false;}
  118.                             else { goto end; }}
  119.                
  120.                         recvd = 0;
  121.  
  122.                         while ((!has_cl) || (recvd < length))
  123.                         {
  124.                                 ret = cellHttpRecvResponse(trans, r_buffer, bufMaxLen-1, &localRecv);
  125.                                 if (ret < 0) {goto end; } else if (localRecv == 0) break;
  126.                                 recvd += localRecv;
  127.                                 r_buffer[localRecv] = '\0'; //null terminate it
  128.                     }
  129.  
  130.                         ret = 0;
  131.  
  132.                         {for(int i = 0;i<bufMaxLen;i++){retBuffer[i] = r_buffer[i];}}  //OUTPUT
  133.  
  134.  
  135.  
  136.                         /* shutdown procedures */
  137.     end:
  138.         if (trans) {
  139.                 cellHttpDestroyTransaction(trans);
  140.                 trans = 0;
  141.         }
  142.  
  143.         if (client) {cellHttpDestroyClient(client);client = 0;}
  144.        
  145.  
  146.         cellHttpEnd();  //END OF HTTP
  147.  
  148.         if (httpPool) {  memFree((char*)httpPool, sizeof(httpPool)); httpPool = NULL;}
  149.  
  150.  
  151.         sys_net_finalize_network();
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement