2011-03-19 22:04:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* netutils/webclient/webclient.c
|
|
|
|
* Implementation of the HTTP client.
|
|
|
|
*
|
2020-04-22 13:36:07 +02:00
|
|
|
* Copyright (C) 2007, 2009, 2011-2012, 2014, 2020 Gregory Nutt.
|
|
|
|
* All rights reserved.
|
2012-02-18 19:13:30 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-03-19 22:04:13 +01:00
|
|
|
*
|
|
|
|
* Based on uIP which also has a BSD style license:
|
|
|
|
*
|
|
|
|
* Author: Adam Dunkels <adam@dunkels.com>
|
|
|
|
* Copyright (c) 2002, Adam Dunkels.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials provided
|
|
|
|
* with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
|
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
|
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This example shows a HTTP client that is able to download web pages
|
|
|
|
* and files from web servers. It requires a number of callback
|
|
|
|
* functions to be implemented by the module that utilizes the code:
|
|
|
|
* webclient_datahandler().
|
|
|
|
*/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
#include <debug.h>
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2015-02-15 22:18:35 +01:00
|
|
|
#include <sys/time.h>
|
2011-03-19 22:04:13 +01:00
|
|
|
#include <stdint.h>
|
2012-11-04 19:54:04 +01:00
|
|
|
#include <stdio.h>
|
2011-03-19 22:04:13 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
2015-07-10 22:03:28 +02:00
|
|
|
#include <netdb.h>
|
2020-05-28 08:31:46 +02:00
|
|
|
#include <string.h>
|
2017-02-16 22:58:15 +01:00
|
|
|
#include <strings.h>
|
2020-04-22 10:29:02 +02:00
|
|
|
#include <stdlib.h>
|
2011-03-19 22:04:13 +01:00
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netinet/in.h>
|
2012-11-03 01:00:56 +01:00
|
|
|
|
|
|
|
#include <nuttx/version.h>
|
2015-07-10 22:03:28 +02:00
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#include "netutils/netlib.h"
|
|
|
|
#include "netutils/webclient.h"
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2012-11-03 01:00:56 +01:00
|
|
|
#if defined(CONFIG_NETUTILS_CODECS)
|
|
|
|
# if defined(CONFIG_CODECS_URLCODE)
|
2012-11-06 17:59:45 +01:00
|
|
|
# define WGET_USE_URLENCODE 1
|
2016-07-11 18:11:18 +02:00
|
|
|
# include "netutils/urldecode.h"
|
2012-11-03 01:00:56 +01:00
|
|
|
# endif
|
|
|
|
# if defined(CONFIG_CODECS_BASE64)
|
2016-07-11 18:11:18 +02:00
|
|
|
# include "netutils/base64.h"
|
2012-11-03 01:00:56 +01:00
|
|
|
# endif
|
2012-11-06 17:59:45 +01:00
|
|
|
#else
|
|
|
|
# undef CONFIG_CODECS_URLCODE
|
|
|
|
# undef CONFIG_CODECS_BASE64
|
2012-11-03 01:00:56 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_WGET_USERAGENT
|
|
|
|
# if CONFIG_VERSION_MAJOR != 0 || CONFIG_VERSION_MINOR != 0
|
|
|
|
# define CONFIG_NSH_WGET_USERAGENT \
|
|
|
|
"NuttX/" CONFIG_VERSION_STRING " (; http://www.nuttx.org/)"
|
|
|
|
# else
|
|
|
|
# define CONFIG_NSH_WGET_USERAGENT \
|
|
|
|
"NuttX/6.xx.x (; http://www.nuttx.org/)"
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
/****************************************************************************
|
2015-10-02 22:06:11 +02:00
|
|
|
* Pre-processor Definitions
|
2011-03-19 22:04:13 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-30 01:10:49 +02:00
|
|
|
#ifndef CONFIG_WEBCLIENT_TIMEOUT
|
|
|
|
# define CONFIG_WEBCLIENT_TIMEOUT 10
|
|
|
|
#endif
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2020-05-25 16:21:07 +02:00
|
|
|
#ifndef CONFIG_WEBCLIENT_MAX_REDIRECT
|
|
|
|
/* The default value 50 is taken from curl's --max-redirs option. */
|
|
|
|
# define CONFIG_WEBCLIENT_MAX_REDIRECT 50
|
|
|
|
#endif
|
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
#define WEBCLIENT_STATE_STATUSLINE 0
|
|
|
|
#define WEBCLIENT_STATE_HEADERS 1
|
|
|
|
#define WEBCLIENT_STATE_DATA 2
|
|
|
|
#define WEBCLIENT_STATE_CLOSE 3
|
|
|
|
|
|
|
|
#define HTTPSTATUS_NONE 0
|
|
|
|
#define HTTPSTATUS_OK 1
|
|
|
|
#define HTTPSTATUS_MOVED 2
|
|
|
|
#define HTTPSTATUS_ERROR 3
|
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
#define ISO_NL 0x0a
|
|
|
|
#define ISO_CR 0x0d
|
|
|
|
#define ISO_SPACE 0x20
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2012-11-03 01:00:56 +01:00
|
|
|
#define WGET_MODE_GET 0
|
|
|
|
#define WGET_MODE_POST 1
|
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct wget_s
|
|
|
|
{
|
|
|
|
/* Internal status */
|
|
|
|
|
|
|
|
uint8_t state;
|
|
|
|
uint8_t httpstatus;
|
|
|
|
|
|
|
|
uint16_t port; /* The port number to use in the connection */
|
|
|
|
|
|
|
|
/* These describe the just-received buffer of data */
|
|
|
|
|
|
|
|
FAR char *buffer; /* user-provided buffer */
|
|
|
|
int buflen; /* Length of the user provided buffer */
|
|
|
|
int offset; /* Offset to the beginning of interesting data */
|
2012-10-06 16:50:37 +02:00
|
|
|
int datend; /* Offset+1 to the last valid byte of data in the buffer */
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
/* Buffer HTTP header data and parse line at a time */
|
|
|
|
|
|
|
|
char line[CONFIG_WEBCLIENT_MAXHTTPLINE];
|
|
|
|
int ndx;
|
|
|
|
|
|
|
|
#ifdef CONFIG_WEBCLIENT_GETMIMETYPE
|
|
|
|
char mimetype[CONFIG_WEBCLIENT_MAXMIMESIZE];
|
|
|
|
#endif
|
2020-05-25 16:22:55 +02:00
|
|
|
char scheme[sizeof("https") + 1];
|
2011-03-19 22:04:13 +01:00
|
|
|
char hostname[CONFIG_WEBCLIENT_MAXHOSTNAME];
|
|
|
|
char filename[CONFIG_WEBCLIENT_MAXFILENAME];
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const char g_http10[] = "HTTP/1.0";
|
|
|
|
static const char g_http11[] = "HTTP/1.1";
|
|
|
|
#ifdef CONFIG_WEBCLIENT_GETMIMETYPE
|
|
|
|
static const char g_httpcontenttype[] = "content-type: ";
|
|
|
|
#endif
|
|
|
|
static const char g_httphost[] = "host: ";
|
|
|
|
static const char g_httplocation[] = "location: ";
|
|
|
|
static const char g_httpget[] = "GET ";
|
2012-11-03 01:00:56 +01:00
|
|
|
static const char g_httppost[] = "POST ";
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
static const char g_httpuseragentfields[] =
|
|
|
|
"Connection: close\r\n"
|
2012-11-03 01:00:56 +01:00
|
|
|
"User-Agent: "
|
|
|
|
CONFIG_NSH_WGET_USERAGENT
|
|
|
|
"\r\n\r\n";
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
static const char g_http200[] = "200 ";
|
|
|
|
static const char g_http301[] = "301 ";
|
|
|
|
static const char g_http302[] = "302 ";
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
static const char g_httpcrnl[] = "\r\n";
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
static const char g_httpform[] = "Content-Type: "
|
|
|
|
"application/x-www-form-urlencoded";
|
|
|
|
static const char g_httpcontsize[] = "Content-Length: ";
|
|
|
|
#if 0
|
|
|
|
static const char g_httpconn[] = "Connection: Keep-Alive";
|
|
|
|
static const char g_httpcache[] = "Cache-Control: no-cache";
|
|
|
|
#endif
|
2012-11-03 01:00:56 +01:00
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: wget_strcpy
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static char *wget_strcpy(char *dest, const char *src)
|
|
|
|
{
|
|
|
|
int len = strlen(src);
|
2012-11-03 01:00:56 +01:00
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
memcpy(dest, src, len);
|
|
|
|
dest[len] = '\0';
|
|
|
|
return dest + len;
|
|
|
|
}
|
|
|
|
|
2012-11-03 01:00:56 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: wget_urlencode_strcpy
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-11-06 17:59:45 +01:00
|
|
|
#ifdef WGET_USE_URLENCODE
|
2012-11-03 01:00:56 +01:00
|
|
|
static char *wget_urlencode_strcpy(char *dest, const char *src)
|
|
|
|
{
|
|
|
|
int len = strlen(src);
|
|
|
|
int d_len;
|
|
|
|
|
|
|
|
d_len = urlencode_len(src, len);
|
|
|
|
urlencode(src, len, dest, &d_len);
|
|
|
|
return dest + d_len;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: wget_parsestatus
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline int wget_parsestatus(struct wget_s *ws)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
int ndx;
|
|
|
|
char *dest;
|
|
|
|
|
|
|
|
offset = ws->offset;
|
|
|
|
ndx = ws->ndx;
|
|
|
|
|
|
|
|
while (offset < ws->datend)
|
|
|
|
{
|
|
|
|
ws->line[ndx] = ws->buffer[offset];
|
2020-04-22 13:36:07 +02:00
|
|
|
if (ws->line[ndx] == ISO_NL)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
|
|
|
ws->line[ndx] = '\0';
|
|
|
|
if ((strncmp(ws->line, g_http10, strlen(g_http10)) == 0) ||
|
|
|
|
(strncmp(ws->line, g_http11, strlen(g_http11)) == 0))
|
|
|
|
{
|
|
|
|
dest = &(ws->line[9]);
|
|
|
|
ws->httpstatus = HTTPSTATUS_NONE;
|
|
|
|
|
|
|
|
/* Check for 200 OK */
|
|
|
|
|
|
|
|
if (strncmp(dest, g_http200, strlen(g_http200)) == 0)
|
|
|
|
{
|
|
|
|
ws->httpstatus = HTTPSTATUS_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
/* Check for 301 Moved permanently or 302 Found.
|
|
|
|
* Location: header line will contain the new location.
|
2011-03-19 22:04:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
else if (strncmp(dest, g_http301, strlen(g_http301)) == 0 ||
|
|
|
|
strncmp(dest, g_http302, strlen(g_http302)) == 0)
|
|
|
|
{
|
|
|
|
ws->httpstatus = HTTPSTATUS_MOVED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return - ECONNABORTED;
|
|
|
|
}
|
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
/* We're done parsing the status line, so start parsing
|
|
|
|
* the HTTP headers.
|
|
|
|
*/
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
ws->state = WEBCLIENT_STATE_HEADERS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offset++;
|
|
|
|
ndx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ws->offset = offset;
|
|
|
|
ws->ndx = ndx;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2020-05-25 16:22:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: parseurl
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int parseurl(FAR const char *url, FAR struct wget_s *ws)
|
|
|
|
{
|
|
|
|
struct url_s url_s;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(&url_s, 0, sizeof(url_s));
|
|
|
|
url_s.scheme = ws->scheme;
|
|
|
|
url_s.schemelen = sizeof(ws->scheme);
|
|
|
|
url_s.host = ws->hostname;
|
|
|
|
url_s.hostlen = sizeof(ws->hostname);
|
|
|
|
url_s.path = ws->filename;
|
|
|
|
url_s.pathlen = sizeof(ws->filename);
|
|
|
|
ret = netlib_parseurl(url, &url_s);
|
2020-05-28 10:19:16 +02:00
|
|
|
if (ret < 0)
|
2020-05-25 16:22:55 +02:00
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url_s.port == 0)
|
|
|
|
{
|
|
|
|
ws->port = 80;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ws->port = url_s.port;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
/****************************************************************************
|
2020-04-22 10:29:02 +02:00
|
|
|
* Name: wget_parseheaders
|
2011-03-19 22:04:13 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline int wget_parseheaders(struct wget_s *ws)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
int ndx;
|
2020-05-25 16:22:55 +02:00
|
|
|
int ret = OK;
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
offset = ws->offset;
|
|
|
|
ndx = ws->ndx;
|
|
|
|
|
|
|
|
while (offset < ws->datend)
|
|
|
|
{
|
|
|
|
ws->line[ndx] = ws->buffer[offset];
|
2020-04-22 13:36:07 +02:00
|
|
|
if (ws->line[ndx] == ISO_NL)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
|
|
|
/* We have an entire HTTP header line in s.line, so
|
|
|
|
* we parse it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ndx > 0) /* Should always be true */
|
|
|
|
{
|
2020-04-22 13:36:07 +02:00
|
|
|
if (ws->line[0] == ISO_CR)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2020-04-22 13:36:07 +02:00
|
|
|
/* This was the last header line (i.e., and empty "\r\n"),
|
|
|
|
* so we are done with the headers and proceed with the
|
|
|
|
* actual data.
|
2011-03-19 22:04:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
ws->state = WEBCLIENT_STATE_DATA;
|
|
|
|
goto exit;
|
2020-04-22 13:36:07 +02:00
|
|
|
}
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
/* Truncate the trailing \r\n */
|
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
ws->line[ndx - 1] = '\0';
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
/* Check for specific HTTP header fields. */
|
|
|
|
|
|
|
|
#ifdef CONFIG_WEBCLIENT_GETMIMETYPE
|
2020-04-22 13:36:07 +02:00
|
|
|
if (strncasecmp(ws->line, g_httpcontenttype,
|
|
|
|
strlen(g_httpcontenttype)) == 0)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
|
|
|
/* Found Content-type field. */
|
|
|
|
|
|
|
|
char *dest = strchr(ws->line, ';');
|
|
|
|
if (dest != NULL)
|
|
|
|
{
|
|
|
|
*dest = 0;
|
2014-09-30 01:10:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
strncpy(ws->mimetype, ws->line + strlen(g_httpcontenttype),
|
|
|
|
sizeof(ws->mimetype));
|
2011-03-19 22:04:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2020-04-22 13:36:07 +02:00
|
|
|
if (strncasecmp(ws->line, g_httplocation,
|
|
|
|
strlen(g_httplocation)) == 0)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2020-05-25 16:22:55 +02:00
|
|
|
/* Parse the new host and filename from the URL.
|
2011-03-19 22:04:13 +01:00
|
|
|
*/
|
|
|
|
|
2020-05-25 16:22:55 +02:00
|
|
|
ninfo("Redirect to location: '%s'\n",
|
|
|
|
ws->line + strlen(g_httplocation));
|
|
|
|
ret = parseurl(ws->line + strlen(g_httplocation), ws);
|
2020-04-22 13:36:07 +02:00
|
|
|
ninfo("New hostname='%s' filename='%s'\n",
|
|
|
|
ws->hostname, ws->filename);
|
2011-03-19 22:04:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We're done parsing this line, so we reset the index to the start
|
|
|
|
* of the next line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ndx = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ndx++;
|
|
|
|
}
|
2014-09-30 01:10:49 +02:00
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2014-07-08 15:29:38 +02:00
|
|
|
ws->offset = ++offset;
|
2011-03-19 22:04:13 +01:00
|
|
|
ws->ndx = ndx;
|
2020-05-25 16:22:55 +02:00
|
|
|
return ret;
|
2011-03-19 22:04:13 +01:00
|
|
|
}
|
|
|
|
|
2015-07-11 16:15:29 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: wget_gethostip
|
|
|
|
*
|
|
|
|
* Description:
|
2020-04-22 10:29:02 +02:00
|
|
|
* Call getaddrinfo() to get the IPv4 address associated with a hostname.
|
2015-07-11 16:15:29 +02:00
|
|
|
*
|
|
|
|
* Input Parameters
|
|
|
|
* hostname - The host name to use in the nslookup.
|
2020-04-22 10:29:02 +02:00
|
|
|
*
|
|
|
|
* Output Parameters
|
|
|
|
* dest - The location to return the IPv4 address.
|
2015-07-11 16:15:29 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-04-22 10:29:02 +02:00
|
|
|
* Zero (OK) on success; ERROR on failure.
|
2015-07-11 16:15:29 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
static int wget_gethostip(FAR char *hostname, FAR struct in_addr *dest)
|
2015-07-11 16:15:29 +02:00
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
#ifdef CONFIG_LIBC_NETDB
|
|
|
|
FAR struct addrinfo hint;
|
|
|
|
FAR struct addrinfo *info;
|
|
|
|
FAR struct sockaddr_in *addr;
|
2015-07-11 16:15:29 +02:00
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
memset(&hint, 0, sizeof(hint));
|
|
|
|
hint.ai_family = AF_INET;
|
|
|
|
|
|
|
|
if (getaddrinfo(hostname, NULL, &hint, &info) != OK)
|
2015-07-11 16:15:29 +02:00
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
return ERROR;
|
2015-07-11 16:15:29 +02:00
|
|
|
}
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
addr = (FAR struct sockaddr_in *)info->ai_addr;
|
|
|
|
memcpy(dest, &addr->sin_addr, sizeof(struct in_addr));
|
|
|
|
|
|
|
|
freeaddrinfo(info);
|
2015-07-11 16:15:29 +02:00
|
|
|
return OK;
|
2020-04-22 10:29:02 +02:00
|
|
|
#else
|
|
|
|
/* No host name support */
|
|
|
|
|
|
|
|
/* Convert strings to numeric IPv4 address */
|
|
|
|
|
|
|
|
int ret = inet_pton(AF_INET, hostname, dest);
|
|
|
|
|
|
|
|
/* The inet_pton() function returns 1 if the conversion succeeds. It will
|
|
|
|
* return 0 if the input is not a valid IPv4 dotted-decimal string or -1
|
|
|
|
* with errno set to EAFNOSUPPORT if the address family argument is
|
|
|
|
* unsupported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return (ret > 0) ? OK : ERROR;
|
|
|
|
#endif
|
2015-07-11 16:15:29 +02:00
|
|
|
}
|
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
/****************************************************************************
|
2012-11-03 01:00:56 +01:00
|
|
|
* Name: wget_base
|
2011-03-19 22:04:13 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Obtain the requested file from an HTTP server using the GET method.
|
|
|
|
*
|
|
|
|
* Input Parameters
|
|
|
|
* url - A pointer to a string containing either the full URL to
|
|
|
|
* the file to get (e.g., http://www.nutt.org/index.html, or
|
|
|
|
* http://192.168.23.1:80/index.html).
|
|
|
|
* buffer - A user provided buffer to receive the file data (also
|
|
|
|
* used for the outgoing GET request
|
|
|
|
* buflen - The size of the user provided buffer
|
|
|
|
* callback - As data is obtained from the host, this function is
|
|
|
|
* to dispose of each block of file data as it is received.
|
2020-04-22 10:29:02 +02:00
|
|
|
* arg - User argument passed to callback.
|
2012-11-03 01:00:56 +01:00
|
|
|
* mode - Indicates GET or POST modes
|
2011-03-19 22:04:13 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0: if the GET operation completed successfully;
|
2012-10-06 16:50:37 +02:00
|
|
|
* -1: On a failure with errno set appropriately
|
2011-03-19 22:04:13 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2012-10-06 16:50:37 +02:00
|
|
|
|
2012-11-03 01:00:56 +01:00
|
|
|
static int wget_base(FAR const char *url, FAR char *buffer, int buflen,
|
|
|
|
wget_callback_t callback, FAR void *arg,
|
|
|
|
FAR const char *posts, uint8_t mode)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
|
|
|
struct sockaddr_in server;
|
2020-04-22 10:29:02 +02:00
|
|
|
struct wget_s *ws;
|
2014-09-30 01:10:49 +02:00
|
|
|
struct timeval tv;
|
2011-03-19 22:04:13 +01:00
|
|
|
bool redirected;
|
2020-05-25 16:21:07 +02:00
|
|
|
unsigned int nredirect = 0;
|
2020-04-22 10:29:02 +02:00
|
|
|
char *dest;
|
2011-03-19 22:04:13 +01:00
|
|
|
int sockfd;
|
2020-04-22 10:29:02 +02:00
|
|
|
int len;
|
2014-02-11 02:11:56 +01:00
|
|
|
int ret;
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
/* Initialize the state structure */
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
ws = calloc(1, sizeof(struct wget_s));
|
|
|
|
if (!ws)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ws->buffer = buffer;
|
|
|
|
ws->buflen = buflen;
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
/* Parse the hostname (with optional port number) and filename
|
|
|
|
* from the URL.
|
|
|
|
*/
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2020-05-25 16:22:55 +02:00
|
|
|
ret = parseurl(url, ws);
|
2011-03-19 22:04:13 +01:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2020-05-25 16:22:55 +02:00
|
|
|
nwarn("WARNING: Malformed URL: %s\n", url);
|
2020-04-22 10:29:02 +02:00
|
|
|
free(ws);
|
2020-05-07 22:07:08 +02:00
|
|
|
errno = -ret;
|
2011-03-19 22:04:13 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
2012-11-03 01:00:56 +01:00
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
ninfo("hostname='%s' filename='%s'\n", ws->hostname, ws->filename);
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
/* The following sequence may repeat indefinitely if we are redirected */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2020-05-25 16:22:55 +02:00
|
|
|
if (strcmp(ws->scheme, "http"))
|
|
|
|
{
|
|
|
|
nerr("ERROR: unsupported scheme: %s\n", ws->scheme);
|
|
|
|
free(ws);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2011-03-19 22:04:13 +01:00
|
|
|
/* Re-initialize portions of the state structure that could have
|
|
|
|
* been left from the previous time through the loop and should not
|
|
|
|
* persist with the new connection.
|
|
|
|
*/
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
ws->httpstatus = HTTPSTATUS_NONE;
|
|
|
|
ws->offset = 0;
|
|
|
|
ws->datend = 0;
|
|
|
|
ws->ndx = 0;
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
/* Create a socket */
|
|
|
|
|
|
|
|
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if (sockfd < 0)
|
|
|
|
{
|
|
|
|
/* socket failed. It will set the errno appropriately */
|
|
|
|
|
2016-06-11 23:51:27 +02:00
|
|
|
nerr("ERROR: socket failed: %d\n", errno);
|
2020-04-22 10:29:02 +02:00
|
|
|
free(ws);
|
2011-03-19 22:04:13 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2014-09-30 01:10:49 +02:00
|
|
|
/* Set send and receive timeout values */
|
|
|
|
|
|
|
|
tv.tv_sec = CONFIG_WEBCLIENT_TIMEOUT;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (FAR const void *)&tv,
|
|
|
|
sizeof(struct timeval));
|
|
|
|
setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (FAR const void *)&tv,
|
|
|
|
sizeof(struct timeval));
|
2014-09-30 01:10:49 +02:00
|
|
|
|
|
|
|
/* Get the server address from the host name */
|
2011-03-19 22:04:13 +01:00
|
|
|
|
|
|
|
server.sin_family = AF_INET;
|
2020-04-22 10:29:02 +02:00
|
|
|
server.sin_port = htons(ws->port);
|
|
|
|
ret = wget_gethostip(ws->hostname, &server.sin_addr);
|
2011-03-19 22:04:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* Could not resolve host (or malformed IP address) */
|
|
|
|
|
2016-06-15 01:53:47 +02:00
|
|
|
nwarn("WARNING: Failed to resolve hostname\n");
|
2011-03-19 22:04:13 +01:00
|
|
|
ret = -EHOSTUNREACH;
|
|
|
|
goto errout_with_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connect to server. First we have to set some fields in the
|
|
|
|
* 'server' address structure. The system will assign me an arbitrary
|
|
|
|
* local port that is not in use.
|
|
|
|
*/
|
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
ret = connect(sockfd, (struct sockaddr *)&server,
|
|
|
|
sizeof(struct sockaddr_in));
|
2011-03-19 22:04:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:51:27 +02:00
|
|
|
nerr("ERROR: connect failed: %d\n", errno);
|
2011-03-19 22:04:13 +01:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the GET request */
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
dest = ws->buffer;
|
2012-11-03 01:00:56 +01:00
|
|
|
if (mode == WGET_MODE_POST)
|
|
|
|
{
|
|
|
|
dest = wget_strcpy(dest, g_httppost);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dest = wget_strcpy(dest, g_httpget);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef WGET_USE_URLENCODE
|
2020-04-22 10:29:02 +02:00
|
|
|
dest = wget_strcpy(dest, ws->filename);
|
2012-11-03 01:00:56 +01:00
|
|
|
#else
|
2020-04-22 13:36:07 +02:00
|
|
|
/* TODO: should we use wget_urlencode_strcpy? */
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
dest = wget_strcpy(dest, ws->filename);
|
2012-11-03 01:00:56 +01:00
|
|
|
#endif
|
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
*dest++ = ISO_SPACE;
|
2012-11-03 01:00:56 +01:00
|
|
|
dest = wget_strcpy(dest, g_http10);
|
|
|
|
dest = wget_strcpy(dest, g_httpcrnl);
|
|
|
|
dest = wget_strcpy(dest, g_httphost);
|
2020-04-22 10:29:02 +02:00
|
|
|
dest = wget_strcpy(dest, ws->hostname);
|
2012-11-03 01:00:56 +01:00
|
|
|
dest = wget_strcpy(dest, g_httpcrnl);
|
|
|
|
|
|
|
|
if (mode == WGET_MODE_POST)
|
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
int post_len;
|
|
|
|
char post_size[8];
|
|
|
|
|
2012-11-03 01:00:56 +01:00
|
|
|
dest = wget_strcpy(dest, g_httpform);
|
|
|
|
dest = wget_strcpy(dest, g_httpcrnl);
|
|
|
|
dest = wget_strcpy(dest, g_httpcontsize);
|
|
|
|
|
|
|
|
/* Post content size */
|
|
|
|
|
|
|
|
post_len = strlen((char *)posts);
|
2020-04-22 10:29:02 +02:00
|
|
|
sprintf(post_size, "%d", post_len);
|
2012-11-03 01:00:56 +01:00
|
|
|
dest = wget_strcpy(dest, post_size);
|
|
|
|
dest = wget_strcpy(dest, g_httpcrnl);
|
|
|
|
}
|
|
|
|
|
|
|
|
dest = wget_strcpy(dest, g_httpuseragentfields);
|
|
|
|
if (mode == WGET_MODE_POST)
|
|
|
|
{
|
|
|
|
dest = wget_strcpy(dest, (char *)posts);
|
|
|
|
}
|
|
|
|
|
|
|
|
len = dest - buffer;
|
|
|
|
|
|
|
|
ret = send(sockfd, buffer, len, 0);
|
2011-03-19 22:04:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:51:27 +02:00
|
|
|
nerr("ERROR: send failed: %d\n", errno);
|
2011-03-19 22:04:13 +01:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now loop to get the file sent in response to the GET. This
|
|
|
|
* loop continues until either we read the end of file (nbytes == 0)
|
|
|
|
* or until we detect that we have been redirected.
|
|
|
|
*/
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
ws->state = WEBCLIENT_STATE_STATUSLINE;
|
2011-03-19 22:04:13 +01:00
|
|
|
redirected = false;
|
2020-04-22 13:36:07 +02:00
|
|
|
for (; ; )
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
ws->datend = recv(sockfd, ws->buffer, ws->buflen, 0);
|
|
|
|
if (ws->datend < 0)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2016-06-11 23:51:27 +02:00
|
|
|
nerr("ERROR: recv failed: %d\n", errno);
|
2020-04-22 10:29:02 +02:00
|
|
|
ret = ws->datend;
|
2011-03-19 22:04:13 +01:00
|
|
|
goto errout_with_errno;
|
|
|
|
}
|
2020-04-22 10:29:02 +02:00
|
|
|
else if (ws->datend == 0)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2016-06-11 19:55:38 +02:00
|
|
|
ninfo("Connection lost\n");
|
2012-10-06 16:50:37 +02:00
|
|
|
close(sockfd);
|
2011-03-19 22:04:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle initial parsing of the status line */
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
ws->offset = 0;
|
|
|
|
if (ws->state == WEBCLIENT_STATE_STATUSLINE)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
ret = wget_parsestatus(ws);
|
2011-03-19 22:04:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse the HTTP data */
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
if (ws->state == WEBCLIENT_STATE_HEADERS)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
ret = wget_parseheaders(ws);
|
2011-03-19 22:04:13 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dispose of the data payload */
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
if (ws->state == WEBCLIENT_STATE_DATA)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
if (ws->httpstatus != HTTPSTATUS_MOVED)
|
2011-03-19 22:04:13 +01:00
|
|
|
{
|
2020-04-22 13:36:07 +02:00
|
|
|
/* Let the client decide what to do with the
|
|
|
|
* received file.
|
|
|
|
*/
|
2011-03-19 22:04:13 +01:00
|
|
|
|
2020-04-22 13:36:07 +02:00
|
|
|
callback(&ws->buffer, ws->offset, ws->datend,
|
|
|
|
&buflen, arg);
|
2011-03-19 22:04:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
redirected = true;
|
2020-05-25 16:21:07 +02:00
|
|
|
nredirect++;
|
|
|
|
if (nredirect > CONFIG_WEBCLIENT_MAX_REDIRECT)
|
|
|
|
{
|
|
|
|
nerr("ERROR: too many redirects (%u)\n", nredirect);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2012-10-06 16:50:37 +02:00
|
|
|
close(sockfd);
|
2011-03-19 22:04:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (redirected);
|
2014-09-30 01:10:49 +02:00
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
free(ws);
|
2011-03-19 22:04:13 +01:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
errout_with_errno:
|
2020-05-07 22:07:08 +02:00
|
|
|
errno = -ret;
|
2011-03-19 22:04:13 +01:00
|
|
|
errout:
|
|
|
|
close(sockfd);
|
2020-04-22 10:29:02 +02:00
|
|
|
free(ws);
|
2011-03-19 22:04:13 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
2012-11-03 01:00:56 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: web_post_str
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-11-06 17:59:45 +01:00
|
|
|
#ifdef WGET_USE_URLENCODE
|
2012-11-03 01:00:56 +01:00
|
|
|
char *web_post_str(FAR char *buffer, int *size, FAR char *name,
|
|
|
|
FAR char *value)
|
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
char *dst = buffer;
|
|
|
|
buffer = wget_strcpy(buffer, name);
|
2012-11-03 01:00:56 +01:00
|
|
|
buffer = wget_strcpy(buffer, "=");
|
2020-04-22 10:29:02 +02:00
|
|
|
buffer = wget_urlencode_strcpy(buffer, value);
|
2012-11-03 01:00:56 +01:00
|
|
|
*size = buffer - dst;
|
|
|
|
return dst;
|
|
|
|
}
|
2012-11-06 17:59:45 +01:00
|
|
|
#endif
|
2012-11-03 01:00:56 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: web_post_strlen
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-11-06 17:59:45 +01:00
|
|
|
#ifdef WGET_USE_URLENCODE
|
2012-11-03 01:00:56 +01:00
|
|
|
int web_post_strlen(FAR char *name, FAR char *value)
|
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
return strlen(name) + urlencode_len(value, strlen(value)) + 1;
|
2012-11-03 01:00:56 +01:00
|
|
|
}
|
2012-11-06 17:59:45 +01:00
|
|
|
#endif
|
2012-11-03 01:00:56 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: web_posts_str
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-11-06 17:59:45 +01:00
|
|
|
#ifdef WGET_USE_URLENCODE
|
2012-11-03 01:00:56 +01:00
|
|
|
char *web_posts_str(FAR char *buffer, int *size, FAR char **name,
|
|
|
|
FAR char **value, int len)
|
|
|
|
{
|
2020-04-22 10:29:02 +02:00
|
|
|
char *dst = buffer;
|
2012-11-03 01:00:56 +01:00
|
|
|
int wlen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
2020-04-22 13:36:07 +02:00
|
|
|
buffer = wget_strcpy(buffer, "&");
|
2012-11-03 01:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
wlen = *size;
|
|
|
|
buffer = web_post_str(buffer, &wlen, name[i], value[i]);
|
|
|
|
buffer += wlen;
|
|
|
|
}
|
|
|
|
|
2020-04-22 10:29:02 +02:00
|
|
|
*size = buffer - dst;
|
2012-11-03 01:00:56 +01:00
|
|
|
return dst;
|
|
|
|
}
|
2012-11-06 17:59:45 +01:00
|
|
|
#endif
|
2012-11-03 01:00:56 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: web_posts_strlen
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-11-06 17:59:45 +01:00
|
|
|
#ifdef WGET_USE_URLENCODE
|
2012-11-03 01:00:56 +01:00
|
|
|
int web_posts_strlen(FAR char **name, FAR char **value, int len)
|
|
|
|
{
|
|
|
|
int wlen = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
wlen += web_post_strlen(name[i], value[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return wlen + len - 1;
|
|
|
|
}
|
2012-11-06 17:59:45 +01:00
|
|
|
#endif
|
2012-11-03 01:00:56 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: wget
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Obtain the requested file from an HTTP server using the GET method.
|
|
|
|
*
|
|
|
|
* Input Parameters
|
|
|
|
* url - A pointer to a string containing either the full URL to
|
|
|
|
* the file to get (e.g., http://www.nutt.org/index.html, or
|
|
|
|
* http://192.168.23.1:80/index.html).
|
|
|
|
* buffer - A user provided buffer to receive the file data (also
|
|
|
|
* used for the outgoing GET request
|
|
|
|
* buflen - The size of the user provided buffer
|
|
|
|
* callback - As data is obtained from the host, this function is
|
|
|
|
* to dispose of each block of file data as it is received.
|
2020-04-22 10:29:02 +02:00
|
|
|
* arg - User argument passed to callback.
|
2012-11-03 01:00:56 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0: if the GET operation completed successfully;
|
|
|
|
* -1: On a failure with errno set appropriately
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int wget(FAR const char *url, FAR char *buffer, int buflen,
|
|
|
|
wget_callback_t callback, FAR void *arg)
|
|
|
|
{
|
|
|
|
return wget_base(url, buffer, buflen, callback, arg, NULL, WGET_MODE_GET);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-11-06 17:59:45 +01:00
|
|
|
* Name: wget_post
|
2012-11-03 01:00:56 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int wget_post(FAR const char *url, FAR const char *posts, FAR char *buffer,
|
|
|
|
int buflen, wget_callback_t callback, FAR void *arg)
|
|
|
|
{
|
2020-04-22 13:36:07 +02:00
|
|
|
return wget_base(url, buffer, buflen, callback, arg, posts,
|
|
|
|
WGET_MODE_POST);
|
2012-11-03 01:00:56 +01:00
|
|
|
}
|