mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 18:32:44 +00:00
Add http_intf.c/http_intf.h
This commit is contained in:
parent
bfdf283a11
commit
1af76d7179
@ -599,7 +599,8 @@ endif
|
||||
ifeq ($(HAVE_NETPLAY), 1)
|
||||
DEFINES += -DHAVE_NETPLAY -DHAVE_NETWORK_CMD
|
||||
OBJ += netplay.o
|
||||
OBJ += http_lib.o
|
||||
OBJ += http_lib.o \
|
||||
http_intf.o
|
||||
ifneq ($(findstring Win32,$(OS)),)
|
||||
LIBS += -lws2_32
|
||||
endif
|
||||
|
97
http_intf.c
Normal file
97
http_intf.c
Normal file
@ -0,0 +1,97 @@
|
||||
#include <stdlib.h>
|
||||
#include "http_intf.h"
|
||||
#include "general.h"
|
||||
#include "retroarch_logger.h"
|
||||
|
||||
int http_intf_command(unsigned mode, char *url)
|
||||
{
|
||||
int ret, lg, blocksize, r;
|
||||
char typebuf[70];
|
||||
char *data=NULL, *filename = NULL, *proxy = NULL;
|
||||
int i=1;
|
||||
|
||||
if (mode == HTTP_INTF_ERROR)
|
||||
return -1;
|
||||
|
||||
i++;
|
||||
|
||||
#if 0
|
||||
if ((proxy = getenv("http_proxy")))
|
||||
{
|
||||
ret=http_parse_url(proxy,&filename);
|
||||
if (ret<0)
|
||||
return ret;
|
||||
http_proxy_server=http_server;
|
||||
http_server=NULL;
|
||||
http_proxy_port=http_port;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = http_parse_url(url, &filename);
|
||||
|
||||
if (ret<0)
|
||||
{
|
||||
if (proxy)
|
||||
free(http_proxy_server);
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
/* *** PUT *** */
|
||||
case HTTP_INTF_PUT:
|
||||
RARCH_LOG("reading stdin...\n");
|
||||
/* read stdin into memory */
|
||||
blocksize=16384;
|
||||
lg=0;
|
||||
if (!(data=malloc(blocksize)))
|
||||
return 3;
|
||||
while (1)
|
||||
{
|
||||
r=read(0, data + lg, blocksize - lg);
|
||||
if (r<=0)
|
||||
break;
|
||||
lg+=r;
|
||||
|
||||
if ((3 * lg / 2) > blocksize)
|
||||
{
|
||||
blocksize *= 4;
|
||||
RARCH_LOG("read to date: %9d bytes, reallocating buffer to %9d\n",
|
||||
lg, blocksize);
|
||||
if (!(data=realloc(data,blocksize)))
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
RARCH_LOG("read %d bytes\n", lg);
|
||||
ret=http_put(filename,data,lg,0,NULL);
|
||||
RARCH_LOG("res=%d\n",ret);
|
||||
break;
|
||||
case HTTP_INTF_GET:
|
||||
/* *** GET *** */
|
||||
ret = http_get(filename, &data, &lg, typebuf);
|
||||
RARCH_LOG("res=%d,type='%s',lg=%d\n",ret,typebuf,lg);
|
||||
fwrite(data,lg,1,stdout);
|
||||
break;
|
||||
case HTTP_INTF_HEAD:
|
||||
/* *** HEAD *** */
|
||||
ret=http_head(filename,&lg,typebuf);
|
||||
RARCH_LOG("res=%d,type='%s',lg=%d\n",ret,typebuf,lg);
|
||||
break;
|
||||
case HTTP_INTF_DELETE:
|
||||
/* *** DELETE *** */
|
||||
ret=http_delete(filename);
|
||||
RARCH_LOG("res=%d\n",ret);
|
||||
break;
|
||||
/* impossible... */
|
||||
default:
|
||||
RARCH_LOG("impossible mode value=%d\n", mode);
|
||||
return 5;
|
||||
}
|
||||
if (data)
|
||||
free(data);
|
||||
free(filename);
|
||||
free(http_server);
|
||||
if (proxy)
|
||||
free(http_proxy_server);
|
||||
return ( (ret==201) || (ret==200) ) ? 0 : ret;
|
||||
}
|
18
http_intf.h
Normal file
18
http_intf.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef _HTTP_INTF_H
|
||||
#define _HTTP_INTF_H
|
||||
|
||||
#include "netplay_compat.h"
|
||||
#include "http_lib.h"
|
||||
|
||||
enum
|
||||
{
|
||||
HTTP_INTF_ERROR = 0,
|
||||
HTTP_INTF_PUT,
|
||||
HTTP_INTF_GET,
|
||||
HTTP_INTF_DELETE,
|
||||
HTTP_INTF_HEAD
|
||||
};
|
||||
|
||||
int http_intf_command(unsigned mode, char *url);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user