HTTPC : added support for a handful of http:C commands. example will follow.
This commit is contained in:
parent
a18cc37dfa
commit
c4382042d6
13
libctru/include/ctr/HTTPC.h
Normal file
13
libctru/include/ctr/HTTPC.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef HTTPC_H
|
||||
#define HTTPC_H
|
||||
|
||||
Result HTTPC_Initialize(Handle handle);
|
||||
Result HTTPC_InitializeConnectionSession(Handle handle, Handle contextHandle);
|
||||
Result HTTPC_CreateContext(Handle handle, char* url, Handle* contextHandle);
|
||||
Result HTTPC_CloseContext(Handle handle, Handle contextHandle);
|
||||
Result HTTPC_SetProxyDefault(Handle handle, Handle contextHandle);
|
||||
Result HTTPC_AddRequestHeaderField(Handle handle, Handle contextHandle, char* name, char* value);
|
||||
Result HTTPC_BeginRequest(Handle handle, Handle contextHandle);
|
||||
Result HTTPC_ReceiveData(Handle handle, Handle contextHandle, u8* buffer, u32 size);
|
||||
|
||||
#endif
|
@ -275,7 +275,7 @@ Result GSPGPU_submitGxCommand(u32* sharedGspCmdBuf, u32 gxCommand[0x8], Handle*
|
||||
u8 commandIndex=cmdBufHeader&0xFF;
|
||||
u8 totalCommands=(cmdBufHeader>>8)&0xFF;
|
||||
|
||||
if(totalCommands>15)return -2;
|
||||
if(totalCommands>=15)return -2;
|
||||
|
||||
u8 nextCmd=(commandIndex+totalCommands)%15; //there are 15 command slots
|
||||
u32* dst=&sharedGspCmdBuf[8*(1+nextCmd)];
|
||||
|
130
libctru/source/HTTPC.c
Normal file
130
libctru/source/HTTPC.c
Normal file
@ -0,0 +1,130 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctr/types.h>
|
||||
#include <ctr/HTTPC.h>
|
||||
#include <ctr/svc.h>
|
||||
|
||||
Result HTTPC_Initialize(Handle handle)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0]=0x10044; //request header code
|
||||
cmdbuf[1]=0x1000; //unk
|
||||
cmdbuf[2]=0x20; //unk
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result HTTPC_CreateContext(Handle handle, char* url, Handle* contextHandle)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
u32 l=strlen(url)+1;
|
||||
|
||||
cmdbuf[0]=0x20082; //request header code
|
||||
cmdbuf[1]=l;
|
||||
cmdbuf[2]=0x01; //unk
|
||||
cmdbuf[3]=(l<<4)|0xA;
|
||||
cmdbuf[4]=(u32)url;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
if(contextHandle)*contextHandle=cmdbuf[2];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result HTTPC_InitializeConnectionSession(Handle handle, Handle contextHandle)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0]=0x80042; //request header code
|
||||
cmdbuf[1]=contextHandle;
|
||||
cmdbuf[2]=0x20; //unk, constant afaict
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result HTTPC_SetProxyDefault(Handle handle, Handle contextHandle)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0]=0xe0040; //request header code
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result HTTPC_CloseContext(Handle handle, Handle contextHandle)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0]=0x30040; //request header code
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result HTTPC_AddRequestHeaderField(Handle handle, Handle contextHandle, char* name, char* value)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
int l1=strlen(name)+1;
|
||||
int l2=strlen(value)+1;
|
||||
|
||||
cmdbuf[0]=0x1100c4; //request header code
|
||||
cmdbuf[1]=contextHandle;
|
||||
cmdbuf[2]=l1;
|
||||
cmdbuf[3]=l2;
|
||||
cmdbuf[4]=(l1<<14)|0xC02;
|
||||
cmdbuf[5]=(u32)name;
|
||||
cmdbuf[6]=(l1<<4)|0xA;
|
||||
cmdbuf[7]=(u32)value;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result HTTPC_BeginRequest(Handle handle, Handle contextHandle)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0]=0x90040; //request header code
|
||||
cmdbuf[1]=contextHandle;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
Result HTTPC_ReceiveData(Handle handle, Handle contextHandle, u8* buffer, u32 size)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
|
||||
cmdbuf[0]=0xB0082; //request header code
|
||||
cmdbuf[1]=contextHandle;
|
||||
cmdbuf[2]=size;
|
||||
cmdbuf[3]=(size<<4)|12;
|
||||
cmdbuf[4]=(u32)buffer;
|
||||
|
||||
Result ret=0;
|
||||
if((ret=svc_sendSyncRequest(handle)))return ret;
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
Loading…
Reference in New Issue
Block a user