-lhttp_util_stub -lhttp_stub
#include <cell/http.h>
#define BUFFER_SIZE 256
#define HTTP_POOL_SIZE (8 * 1024)
#define MALLOC(size) malloc(size)
#define FREE(ptr) free(ptr); ptr = NULL;
#define REQUEST_URI "http://www.bombsomedodongos.com/covers/"
#define REQUEST_URI_3D "http://www.bombsomedodongos.com/covers/3d/"
static char httpbuffer[BUFFER_SIZE];
int fd;
CellHttpClientId client = 0;
CellHttpTransId trans = 0;
CellHttpUri uri;
CellHttpUri uripath;
int ret;
bool has_cl = true;
uint64_t length = 0;
uint64_t recvd;
size_t poolSize = 0;
void *uriPool;
void *httpPool;
char* serverName;
size_t localRecv = 0;
char tmp[256];
char tmp2[100];
char path[256];
memset(tmp, 0, 256);
memset(httpbuffer, 0x00, sizeof(httpbuffer));
if(use_3dcovers == 0)
{
serverName = REQUEST_URI;
}
else
{
serverName = REQUEST_URI_3D;
}
httpPool = malloc(HTTP_POOL_SIZE);
char rdr[256];
if(use_3dcovers == 0)
{
sprintf(path, "/dev_hdd0/game/OMAN46756/covers/%s.PNG",menu_list[game_sel].title_id);
}
else
{
sprintf(path, "/dev_hdd0/game/OMAN46756/covers/3d/%s.PNG",menu_list[game_sel].title_id);
}
ret = cellHttpInit(httpPool, HTTP_POOL_SIZE);
ret = cellHttpCreateClient(&client);
ret = cellHttpUtilParseUri(NULL, serverName, NULL, 0, &poolSize);
uriPool = MALLOC(poolSize);
cellHttpUtilParseUri(&uri, serverName, uriPool, poolSize, NULL);
if(use_3dcovers == 0)
{
sprintf(rdr, "http://www.bombsomedodongos.com/covers/%s.PNG",menu_list[game_sel].title_id);
}
else
{
sprintf(rdr, "http://www.bombsomedodongos.com/covers/3d/%s.PNG",menu_list[game_sel].title_id);
}
ret = cellHttpUtilParseUri(NULL, rdr, NULL, 0, &poolSize);
uriPool = MALLOC(poolSize);
sprintf(rdr, "%s.PNG", menu_list[game_sel].title_id);
cellHttpUtilMergeUriPath(&uripath, &uri, rdr, uriPool, poolSize, NULL);
ret = cellHttpCreateTransaction(&trans, client, CELL_HTTP_METHOD_GET, &uripath);
if ( 0 > ret )
{
}
ret = cellHttpSendRequest(trans, NULL, 0, NULL);
if ( 0 > ret )
{
}
int code = 0;
ret = cellHttpResponseGetStatusCode(trans, &code);
{
}
ret = cellHttpResponseGetContentLength(trans, &length);
if (0 > ret) {
if (ret == CELL_HTTP_ERROR_NO_CONTENT_LENGTH) {
has_cl = false;
} else {
ret = -1;
}
}
recvd = 0;
if(code == 200)
{
dialog_ret=0;
ret = cellMsgDialogOpen2( type_dialog_yes_no, "Cover image was found, do you want to download it?", dialog_fun1, (void*)0x0000aaaa, NULL );
wait_dialog();
if(dialog_ret==1){
cellFsOpen(path, CELL_FS_O_CREAT|CELL_FS_O_RDWR, &fd, NULL, 0);
while ((!has_cl) || (recvd < length))
{
ret = cellHttpRecvResponse(trans, httpbuffer, BUFFER_SIZE-1, &localRecv);
if (0 > ret) {
printf("error receiving body... (0x%x)\n\n", ret);
ret = -1;
goto end;
} else if (localRecv == 0) break;
recvd += localRecv;
httpbuffer[localRecv] = '\0';
cellFsWrite(fd, (const void *)httpbuffer, localRecv, NULL);
}
cellFsClose(fd);
cellFsChmod(path, 0666);
}
}
else
{
sprintf(filename, "Encountered a problem while fetching cover\nHTTP error code %d", code);
dialog_ret=0;
ret = cellMsgDialogOpen2( type_dialog_ok, filename, dialog_fun2, (void*)0x0000aaab, NULL );
wait_dialog();
}
end:
cellHttpDestroyTransaction(trans);
cellHttpDestroyClient(client);
client = 0;
cellHttpEnd();
free(httpPool);
free(uriPool);
did_l1 = 0;
// load_covers reloads current displayed cover so that we refresh after download
load_covers();