wget now takes only a URL as a argument; not host + file name
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1654 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
68f8ca16e2
commit
4d00519a5a
|
@ -353,8 +353,7 @@ examples/wget
|
|||
A simple web client example. It will obtain a file from a server using the HTTP
|
||||
protocol. Settings unique to this example include:
|
||||
|
||||
CONFIG_EXAMPLE_WGET_HOSTNAME - The host that serves the file
|
||||
CONFIG_EXAMPLE_WGET_FILENAME - The name of the file to get (with leading '/')
|
||||
CONFIG_EXAMPLE_WGET_URL - The URL of the file to get
|
||||
CONFIG_EXAMPLE_WGET_NOMAC - (May be defined to use software assigned MAC)
|
||||
CONFIG_EXAMPLE_WGET_IPADDR - Target IP address
|
||||
CONFIG_EXAMPLE_WGET_DRIPADDR - Default router IP addess
|
||||
|
|
|
@ -37,12 +37,12 @@ WD = ${shell pwd}
|
|||
TOPDIR = $(WD)/../..
|
||||
include $(TOPDIR)/Make.defs
|
||||
|
||||
OBJS = host.o1 webclient.o1
|
||||
OBJS = host.o1 webclient.o1 uip_parsehttpurl.o1
|
||||
BIN = wget
|
||||
|
||||
HOSTCFLAGS += -DCONFIG_WEBCLIENT_HOST=1
|
||||
HOSTCFLAGS += -I. -include hostdefs.h
|
||||
VPATH = $(TOPDIR)/netutils/webclient:.
|
||||
VPATH = $(TOPDIR)/netutils/webclient:$(TOPDIR)/netutils/uiplib:.
|
||||
|
||||
all: $(BIN)
|
||||
.PHONY: clean context clean_context distclean
|
||||
|
@ -56,11 +56,22 @@ net/uip:
|
|||
net/uip/webclient.h: net/uip $(TOPDIR)/include/net/uip/webclient.h
|
||||
@cp -a $(TOPDIR)/include/net/uip/webclient.h net/uip/.
|
||||
|
||||
$(BIN): net/uip/webclient.h $(OBJS)
|
||||
net/uip/uip-lib.h: net/uip $(TOPDIR)/include/net/uip/uip-lib.h
|
||||
@cp -a $(TOPDIR)/include/net/uip/uip-lib.h net/uip/.
|
||||
|
||||
nuttx:
|
||||
@mkdir nuttx
|
||||
|
||||
nuttx/config.h: nuttx
|
||||
@touch nuttx/config.h
|
||||
|
||||
headers: net/uip/webclient.h net/uip/uip-lib.h nuttx/config.h
|
||||
|
||||
$(BIN): headers $(OBJS)
|
||||
$(HOSTCC) $(HOSTLDFLAGS) $(OBJS) -o $@
|
||||
|
||||
clean:
|
||||
@rm -f $(BIN).* *.o1 *~
|
||||
@rm -rf net
|
||||
@rm -rf net nuttx
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
|
@ -66,7 +67,7 @@ static void callback(FAR char **buffer, int offset, int datend, FAR int *buflen)
|
|||
|
||||
static void show_usage(const char *progname, int exitcode)
|
||||
{
|
||||
fprintf(stderr, "USAGE: %s <host> <filename>\n", progname);
|
||||
fprintf(stderr, "USAGE: %s <url>\n", progname);
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
|
@ -80,13 +81,18 @@ static void show_usage(const char *progname, int exitcode)
|
|||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
char buffer[1024];
|
||||
int ret;
|
||||
|
||||
if (argc != 3)
|
||||
if (argc != 2)
|
||||
{
|
||||
show_usage(argv[0], 1);
|
||||
}
|
||||
|
||||
printf("WGET: Getting %s from %s\n", argv[2], argv[1]);
|
||||
wget(80, argv[1], argv[2], buffer, 1024, callback);
|
||||
printf("WGET: Getting %s\n", argv[1]);
|
||||
ret = wget(argv[1], buffer, 1024, callback);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "WGET: wget failed: %s\n", strerror(errno));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,50 @@
|
|||
/****************************************************************************
|
||||
* examples/wget/hostdefs.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* 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. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "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
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __HOSTDEFS_H
|
||||
#define __HOSTDEFS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
*****************************************************************************/
|
||||
|
||||
# include <stdio.h>
|
||||
|
||||
typedef unsigned char ubyte;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint32;
|
||||
typedef unsigned char boolean;
|
||||
/****************************************************************************
|
||||
* Preprocessor Defintiions
|
||||
*****************************************************************************/
|
||||
|
||||
# define HTONS(a) htons(a)
|
||||
# define HTONL(a) htonl(a)
|
||||
|
@ -22,4 +60,16 @@ typedef unsigned char boolean;
|
|||
# define ERROR (-1)
|
||||
# define OK (0)
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
*****************************************************************************/
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned char ubyte;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint32;
|
||||
typedef unsigned char boolean;
|
||||
|
||||
typedef void *(*pthread_startroutine_t)(void *);
|
||||
|
||||
#endif /* __HOSTDEFS_H */
|
||||
|
|
|
@ -155,6 +155,6 @@ int user_start(int argc, char *argv[])
|
|||
|
||||
/* Then start the server */
|
||||
|
||||
wget(80, CONFIG_EXAMPLE_WGET_HOSTNAME, CONFIG_EXAMPLE_WGET_FILENAME, g_iobuffer, 512, callback);
|
||||
wget(CONFIG_EXAMPLE_WGET_URL, g_iobuffer, 512, callback);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -122,10 +122,9 @@ extern "C" {
|
|||
* query answer.
|
||||
*
|
||||
* Input Parameters
|
||||
* port - The port number to which to connect, in host byte order.
|
||||
* hostname - A pointer to a string containing either a host name or
|
||||
* a numerical IP address in dotted decimal notation (e.g., 192.168.23.1).
|
||||
* filename - A pointer to the name of the file to get.
|
||||
* 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
|
||||
|
@ -138,9 +137,8 @@ extern "C" {
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int wget(uint16 port,
|
||||
FAR const char *hostname, FAR const char *filename,
|
||||
FAR char *buffer, int buflen, wget_callback_t callback);
|
||||
EXTERN int wget(FAR const char *url, FAR char *buffer, int buflen,
|
||||
wget_callback_t callback);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Reference in New Issue