mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-27 18:20:27 +00:00
Remove old http code
This commit is contained in:
parent
6bbf4ffdd1
commit
1a9f449362
@ -629,8 +629,6 @@ ifeq ($(HAVE_NETPLAY), 1)
|
||||
DEFINES += -DHAVE_NETPLAY -DHAVE_NETWORK_CMD
|
||||
OBJ += netplay.o \
|
||||
netplay_compat.o \
|
||||
http_lib.o \
|
||||
http_intf.o \
|
||||
net_http.o
|
||||
ifneq ($(findstring Win32,$(OS)),)
|
||||
LIBS += -lws2_32
|
||||
|
@ -662,8 +662,6 @@ NETPLAY
|
||||
#ifdef HAVE_NETPLAY
|
||||
#include "../netplay.c"
|
||||
#include "../netplay_compat.c"
|
||||
#include "../http_lib.c"
|
||||
#include "../http_intf.c"
|
||||
#include "../net_http.c"
|
||||
#endif
|
||||
|
||||
|
44
http_intf.c
44
http_intf.c
@ -1,44 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
* Copyright (C) 2014-2015 - Alfred Agrell
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "http_intf.h"
|
||||
#include <retro_miscellaneous.h>
|
||||
|
||||
#include <file/file_path.h>
|
||||
|
||||
/**
|
||||
* http_get_file:
|
||||
* @url : URL to file.
|
||||
* @buf : Buffer.
|
||||
* @len : Size of @buf.
|
||||
*
|
||||
* Loads the contents of a file at specified URL into
|
||||
* buffer @buf. Sets length of data buffer as well.
|
||||
*
|
||||
* Returns: HTTP return code on success, otherwise
|
||||
* negative on failure.
|
||||
**/
|
||||
http_retcode http_get_file(char *url, char **buf, int *len)
|
||||
{
|
||||
char *urlfilename = NULL;
|
||||
|
||||
if (http_parse_url(url, &urlfilename) != 0)
|
||||
return ERRRDDT;
|
||||
|
||||
return http_get(urlfilename, buf, len, NULL);
|
||||
}
|
46
http_intf.h
46
http_intf.h
@ -1,46 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
* Copyright (C) 2014-2015 - Alfred Agrell
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _HTTP_INTF_H
|
||||
#define _HTTP_INTF_H
|
||||
|
||||
#include <boolean.h>
|
||||
#include "netplay_compat.h"
|
||||
#include "http_lib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* http_get_file:
|
||||
* @url : URL to file.
|
||||
* @buf : Buffer.
|
||||
* @len : Size of @buf.
|
||||
*
|
||||
* Loads the contents of a file at specified URL into
|
||||
* buffer @buf. Sets length of data buffer as well.
|
||||
*
|
||||
* Returns: HTTP return code on success, otherwise
|
||||
* negative on failure.
|
||||
**/
|
||||
http_retcode http_get_file(char *url, char **buf, int *len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
563
http_lib.c
563
http_lib.c
@ -1,563 +0,0 @@
|
||||
/*
|
||||
* Http put/get mini lib
|
||||
* written by L. Demailly
|
||||
* (c) 1998 Laurent Demailly - http://www.demailly.com/~dl/
|
||||
* (c) 1996 Observatoire de Paris - Meudon - France
|
||||
* see LICENSE for terms, conditions and DISCLAIMER OF ALL WARRANTIES
|
||||
*
|
||||
* $Id: http_lib.c,v 3.5 1998/09/23 06:19:15 dl Exp $
|
||||
*
|
||||
* Description : Use http protocol, connects to server to echange data
|
||||
*
|
||||
* $Log: http_lib.c,v $
|
||||
* Revision 3.5 1998/09/23 06:19:15 dl
|
||||
* portability and http 1.x (1.1 and later) compatibility
|
||||
*
|
||||
* Revision 3.4 1998/09/23 05:44:27 dl
|
||||
* added support for HTTP/1.x answers
|
||||
*
|
||||
* Revision 3.3 1996/04/25 19:07:22 dl
|
||||
* using intermediate variable for htons (port) so it does not yell
|
||||
* on freebsd (thx pp for report)
|
||||
*
|
||||
* Revision 3.2 1996/04/24 13:56:08 dl
|
||||
* added proxy support through http_proxy_server & http_proxy_port
|
||||
* some httpd *needs* cr+lf so provide them
|
||||
* simplification + cleanup
|
||||
*
|
||||
* Revision 3.1 1996/04/18 13:53:13 dl
|
||||
* http-tiny release 1.0
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#define VERBOSE
|
||||
|
||||
/* http_lib - HTTP data exchanges mini library.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "netplay_compat.h"
|
||||
#include "http_lib.h"
|
||||
|
||||
#define SERVER_DEFAULT "adonis"
|
||||
|
||||
/* pointer to a mallocated string containing server name or NULL */
|
||||
char *http_server=NULL ;
|
||||
/* server port number */
|
||||
int http_port=5757;
|
||||
/* pointer to proxy server name or NULL */
|
||||
char *http_proxy_server=NULL;
|
||||
/* proxy server port number or 0 */
|
||||
int http_proxy_port=0;
|
||||
/* user agent id string */
|
||||
static const char *http_user_agent="adlib/3 ($Date: 1998/09/23 06:19:15 $)";
|
||||
|
||||
/**
|
||||
* http_read_line:
|
||||
* @fd : File descriptor to read from.
|
||||
* @buffer : Placeholder for data.
|
||||
* @max : Maximum number of bytes to read.
|
||||
*
|
||||
* Reads a line from file descriptor
|
||||
* returns the number of bytes read. negative if a read error occured
|
||||
* before the end of line or the max.
|
||||
* cariage returns (CR) are ignored.
|
||||
*
|
||||
* Returns: number of bytes read, negative if error occurred.
|
||||
**/
|
||||
static int http_read_line (int fd, char *buffer, int max)
|
||||
{
|
||||
/* not efficient on long lines (multiple unbuffered 1 char reads) */
|
||||
int n = 0;
|
||||
|
||||
while (n < max)
|
||||
{
|
||||
if (read(fd, buffer, 1) != 1)
|
||||
{
|
||||
n = -n;
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
if (*buffer == '\015')
|
||||
continue; /* ignore CR */
|
||||
if (*buffer == '\012')
|
||||
break; /* LF is the separator */
|
||||
buffer++;
|
||||
}
|
||||
*buffer=0;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* http_read_buffer:
|
||||
* @fd : File descriptor to read from.
|
||||
* @buffer : Placeholder for data.
|
||||
* @max : Maximum number of bytes to read.
|
||||
*
|
||||
* Reads data from file descriptor.
|
||||
* Retries reading until the number of bytes requested is read.
|
||||
* Returns the number of bytes read. negative if a read error (EOF) occured
|
||||
* before the requested length.
|
||||
*
|
||||
* Returns: number of bytes read, negative if error occurred.
|
||||
**/
|
||||
static int http_read_buffer (int fd, char *buffer, int length)
|
||||
{
|
||||
int n,r;
|
||||
|
||||
for (n = 0; n < length; n += r)
|
||||
{
|
||||
r = read(fd, buffer, length-n);
|
||||
if (r <= 0)
|
||||
return -n;
|
||||
buffer += r;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* Close the socket after the query (for put) */
|
||||
CLOSE,
|
||||
/* Keep it open */
|
||||
KEEP_OPEN
|
||||
} querymode;
|
||||
|
||||
#ifndef OSK
|
||||
|
||||
static http_retcode http_query(const char *command, const char *url,
|
||||
const char *additional_header, querymode mode,
|
||||
const char* data, int length, int *pfd);
|
||||
#endif
|
||||
|
||||
/* beware that filename+type+rest of header must not exceed MAXBUF */
|
||||
/* so we limit filename to 256 and type to 64 chars in put & get */
|
||||
#define MAXBUF 512
|
||||
|
||||
/*
|
||||
* http_query:
|
||||
* @command : Command to send.
|
||||
* @url : URL / filename queried.
|
||||
* @additional_header : Additional header.
|
||||
* @mode : Type of query.
|
||||
* @data : Data to send after header. If NULL,
|
||||
* no data is sent.
|
||||
* @length : Size of data.
|
||||
* @pfd : Pointer to variable where to set file
|
||||
* descriptor value.
|
||||
*
|
||||
* Pseudo general HTTP query.
|
||||
*
|
||||
* Sends a command and additional headers to the HTTP server.
|
||||
* optionally through the proxy (if http_proxy_server and http_proxy_port are
|
||||
* set).
|
||||
*
|
||||
* Limitations: the url is truncated to first 256 chars and
|
||||
* the server name to 128 in case of proxy request.
|
||||
*
|
||||
* Returns: HTTP return code.
|
||||
**/
|
||||
static http_retcode http_query(const char *command, const char *url,
|
||||
const char *additional_header, querymode mode,
|
||||
const char *data, int length, int *pfd)
|
||||
{
|
||||
int s;
|
||||
struct hostent *hp;
|
||||
struct sockaddr_in server;
|
||||
char header[MAXBUF];
|
||||
int hlg;
|
||||
http_retcode ret;
|
||||
int proxy = (http_proxy_server != NULL && http_proxy_port != 0);
|
||||
int port = proxy ? http_proxy_port : http_port ;
|
||||
|
||||
if (pfd)
|
||||
*pfd=-1;
|
||||
|
||||
/* get host info by name :*/
|
||||
if ((hp = gethostbyname( proxy ? http_proxy_server
|
||||
: ( http_server ? http_server
|
||||
: SERVER_DEFAULT )
|
||||
)))
|
||||
{
|
||||
memset((char *) &server,0, sizeof(server));
|
||||
memmove((char *) &server.sin_addr, hp->h_addr, hp->h_length);
|
||||
|
||||
server.sin_family = hp->h_addrtype;
|
||||
server.sin_port = (unsigned short) htons( port );
|
||||
}
|
||||
else
|
||||
return ERRHOST;
|
||||
|
||||
/* create socket */
|
||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
return ERRSOCK;
|
||||
setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
|
||||
|
||||
/* connect to server */
|
||||
if (connect(s, (struct sockaddr*)&server, sizeof(server)) < 0)
|
||||
ret=ERRCONN;
|
||||
else
|
||||
{
|
||||
int n;
|
||||
|
||||
if (pfd)
|
||||
*pfd=s;
|
||||
|
||||
/* create header */
|
||||
if (proxy)
|
||||
{
|
||||
snprintf(header,
|
||||
sizeof(header),
|
||||
"%s http://%.128s:%d/%.256s HTTP/1.0\015\012User-Agent: %s\015\012Host: %s\015\012%s\015\012",
|
||||
command,
|
||||
http_server,
|
||||
http_port,
|
||||
url,
|
||||
http_user_agent,
|
||||
http_server,
|
||||
additional_header
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(header,
|
||||
sizeof(header),
|
||||
"%s /%.256s HTTP/1.0\015\012User-Agent: %s\015\012Host: %s\015\012%s\015\012",
|
||||
command,
|
||||
url,
|
||||
http_user_agent,
|
||||
http_server,
|
||||
additional_header
|
||||
);
|
||||
}
|
||||
|
||||
hlg=strlen(header);
|
||||
|
||||
/* send header */
|
||||
if (write(s, header, hlg) != hlg)
|
||||
ret= ERRWRHD;
|
||||
|
||||
/* send data */
|
||||
else if (length && data && (write(s, data, length) != length) )
|
||||
ret= ERRWRDT;
|
||||
else
|
||||
{
|
||||
/* read result & check */
|
||||
n = http_read_line(s,header,MAXBUF-1);
|
||||
#ifdef VERBOSE
|
||||
fputs(header,stderr);
|
||||
putc('\n',stderr);
|
||||
#endif
|
||||
if (n <= 0)
|
||||
ret = ERRRDHD;
|
||||
else if (sscanf(header, "HTTP/1.%*d %03d", (int*)&ret) != 1)
|
||||
ret = ERRPAHD;
|
||||
else if (mode == KEEP_OPEN)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
close(s); /* close socket */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* http_put:
|
||||
* @filename : Name of the resource to create.
|
||||
* @data : Pointer to the data to send.
|
||||
* @length : Length of the data to send.
|
||||
* @overwrite : Flag to request to overwrite the
|
||||
* resource if it already exists.
|
||||
* @type : Type of data.
|
||||
*
|
||||
* Put data on the server
|
||||
*
|
||||
* This function sends data to the HTTP data server.
|
||||
* The data will be stored under the ressource name filename.
|
||||
* returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
* and type to 64.
|
||||
*
|
||||
* Returns: HTTP return code.
|
||||
**/
|
||||
http_retcode http_put(const char *filename, const char *data,
|
||||
int length, int overwrite, const char *type)
|
||||
{
|
||||
char header[MAXBUF];
|
||||
if (type)
|
||||
snprintf(header, sizeof(header), "Content-length: %d\015\012Content-type: %.64s\015\012%s",
|
||||
length, type, overwrite ? "Control: overwrite=1\015\012" : "");
|
||||
else
|
||||
snprintf(header, sizeof(header), "Content-length: %d\015\012%s",length,
|
||||
overwrite ? "Control: overwrite=1\015\012" : "");
|
||||
|
||||
return http_query("PUT", filename, header, CLOSE, data, length, NULL);
|
||||
}
|
||||
|
||||
static http_retcode http_read_line_loop(int fd, char *header,
|
||||
int *length, char *typebuf)
|
||||
{
|
||||
int n;
|
||||
char *pc;
|
||||
|
||||
while (1)
|
||||
{
|
||||
n = http_read_line(fd, header, MAXBUF-1);
|
||||
#ifdef VERBOSE
|
||||
fputs(header, stderr);
|
||||
putc('\n', stderr);
|
||||
#endif
|
||||
if (n <= 0)
|
||||
return ERRRDHD;
|
||||
|
||||
/* Empty line ? (=> end of header) */
|
||||
if (n > 0 && (*header) == '\0')
|
||||
break;
|
||||
|
||||
/* Try to parse some keywords : */
|
||||
/* convert to lower case 'till a : is found or end of string */
|
||||
for (pc=header; (*pc != ':' && *pc) ; pc++)
|
||||
*pc = tolower(*pc);
|
||||
sscanf(header, "content-length: %d", length);
|
||||
|
||||
if (typebuf)
|
||||
sscanf(header, "content-type: %s", typebuf);
|
||||
}
|
||||
return OK0;
|
||||
}
|
||||
|
||||
/**
|
||||
* http_get:
|
||||
* @filename : Name of the resource to create.
|
||||
* @pdata : Address of pointer which will be set
|
||||
* to point toward allocated memory containing
|
||||
* read data.
|
||||
* @typebuf : Allocated buffer where the read data
|
||||
* type is returned. If NULL, the type is
|
||||
* not returned.
|
||||
*
|
||||
* Gets data from the server
|
||||
*
|
||||
* This function gets data from the HTTP data server.
|
||||
* The data is read from the ressource named filename.
|
||||
* Address of new new allocated memory block is filled in pdata
|
||||
* whose length is returned via plength.
|
||||
*
|
||||
* Returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
*
|
||||
* Returns: HTTP error code.
|
||||
**/
|
||||
http_retcode http_get(const char *filename,
|
||||
char **pdata, int *plength, char *typebuf)
|
||||
{
|
||||
http_retcode ret;
|
||||
char header[MAXBUF], *pc = NULL;
|
||||
int fd, n, length = -1;
|
||||
|
||||
(void)pc;
|
||||
|
||||
if (!pdata)
|
||||
return ERRNULL;
|
||||
|
||||
*pdata = NULL;
|
||||
|
||||
if (plength)
|
||||
*plength = 0;
|
||||
if (typebuf)
|
||||
*typebuf = '\0';
|
||||
|
||||
ret = http_query("GET", filename, "", KEEP_OPEN, NULL, 0, &fd);
|
||||
|
||||
if (ret == 200)
|
||||
{
|
||||
if ((ret = http_read_line_loop(fd, header, &length, typebuf)) != 0)
|
||||
{
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (length <= 0)
|
||||
{
|
||||
close(fd);
|
||||
return ERRNOLG;
|
||||
}
|
||||
|
||||
if (plength)
|
||||
*plength = length;
|
||||
|
||||
if (!(*pdata = (char*)malloc(length)))
|
||||
{
|
||||
close(fd);
|
||||
return ERRMEM;
|
||||
}
|
||||
|
||||
n = http_read_buffer(fd, *pdata, length);
|
||||
|
||||
close(fd);
|
||||
if (n != length)
|
||||
ret = ERRRDDT;
|
||||
}
|
||||
else if (ret >= 0)
|
||||
close(fd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* http_head:
|
||||
* @filename : Name of the resource to create.
|
||||
* @plength : Address of integer variable which will be set
|
||||
* to length of the data.
|
||||
* @typebuf : Allocated buffer where the read data
|
||||
* type is returned. If NULL, the type is
|
||||
* not returned.
|
||||
*
|
||||
* Requests the header.
|
||||
*
|
||||
* This function outputs the header of the HTTP data server.
|
||||
* The header is from the ressource named filename.
|
||||
* The length and type of data is eventually returned (like for http_get(3))
|
||||
*
|
||||
* Returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
*
|
||||
* Returns: HTTP return code.
|
||||
**/
|
||||
http_retcode http_head(const char *filename, int *plength, char *typebuf)
|
||||
{
|
||||
http_retcode ret;
|
||||
char header[MAXBUF];
|
||||
int fd, length = -1;
|
||||
|
||||
if (plength)
|
||||
*plength=0;
|
||||
if (typebuf)
|
||||
*typebuf='\0';
|
||||
|
||||
ret=http_query("HEAD", filename, "", KEEP_OPEN, NULL, 0, &fd);
|
||||
|
||||
if (ret == 200)
|
||||
{
|
||||
if ((ret = http_read_line_loop(fd, header, &length, typebuf)) != 0)
|
||||
{
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (plength)
|
||||
*plength = length;
|
||||
close(fd);
|
||||
}
|
||||
else if (ret >= 0)
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* http_delete:
|
||||
* @filename : Name of the resource to create.
|
||||
*
|
||||
* Deletes data on the server
|
||||
*
|
||||
* Request a DELETE on the HTTP data server.
|
||||
*
|
||||
* Returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
*
|
||||
* Returns: HTTP return code.
|
||||
**/
|
||||
http_retcode http_delete(const char *filename)
|
||||
{
|
||||
return http_query("DELETE", filename, "", CLOSE, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* http_parse_url:
|
||||
* @url : Writable copy of an URL.
|
||||
* @pfilename : Address of a pointer that will be filled with
|
||||
* allocated filename. The pointer must be equal
|
||||
* to NULL before calling it or it will be automatically
|
||||
* freed (free(3)).
|
||||
* Parses an url : setting the http_server and http_port global variables
|
||||
* and returning the filename to pass to http_get/put/...
|
||||
* returns a negative error code or 0 if sucessfully parsed.
|
||||
*
|
||||
* Returns: 0 if successfully parsed, negative error code if not.
|
||||
**/
|
||||
http_retcode http_parse_url(char *url, char **pfilename)
|
||||
{
|
||||
char *pc, c;
|
||||
|
||||
http_port = 80;
|
||||
|
||||
if (http_server)
|
||||
{
|
||||
free(http_server);
|
||||
http_server=NULL;
|
||||
}
|
||||
if (*pfilename)
|
||||
{
|
||||
free(*pfilename);
|
||||
*pfilename=NULL;
|
||||
}
|
||||
|
||||
if (strncasecmp("http://", url, 7))
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
fprintf(stderr,"invalid url (must start with 'http://')\n");
|
||||
#endif
|
||||
return ERRURLH;
|
||||
}
|
||||
url+=7;
|
||||
|
||||
for (pc = url, c = *pc; (c && c != ':' && c != '/');)
|
||||
c=*pc++;
|
||||
|
||||
*(pc-1) = 0;
|
||||
|
||||
if (c == ':')
|
||||
{
|
||||
if (sscanf(pc, "%d", &http_port) != 1)
|
||||
{
|
||||
#ifdef VERBOSE
|
||||
fprintf(stderr,"invalid port in url\n");
|
||||
#endif
|
||||
return ERRURLP;
|
||||
}
|
||||
for (pc++; (*pc && *pc != '/') ; pc++) ;
|
||||
if (*pc)
|
||||
pc++;
|
||||
}
|
||||
|
||||
http_server = strdup(url);
|
||||
*pfilename = strdup ( c ? pc : "") ;
|
||||
|
||||
#ifdef VERBOSE
|
||||
fprintf(stderr,"host=(%s), port=%d, filename=(%s)\n",
|
||||
http_server, http_port, *pfilename);
|
||||
#endif
|
||||
return OK0;
|
||||
}
|
167
http_lib.h
167
http_lib.h
@ -1,167 +0,0 @@
|
||||
/*
|
||||
* Http put/get mini lib
|
||||
* written by L. Demailly
|
||||
* (c) 1998 Laurent Demailly - http://www.demailly.com/~dl/
|
||||
* (c) 1996 Observatoire de Paris - Meudon - France
|
||||
* see LICENSE for terms, conditions and DISCLAIMER OF ALL WARRANTIES
|
||||
*
|
||||
* $Id: http_lib.h,v 1.4 1998/09/23 06:14:15 dl Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HTTP_LIB_H
|
||||
#define _HTTP_LIB_H
|
||||
|
||||
extern char *http_server;
|
||||
|
||||
extern int http_port;
|
||||
|
||||
extern char *http_proxy_server;
|
||||
|
||||
extern int http_proxy_port;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* Client side errors */
|
||||
|
||||
ERRHOST = -1, /* No such host */
|
||||
ERRSOCK = -2, /* Can't create socket */
|
||||
ERRCONN = -3, /* Can't connect to host */
|
||||
ERRWRHD = -4, /* Write error on socket while writing header */
|
||||
ERRWRDT = -5, /* Write error on socket while writing data */
|
||||
ERRRDHD = -6, /* Read error on socket while reading result */
|
||||
ERRPAHD = -7, /* Invalid answer from data server */
|
||||
ERRNULL = -8, /* NULL data pointer */
|
||||
ERRNOLG = -9, /* No/Bad length in header */
|
||||
ERRMEM = -10, /* Can't allocate memory */
|
||||
ERRRDDT = -11, /* Read error while reading data */
|
||||
ERRURLH = -12, /* Invalid URL - must start with 'http://' */
|
||||
ERRURLP = -13, /* Invalid port in URL */
|
||||
|
||||
/* Return code by the server */
|
||||
|
||||
ERR400 = 400, /* Invalid query */
|
||||
ERR403 = 403, /* Forbidden */
|
||||
ERR408 = 408, /* Request timeout */
|
||||
ERR500 = 500, /* Server error */
|
||||
ERR501 = 501, /* Not implemented */
|
||||
ERR503 = 503, /* Service overloaded */
|
||||
|
||||
/* Succesful results */
|
||||
OK201 = 201, /* Resource successfully created */
|
||||
OK200 = 200, /* Resource successfully read */
|
||||
|
||||
OK0 = 0
|
||||
|
||||
} http_retcode;
|
||||
|
||||
|
||||
/* prototypes */
|
||||
|
||||
#ifndef OSK
|
||||
/**
|
||||
* http_put:
|
||||
* @filename : Name of the resource to create.
|
||||
* @data : Pointer to the data to send.
|
||||
* @length : Length of the data to send.
|
||||
* @overwrite : Flag to request to overwrite the
|
||||
* resource if it already exists.
|
||||
* @type : Type of data.
|
||||
*
|
||||
* Put data on the server
|
||||
*
|
||||
* This function sends data to the http data server.
|
||||
* The data will be stored under the ressource name filename.
|
||||
* returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
* and type to 64.
|
||||
*
|
||||
* Returns: HTTP return code.
|
||||
**/
|
||||
http_retcode http_put(const char *filename, const char *data, int length,
|
||||
int overwrite, const char *type) ;
|
||||
|
||||
/**
|
||||
* http_get:
|
||||
* @filename : Name of the resource to create.
|
||||
* @pdata : Address of pointer which will be set
|
||||
* to point toward allocated memory containing
|
||||
* read data.
|
||||
* @typebuf : Allocated buffer where the read data
|
||||
* type is returned. If NULL, the type is
|
||||
* not returned.
|
||||
*
|
||||
* Gets data from the server.
|
||||
*
|
||||
* This function gets data from the HTTP data server.
|
||||
* The data is read from the ressource named filename.
|
||||
* Address of new new allocated memory block is filled in pdata
|
||||
* whose length is returned via plength.
|
||||
*
|
||||
* Returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
*
|
||||
* Returns: HTTP error code.
|
||||
**/
|
||||
http_retcode http_get(const char *filename, char **pdata,
|
||||
int *plength, char *typebuf);
|
||||
|
||||
/**
|
||||
* http_parse_url:
|
||||
* @url : Writable copy of an URL.
|
||||
* @pfilename : Address of a pointer that will be filled with
|
||||
* allocated filename. The pointer must be equal
|
||||
* to NULL before calling it or it will be automatically
|
||||
* freed (free(3)).
|
||||
* Parses an url : setting the http_server and http_port global variables
|
||||
* and returning the filename to pass to http_get/put/...
|
||||
* returns a negative error code or 0 if sucessfully parsed.
|
||||
*
|
||||
* Returns: 0 if successfully parsed, negative error code if not.
|
||||
**/
|
||||
http_retcode http_parse_url(char *url, char **pfilename);
|
||||
|
||||
/**
|
||||
* http_delete:
|
||||
* @filename : Name of the resource to create.
|
||||
*
|
||||
* Deletes data on the server
|
||||
*
|
||||
* Request a DELETE on the HTTP data server.
|
||||
*
|
||||
* Returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
*
|
||||
* Returns: HTTP return code.
|
||||
**/
|
||||
http_retcode http_delete(const char *filename) ;
|
||||
|
||||
/**
|
||||
* http_head:
|
||||
* @filename : Name of the resource to create.
|
||||
* @plength : Address of integer variable which will be set
|
||||
* to length of the data.
|
||||
* @typebuf : Allocated buffer where the read data
|
||||
* type is returned. If NULL, the type is
|
||||
* not returned.
|
||||
*
|
||||
* Requests the header.
|
||||
*
|
||||
* This function outputs the header of the HTTP data server.
|
||||
* The header is from the ressource named filename.
|
||||
* The length and type of data is eventually returned (like for http_get(3))
|
||||
*
|
||||
* Returns a negative error code or a positive code from the server
|
||||
*
|
||||
* limitations: filename is truncated to first 256 characters
|
||||
*
|
||||
* Returns: HTTP return code.
|
||||
**/
|
||||
http_retcode http_head(const char *filename, int *plength, char *typebuf);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -29,7 +29,6 @@
|
||||
#include "../performance.h"
|
||||
|
||||
#ifdef HAVE_NETPLAY
|
||||
#include "../http_intf.h"
|
||||
#include "../net_http.h"
|
||||
#endif
|
||||
|
||||
@ -2278,18 +2277,61 @@ static void print_buf_lines(file_list_t *list, char *buf, int buf_size,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* HACK - we have to find some way to pass state inbetween
|
||||
* function pointer callback functions that don't necessarily
|
||||
* call each other. */
|
||||
static char core_manager_path[PATH_MAX_LENGTH];
|
||||
static void *core_manager_list_data;
|
||||
static char core_manager_list_path[PATH_MAX_LENGTH];
|
||||
static char core_manager_list_label[PATH_MAX_LENGTH];
|
||||
static unsigned core_manager_list_type;
|
||||
|
||||
static int cb_core_manager_list(void *data_, size_t len)
|
||||
{
|
||||
char *data = (char*)data_;
|
||||
file_list_t *list = NULL;
|
||||
|
||||
if (!data || !core_manager_list_data)
|
||||
return -1;
|
||||
|
||||
list = (file_list_t*)core_manager_list_data;
|
||||
|
||||
if (!list)
|
||||
return -1;
|
||||
|
||||
menu_list_clear(list);
|
||||
|
||||
rarch_main_command(RARCH_CMD_NETWORK_INIT);
|
||||
|
||||
print_buf_lines(list, data, len, MENU_FILE_DOWNLOAD_CORE);
|
||||
|
||||
driver.menu->scroll_indices_size = 0;
|
||||
menu_entries_build_scroll_indices(list);
|
||||
menu_entries_refresh(list);
|
||||
|
||||
if (driver.menu_ctx && driver.menu_ctx->populate_entries)
|
||||
driver.menu_ctx->populate_entries(driver.menu,
|
||||
core_manager_list_path,
|
||||
core_manager_list_label,
|
||||
core_manager_list_type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int deferred_push_core_manager_list(void *data, void *userdata,
|
||||
const char *path, const char *label, unsigned type)
|
||||
{
|
||||
#ifdef HAVE_NETPLAY
|
||||
int len;
|
||||
char url[PATH_MAX_LENGTH];
|
||||
char url_path[PATH_MAX_LENGTH];
|
||||
#endif
|
||||
char *buf = NULL;
|
||||
file_list_t *list = (file_list_t*)data;
|
||||
|
||||
(void)buf;
|
||||
|
||||
core_manager_list_data = data;
|
||||
strlcpy(core_manager_list_path, path,
|
||||
sizeof(core_manager_list_path));
|
||||
strlcpy(core_manager_list_label, label,
|
||||
sizeof(core_manager_list_label));
|
||||
core_manager_list_type = type;
|
||||
|
||||
menu_list_clear(list);
|
||||
|
||||
@ -2304,34 +2346,27 @@ static int deferred_push_core_manager_list(void *data, void *userdata,
|
||||
"Network not available.", "",
|
||||
0, 0);
|
||||
#endif
|
||||
goto exit;
|
||||
driver.menu->scroll_indices_size = 0;
|
||||
menu_entries_build_scroll_indices(list);
|
||||
menu_entries_refresh(list);
|
||||
|
||||
if (driver.menu_ctx && driver.menu_ctx->populate_entries)
|
||||
driver.menu_ctx->populate_entries(driver.menu, path, label, type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_NETPLAY
|
||||
rarch_main_command(RARCH_CMD_NETWORK_INIT);
|
||||
|
||||
fill_pathname_join(url, g_settings.network.buildbot_url,
|
||||
".index", sizeof(url));
|
||||
fill_pathname_join(url_path, g_settings.network.buildbot_url,
|
||||
".index", sizeof(url_path));
|
||||
|
||||
if (!list)
|
||||
return -1;
|
||||
msg_queue_clear(g_extern.http_msg_queue);
|
||||
msg_queue_push(g_extern.http_msg_queue, url_path, 0, 180);
|
||||
|
||||
if (http_get_file(url, &buf, &len) < 0)
|
||||
return -1;
|
||||
|
||||
print_buf_lines(list, buf, len, MENU_FILE_DOWNLOAD_CORE);
|
||||
net_http_set_pending_cb(cb_core_manager_list);
|
||||
#endif
|
||||
|
||||
exit:
|
||||
driver.menu->scroll_indices_size = 0;
|
||||
menu_entries_build_scroll_indices(list);
|
||||
menu_entries_refresh(list);
|
||||
|
||||
if (driver.menu_ctx && driver.menu_ctx->populate_entries)
|
||||
driver.menu_ctx->populate_entries(driver.menu, path, label, type);
|
||||
|
||||
if (buf)
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user