2 Commits

Author SHA1 Message Date
5c4fc93d5f Merge branch 'master' into hjelmeland-patch-1 2023-11-10 09:12:04 +03:00
ccef3bc4e2 Changed return text for ETIMEDOUT/ WSAETIMEDOUT
Changed return text for ETIMEDOUT/ WSAETIMEDOUT to “connection timeout”.

This is needed for the application to be able tell to the difference between timeout of TCP connection (ETIMEDOUT/ WSAETIMEDOUT) and a normal return from a non-blocking socket (error codes EAGAIN/WSAEWOULDBLOCK). Both situations returned the text “timeout”.
2015-09-03 15:24:22 +02:00
46 changed files with 169 additions and 1437 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
*.o *.o
*.so *.so
*.so.* *.so.*
*.a
*.obj *.obj
*.lib *.lib
*.dll* *.dll*

0
Lua.props Normal file → Executable file
View File

View File

@ -55,7 +55,7 @@ protocol. For that, check the implementation.
<p> <p>
To really benefit from this module, a good understanding of To really benefit from this module, a good understanding of
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md"> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
LTN012, Filters sources and sinks</a> is necessary. LTN012, Filters sources and sinks</a> is necessary.
</p> </p>
@ -122,7 +122,7 @@ expects at least the fields <tt>host</tt>, <tt>sink</tt>, and one of
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes <tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
precedence). <tt>Host</tt> is the server to connect to. <tt>Sink</tt> is precedence). <tt>Host</tt> is the server to connect to. <tt>Sink</tt> is
the <em>simple</em> the <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
sink that will receive the downloaded data. <tt>Argument</tt> or sink that will receive the downloaded data. <tt>Argument</tt> or
<tt>path</tt> give the target path to the resource in the server. The <tt>path</tt> give the target path to the resource in the server. The
optional arguments are the following: optional arguments are the following:
@ -136,7 +136,7 @@ authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";</li>
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or <li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
"<tt>a</tt>". Defaults to whatever is the server default;</li> "<tt>a</tt>". Defaults to whatever is the server default;</li>
<li><tt>step</tt>: <li><tt>step</tt>:
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
pump step function used to pass data from the pump step function used to pass data from the
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li> server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
<li><tt>create</tt>: An optional function to be used instead of <li><tt>create</tt>: An optional function to be used instead of
@ -206,7 +206,7 @@ expects at least the fields <tt>host</tt>, <tt>source</tt>, and one of
<tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes <tt>argument</tt> or <tt>path</tt> (<tt>argument</tt> takes
precedence). <tt>Host</tt> is the server to connect to. <tt>Source</tt> is precedence). <tt>Host</tt> is the server to connect to. <tt>Source</tt> is
the <em>simple</em> the <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
source that will provide the contents to be uploaded. source that will provide the contents to be uploaded.
<tt>Argument</tt> or <tt>Argument</tt> or
<tt>path</tt> give the target path to the resource in the server. The <tt>path</tt> give the target path to the resource in the server. The
@ -221,7 +221,7 @@ authentication. Defaults to "<tt>ftp:anonymous@anonymous.org</tt>";</li>
<li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or <li><tt>type</tt>: The transfer mode. Can take values "<tt>i</tt>" or
"<tt>a</tt>". Defaults to whatever is the server default;</li> "<tt>a</tt>". Defaults to whatever is the server default;</li>
<li><tt>step</tt>: <li><tt>step</tt>:
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
pump step function used to pass data from the pump step function used to pass data from the
server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li> server to the sink. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
<li><tt>create</tt>: An optional function to be used instead of <li><tt>create</tt>: An optional function to be used instead of

View File

@ -52,7 +52,7 @@ implementation conforms to the HTTP/1.1 standard,
The module exports functions that provide HTTP functionality in different The module exports functions that provide HTTP functionality in different
levels of abstraction. From the simple levels of abstraction. From the simple
string oriented requests, through generic string oriented requests, through generic
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> based, down to even lower-level if you bother to look through the source code. <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based, down to even lower-level if you bother to look through the source code.
</p> </p>
<p> <p>
@ -144,7 +144,7 @@ http.<b>request{</b><br>
The request function has two forms. The simple form downloads The request function has two forms. The simple form downloads
a URL using the <tt>GET</tt> or <tt>POST</tt> method and is based a URL using the <tt>GET</tt> or <tt>POST</tt> method and is based
on strings. The generic form performs any HTTP method and is on strings. The generic form performs any HTTP method and is
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> based. <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> based.
</p> </p>
<p class="parameters"> <p class="parameters">
@ -158,7 +158,7 @@ in the <tt>url</tt>. Otherwise, it performs a <tt>GET</tt> in the
<p class="parameters"> <p class="parameters">
If the first argument is instead a table, the most important fields are If the first argument is instead a table, the most important fields are
the <tt>url</tt> and the <em>simple</em> the <tt>url</tt> and the <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
<tt>sink</tt> that will receive the downloaded content. <tt>sink</tt> that will receive the downloaded content.
Any part of the <tt>url</tt> can be overridden by including Any part of the <tt>url</tt> can be overridden by including
the appropriate field in the request table. the appropriate field in the request table.
@ -172,13 +172,13 @@ following:
<li><tt>method</tt>: The HTTP request method. Defaults to "GET";</li> <li><tt>method</tt>: The HTTP request method. Defaults to "GET";</li>
<li><tt>headers</tt>: Any additional HTTP headers to send with the request;</li> <li><tt>headers</tt>: Any additional HTTP headers to send with the request;</li>
<li><tt>source</tt>: <em>simple</em> <li><tt>source</tt>: <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
source to provide the request body. If there source to provide the request body. If there
is a body, you need to provide an appropriate "<tt>content-length</tt>" is a body, you need to provide an appropriate "<tt>content-length</tt>"
request header field, or the function will attempt to send the body as request header field, or the function will attempt to send the body as
"<tt>chunked</tt>" (something few servers support). Defaults to the empty source;</li> "<tt>chunked</tt>" (something few servers support). Defaults to the empty source;</li>
<li><tt>step</tt>: <li><tt>step</tt>:
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
pump step function used to move data. pump step function used to move data.
Defaults to the LTN12 <tt>pump.step</tt> function.</li> Defaults to the LTN12 <tt>pump.step</tt> function.</li>
<li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy;</li> <li><tt>proxy</tt>: The URL of a proxy server to use. Defaults to no proxy;</li>

View File

@ -89,7 +89,7 @@ it should be easy to use LuaSocket. Just fire the interpreter and use the
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
&gt; socket = require("socket") &gt; socket = require("socket")
&gt; print(socket._VERSION) &gt; print(socket._VERSION)
--&gt; LuaSocket 3.1.0 --&gt; LuaSocket 3.0.0
</pre> </pre>
<p> Each module loads their dependencies automatically, so you only need to <p> Each module loads their dependencies automatically, so you only need to

View File

@ -40,7 +40,7 @@ Pump, Support, Library">
<h2 id="ltn12">LTN12</h2> <h2 id="ltn12">LTN12</h2>
<p> The <tt>ltn12</tt> namespace implements the ideas described in <p> The <tt>ltn12</tt> namespace implements the ideas described in
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md"> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
LTN012, Filters sources and sinks</a>. This manual simply describes the LTN012, Filters sources and sinks</a>. This manual simply describes the
functions. Please refer to the LTN for a deeper explanation of the functions. Please refer to the LTN for a deeper explanation of the
functionality provided by this module. functionality provided by this module.

View File

@ -54,7 +54,7 @@ MIME is described mainly in
<p> <p>
All functionality provided by the MIME module All functionality provided by the MIME module
follows the ideas presented in follows the ideas presented in
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md"> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">
LTN012, Filters sources and sinks</a>. LTN012, Filters sources and sinks</a>.
</p> </p>

View File

@ -57,7 +57,7 @@ of the MIME standard, but described mainly
in <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>.</p> in <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>.</p>
<p> In the description below, good understanding of <a <p> In the description below, good understanding of <a
href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md"> LTN012, Filters href="http://lua-users.org/wiki/FiltersSourcesAndSinks"> LTN012, Filters
sources and sinks</a> and the <a href="mime.html">MIME</a> module is sources and sinks</a> and the <a href="mime.html">MIME</a> module is
assumed. In fact, the SMTP module was the main reason for their assumed. In fact, the SMTP module was the main reason for their
creation. </p> creation. </p>
@ -122,7 +122,7 @@ smtp.<b>message(</b>mesgt<b>)</b>
<p class="description"> <p class="description">
Returns a <em>simple</em> Returns a <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep). <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a> source that sends an SMTP message body, possibly multipart (arbitrarily deep).
</p> </p>
<p class="parameters"> <p class="parameters">
@ -155,7 +155,7 @@ multipart-mesgt = {<br>
For a simple message, all that is needed is a set of <tt>headers</tt> For a simple message, all that is needed is a set of <tt>headers</tt>
and the <tt>body</tt>. The message <tt>body</tt> can be given as a string and the <tt>body</tt>. The message <tt>body</tt> can be given as a string
or as a <em>simple</em> or as a <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
source. For multipart messages, the body is a table that source. For multipart messages, the body is a table that
recursively defines each part as an independent message, plus an optional recursively defines each part as an independent message, plus an optional
<tt>preamble</tt> and <tt>epilogue</tt>. <tt>preamble</tt> and <tt>epilogue</tt>.
@ -163,7 +163,7 @@ recursively defines each part as an independent message, plus an optional
<p class="return"> <p class="return">
The function returns a <em>simple</em> The function returns a <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
source that produces the source that produces the
message contents as defined by <tt>mesgt</tt>, chunk by chunk. message contents as defined by <tt>mesgt</tt>, chunk by chunk.
Hopefully, the following Hopefully, the following
@ -264,7 +264,7 @@ The sender is given by the e-mail address in the <tt>from</tt> field.
address, or a string address, or a string
in case there is just one recipient. in case there is just one recipient.
The contents of the message are given by a <em>simple</em> The contents of the message are given by a <em>simple</em>
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
<tt>source</tt>. Several arguments are optional: <tt>source</tt>. Several arguments are optional:
</p> </p>
<ul> <ul>
@ -276,7 +276,7 @@ methods if supported by the server (both are unsafe);</li>
<li> <tt>domain</tt>: Domain name used to greet the server; Defaults to the <li> <tt>domain</tt>: Domain name used to greet the server; Defaults to the
local machine host name;</li> local machine host name;</li>
<li> <tt>step</tt>: <li> <tt>step</tt>:
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
pump step function used to pass data from the pump step function used to pass data from the
source to the server. Defaults to the LTN12 <tt>pump.step</tt> function;</li> source to the server. Defaults to the LTN12 <tt>pump.step</tt> function;</li>
<li><tt>create</tt>: An optional function to be used instead of <li><tt>create</tt>: An optional function to be used instead of
@ -308,7 +308,7 @@ Only recipients specified in the <tt>rcpt</tt> list will receive a copy of the
message. Each recipient of an SMTP mail message receives a copy of the message. Each recipient of an SMTP mail message receives a copy of the
message body along with the headers, and nothing more. The headers message body along with the headers, and nothing more. The headers
<em>are</em> part of the message and should be produced by the <em>are</em> part of the message and should be produced by the
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
<tt>source</tt> function. The <tt>rcpt</tt> list is <em>not</em> <tt>source</tt> function. The <tt>rcpt</tt> list is <em>not</em>
part of the message and will not be sent to anyone. part of the message and will not be sent to anyone.
</p> </p>

View File

@ -164,9 +164,6 @@ Creates and returns a <em>clean</em>
<a href="#try"><tt>try</tt></a> <a href="#try"><tt>try</tt></a>
function that allows for cleanup before the exception function that allows for cleanup before the exception
is raised. is raised.
This implements the ideas described in
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
LTN012, Using finalized exceptions</a>.
</p> </p>
<p class="parameters"> <p class="parameters">
@ -210,9 +207,6 @@ Converts a function that throws exceptions into a safe function. This
function only catches exceptions thrown by the <a href="#try"><tt>try</tt></a> function only catches exceptions thrown by the <a href="#try"><tt>try</tt></a>
and <a href="#newtry"><tt>newtry</tt></a> functions. It does not catch normal and <a href="#newtry"><tt>newtry</tt></a> functions. It does not catch normal
Lua errors. Lua errors.
This implements the ideas described in
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
LTN012, Using finalized exceptions</a>.
</p> </p>
<p class="parameters"> <p class="parameters">
@ -311,7 +305,7 @@ socket.<b>sink(</b>mode, socket<b>)</b>
<p class="description"> <p class="description">
Creates an Creates an
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
sink from a stream socket object. sink from a stream socket object.
</p> </p>
@ -386,7 +380,7 @@ socket.<b>source(</b>mode, socket [, length]<b>)</b>
<p class="description"> <p class="description">
Creates an Creates an
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn012.md">LTN12</a> <a href="http://lua-users.org/wiki/FiltersSourcesAndSinks">LTN12</a>
source from a stream socket object. source from a stream socket object.
</p> </p>
@ -431,9 +425,6 @@ socket.<b>try(</b>ret<sub>1</sub> [, ret<sub>2</sub> ... ret<sub>N</sub>]<b>)</b
Throws an exception in case <tt>ret<sub>1</sub></tt> is falsy, using Throws an exception in case <tt>ret<sub>1</sub></tt> is falsy, using
<tt>ret<sub>2</sub></tt> as the error message. The exception is supposed to be caught <tt>ret<sub>2</sub></tt> as the error message. The exception is supposed to be caught
by a <a href="#protect"><tt>protect</tt></a>ed function only. by a <a href="#protect"><tt>protect</tt></a>ed function only.
This implements the ideas described in
<a href="https://github.com/lunarmodules/luasocket/blob/master/ltn013.md">
LTN012, Using finalized exceptions</a>.
</p> </p>
<p class="parameters"> <p class="parameters">

View File

@ -69,7 +69,6 @@ local function make_plat(plat)
["socket.smtp"] = "src/smtp.lua", ["socket.smtp"] = "src/smtp.lua",
ltn12 = "src/ltn12.lua", ltn12 = "src/ltn12.lua",
socket = "src/socket.lua", socket = "src/socket.lua",
mbox = "src/mbox.lua",
mime = "src/mime.lua" mime = "src/mime.lua"
} }
if plat == "unix" if plat == "unix"

4
makefile Normal file → Executable file
View File

@ -10,11 +10,11 @@
# print print the build settings # print print the build settings
PLAT?= linux PLAT?= linux
PLATS= macosx linux win32 win64 mingw freebsd solaris psp PLATS= macosx linux win32 win64 mingw freebsd solaris
all: $(PLAT) all: $(PLAT)
$(PLATS) none install install-unix install-static local clean: $(PLATS) none install install-unix local clean:
$(MAKE) -C src $@ $(MAKE) -C src $@
print: print:

View File

@ -1,7 +1,7 @@
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# Distribution makefile # Distribution makefile
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
DIST = luasocket-3.1.0 DIST = luasocket-3.0.0
TEST = \ TEST = \
test/README \ test/README \

0
mime.vcxproj Normal file → Executable file
View File

0
socket.vcxproj Normal file → Executable file
View File

View File

@ -1,13 +0,0 @@
/*
* This file is needed to compile PSP stubs
*/
#define STDC_HEADERS
#define HAVE_STRING_H
#define HAVE_MEMORY_H
#define HAVE_STDLIB_H
//#define ENABLE_PTHREAD
//#define ENABLE_NLS
#define HAVE_MEMCPY
#include "netdb-compat.h"

View File

@ -1,593 +0,0 @@
/*
* Copyright (c) 2001, 02 Motoyuki Kasahara
*
* 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 of the project 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 PROJECT 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 PROJECT 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.
*/
/*
* This program provides getaddrinfo() and getnameinfo() described in
* RFC2133, 2553 and 3493. These functions are mainly used for IPv6
* application to resolve hostname or address.
*
* This program is designed to be working on traditional IPv4 systems
* which don't have those functions. Therefore, this implementation
* supports IPv4 only.
*
* This program is useful for application which should support both IPv6
* and traditional IPv4 systems. Use genuine getaddrinfo() and getnameinfo()
* provided by system if the system supports IPv6. Otherwise, use this
* implementation.
*
* This program is intended to be used in combination with GNU Autoconf.
*
* This program also provides freeaddrinfo() and gai_strerror().
*
* To use this program in your application, insert the following lines to
* C source files after including `sys/types.h', `sys/socket.h' and
* `netdb.h'. `getaddrinfo.h' defines `struct addrinfo' and AI_, NI_,
* EAI_ macros.
*
* #ifndef HAVE_GETADDRINFO
* #include "getaddrinfo.h"
* #endif
*
* Restriction:
* getaddrinfo() and getnameinfo() of this program are NOT thread
* safe, unless the cpp macro ENABLE_PTHREAD is defined.
*/
/*
* Add the following code to your configure.ac (or configure.in).
* AC_C_CONST
* AC_HEADER_STDC
* AC_CHECK_HEADERS(string.h memory.h stdlib.h)
* AC_CHECK_FUNCS(memcpy)
* AC_REPLACE_FUNCS(memset)
* AC_TYPE_SOCKLEN_T
* AC_TYPE_IN_PORT_T
* AC_DECL_H_ERRNO
*
* AC_CHECK_FUNCS(getaddrinfo getnameinfo)
* if test "$ac_cv_func_getaddrinfo$ac_cv_func_getnameinfo" != yesyes ; then
* LIBOBJS="$LIBOBJS getaddrinfo.$ac_objext"
* fi
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
#include <memory.h>
#endif /* not STDC_HEADERS and HAVE_MEMORY_H */
#else /* not STDC_HEADERS and not HAVE_STRING_H */
#include <strings.h>
#endif /* not STDC_HEADERS and not HAVE_STRING_H */
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef ENABLE_PTHREAD
#include <pthread.h>
#endif
#ifdef ENABLE_NLS
#include <libintl.h>
#endif
#ifndef HAVE_MEMCPY
#define memcpy(d, s, n) bcopy((s), (d), (n))
#ifdef __STDC__
void *memchr(const void *, int, size_t);
int memcmp(const void *, const void *, size_t);
void *memmove(void *, const void *, size_t);
void *memset(void *, int, size_t);
#else /* not __STDC__ */
char *memchr();
int memcmp();
char *memmove();
char *memset();
#endif /* not __STDC__ */
#endif /* not HAVE_MEMCPY */
#ifndef H_ERRNO_DECLARED
extern int h_errno;
#endif
#include "getaddrinfo.h"
#ifdef ENABLE_NLS
#define _(string) gettext(string)
#ifdef gettext_noop
#define N_(string) gettext_noop(string)
#else
#define N_(string) (string)
#endif
#else
#define gettext(string) (string)
#define _(string) (string)
#define N_(string) (string)
#endif
/*
* Error messages for gai_strerror().
*/
static char *eai_errlist[] = {
N_("Success"),
/* EAI_ADDRFAMILY */
N_("Address family for hostname not supported"),
/* EAI_AGAIN */
N_("Temporary failure in name resolution"),
/* EAI_BADFLAGS */
N_("Invalid value for ai_flags"),
/* EAI_FAIL */
N_("Non-recoverable failure in name resolution"),
/* EAI_FAMILY */
N_("ai_family not supported"),
/* EAI_MEMORY */
N_("Memory allocation failure"),
/* EAI_NONAME */
N_("hostname nor servname provided, or not known"),
/* EAI_OVERFLOW */
N_("An argument buffer overflowed"),
/* EAI_SERVICE */
N_("servname not supported for ai_socktype"),
/* EAI_SOCKTYPE */
N_("ai_socktype not supported"),
/* EAI_SYSTEM */
N_("System error returned in errno")
};
/*
* Default hints for getaddrinfo().
*/
static struct addrinfo default_hints = {
0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL
};
/*
* Mutex.
*/
#ifdef ENABLE_PTHREAD
static pthread_mutex_t gai_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
/*
* Declaration of static functions.
*/
#ifdef __STDC__
static int is_integer(const char *);
static int is_address(const char *);
static int itoa_length(int);
#else
static int is_integer();
static int is_address();
static int itoa_length();
#endif
/*
* gai_strerror().
*/
const char *
gai_strerror(ecode)
int ecode;
{
if (ecode < 0 || ecode > EAI_SYSTEM)
return _("Unknown error");
return gettext(eai_errlist[ecode]);
}
/*
* freeaddrinfo().
*/
void
freeaddrinfo(ai)
struct addrinfo *ai;
{
struct addrinfo *next_ai;
while (ai != NULL) {
if (ai->ai_canonname != NULL)
free(ai->ai_canonname);
if (ai->ai_addr != NULL)
free(ai->ai_addr);
next_ai = ai->ai_next;
free(ai);
ai = next_ai;
}
}
/*
* Return 1 if the string `s' represents an integer.
*/
static int
is_integer(s)
const char *s;
{
if (*s == '-' || *s == '+')
s++;
if (*s < '0' || '9' < *s)
return 0;
s++;
while ('0' <= *s && *s <= '9')
s++;
return (*s == '\0');
}
/*
* Return 1 if the string `s' represents an IPv4 address.
* Unlike inet_addr(), it doesn't permit malformed nortation such
* as "192.168".
*/
static int
is_address(s)
const char *s;
{
const static char delimiters[] = {'.', '.', '.', '\0'};
int i, j;
int octet;
for (i = 0; i < 4; i++) {
if (*s == '0' && *(s + 1) != delimiters[i])
return 0;
for (j = 0, octet = 0; '0' <= *s && *s <= '9' && j < 3; s++, j++)
octet = octet * 10 + (*s - '0');
if (j == 0 || octet > 255 || *s != delimiters[i])
return 0;
s++;
}
return 1;
}
/*
* Calcurate length of the string `s', where `s' is set by
* sprintf(s, "%d", n).
*/
static int
itoa_length(n)
int n;
{
int result = 1;
if (n < 0) {
n = -n;
result++;
}
while (n >= 10) {
result++;
n /= 10;
}
return result;
}
/*
* getaddrinfo().
*/
int
getaddrinfo(nodename, servname, hints, res)
const char *nodename;
const char *servname;
const struct addrinfo *hints;
struct addrinfo **res;
{
struct addrinfo *head_res = NULL;
struct addrinfo *tail_res = NULL;
struct addrinfo *new_res;
struct sockaddr_in *sa_in;
struct in_addr **addr_list;
struct in_addr *addr_list_buf[2];
struct in_addr addr_buf;
struct in_addr **ap;
struct servent *servent;
struct hostent *hostent;
const char *canonname = NULL;
in_port_t port;
int saved_h_errno;
int result = 0;
#ifdef ENABLE_PTHREAD
pthread_mutex_lock(&gai_mutex);
#endif
saved_h_errno = h_errno;
if (nodename == NULL && servname == NULL) {
result = EAI_NONAME;
goto end;
}
if (hints != NULL) {
if (hints->ai_family != PF_INET && hints->ai_family != PF_UNSPEC) {
result = EAI_FAMILY;
goto end;
}
if (hints->ai_socktype != SOCK_DGRAM
&& hints->ai_socktype != SOCK_STREAM
&& hints->ai_socktype != 0) {
result = EAI_SOCKTYPE;
goto end;
}
} else {
hints = &default_hints;
}
if (servname != NULL) {
if (is_integer(servname))
port = htons(atoi(servname));
else {
if (hints->ai_flags & AI_NUMERICSERV) {
result = EAI_NONAME;
goto end;
}
if (hints->ai_socktype == SOCK_DGRAM)
servent = getservbyname(servname, "udp");
else if (hints->ai_socktype == SOCK_STREAM)
servent = getservbyname(servname, "tcp");
else if (hints->ai_socktype == 0)
servent = getservbyname(servname, "tcp");
else {
result = EAI_SOCKTYPE;
goto end;
}
if (servent == NULL) {
result = EAI_SERVICE;
goto end;
}
port = servent->s_port;
}
} else {
port = htons(0);
}
if (nodename != NULL) {
if (is_address(nodename)) {
addr_buf.s_addr = inet_addr(nodename);
addr_list_buf[0] = &addr_buf;
addr_list_buf[1] = NULL;
addr_list = addr_list_buf;
if (hints->ai_flags & AI_CANONNAME
&& !(hints->ai_flags & AI_NUMERICHOST)) {
hostent = gethostbyaddr((char *)&addr_buf,
sizeof(struct in_addr), AF_INET);
if (hostent != NULL)
canonname = hostent->h_name;
else
canonname = nodename;
}
} else {
if (hints->ai_flags & AI_NUMERICHOST) {
result = EAI_NONAME;
goto end;
}
hostent = gethostbyname(nodename);
if (hostent == NULL) {
switch (h_errno) {
case HOST_NOT_FOUND:
case NO_DATA:
result = EAI_NONAME;
goto end;
case TRY_AGAIN:
result = EAI_AGAIN;
goto end;
default:
result = EAI_FAIL;
goto end;
}
}
addr_list = (struct in_addr **)hostent->h_addr_list;
if (hints->ai_flags & AI_CANONNAME)
canonname = hostent->h_name;
}
} else {
if (hints->ai_flags & AI_PASSIVE)
addr_buf.s_addr = htonl(INADDR_ANY);
else
addr_buf.s_addr = htonl(0x7F000001);
addr_list_buf[0] = &addr_buf;
addr_list_buf[1] = NULL;
addr_list = addr_list_buf;
}
for (ap = addr_list; *ap != NULL; ap++) {
new_res = (struct addrinfo *)malloc(sizeof(struct addrinfo));
if (new_res == NULL) {
if (head_res != NULL)
freeaddrinfo(head_res);
result = EAI_MEMORY;
goto end;
}
new_res->ai_family = PF_INET;
new_res->ai_socktype = hints->ai_socktype;
new_res->ai_protocol = hints->ai_protocol;
new_res->ai_addr = NULL;
new_res->ai_addrlen = sizeof(struct sockaddr_in);
new_res->ai_canonname = NULL;
new_res->ai_next = NULL;
new_res->ai_addr = (struct sockaddr *)
malloc(sizeof(struct sockaddr_in));
if (new_res->ai_addr == NULL) {
free(new_res);
if (head_res != NULL)
freeaddrinfo(head_res);
result = EAI_MEMORY;
goto end;
}
sa_in = (struct sockaddr_in *)new_res->ai_addr;
memset(sa_in, 0, sizeof(struct sockaddr_in));
sa_in->sin_family = PF_INET;
sa_in->sin_port = port;
memcpy(&sa_in->sin_addr, *ap, sizeof(struct in_addr));
if (head_res == NULL)
head_res = new_res;
else
tail_res->ai_next = new_res;
tail_res = new_res;
}
if (canonname != NULL && head_res != NULL) {
head_res->ai_canonname = (char *)malloc(strlen(canonname) + 1);
if (head_res->ai_canonname != NULL)
strcpy(head_res->ai_canonname, canonname);
}
*res = head_res;
end:
h_errno = saved_h_errno;
#ifdef ENABLE_PTHREAD
pthread_mutex_unlock(&gai_mutex);
#endif
return result;
}
/*
* getnameinfo().
*/
int
getnameinfo(sa, salen, node, nodelen, serv, servlen, flags)
const struct sockaddr *sa;
socklen_t salen;
char *node;
socklen_t nodelen;
char *serv;
socklen_t servlen;
int flags;
{
const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa;
struct hostent *hostent;
struct servent *servent;
char *ntoa_address;
int saved_h_errno;
int result = 0;
#ifdef ENABLE_PTHREAD
pthread_mutex_lock(&gai_mutex);
#endif
saved_h_errno = h_errno;
if (sa_in->sin_family != PF_INET) {
result = EAI_FAMILY;
goto end;
} else if (node == NULL && serv == NULL) {
result = EAI_NONAME;
goto end;
}
if (serv != NULL && servlen > 0) {
if (flags & NI_NUMERICSERV)
servent = NULL;
else if (flags & NI_DGRAM)
servent = getservbyport(sa_in->sin_port, "udp");
else
servent = getservbyport(sa_in->sin_port, "tcp");
if (servent != NULL) {
if (servlen <= strlen(servent->s_name)) {
result = EAI_OVERFLOW;
goto end;
}
strcpy(serv, servent->s_name);
} else {
if (servlen <= itoa_length(ntohs(sa_in->sin_port))) {
result = EAI_OVERFLOW;
goto end;
}
sprintf(serv, "%d", ntohs(sa_in->sin_port));
}
}
if (node != NULL && nodelen > 0) {
if (flags & NI_NUMERICHOST)
hostent = NULL;
else {
hostent = gethostbyaddr((char *)&sa_in->sin_addr,
sizeof(struct in_addr), AF_INET);
}
if (hostent != NULL) {
if (nodelen <= strlen(hostent->h_name)) {
result = EAI_OVERFLOW;
goto end;
}
strcpy(node, hostent->h_name);
} else {
if (flags & NI_NAMEREQD) {
result = EAI_NONAME;
goto end;
}
ntoa_address = inet_ntoa(sa_in->sin_addr);
if (nodelen <= strlen(ntoa_address)) {
result = EAI_OVERFLOW;
goto end;
}
strcpy(node, ntoa_address);
}
}
end:
h_errno = saved_h_errno;
#ifdef ENABLE_PTHREAD
pthread_mutex_unlock(&gai_mutex);
#endif
return result;
}

View File

@ -1,227 +0,0 @@
/*
* Copyright (c) 2001, 02 Motoyuki Kasahara
*
* 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 of the project 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 PROJECT 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 PROJECT 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 GETADDRINFO_H
#define GETADDRINFO_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
/********************************************************************/
/*
* Undefine all the macros.
* <netdb.h> might defines some of them.
*/
#ifdef EAI_ADDRFAMILY
#undef EAI_ADDRFAMILY
#endif
#ifdef EAI_AGAIN
#undef EAI_AGAIN
#endif
#ifdef EAI_BADFLAGS
#undef EAI_BADFLAGS
#endif
#ifdef EAI_FAIL
#undef EAI_FAIL
#endif
#ifdef EAI_FAMILY
#undef EAI_FAMILY
#endif
#ifdef EAI_MEMORY
#undef EAI_MEMORY
#endif
#ifdef EAI_NONAME
#undef EAI_NONAME
#endif
#ifdef EAI_OVERFLOW
#undef EAI_OVERFLOW
#endif
#ifdef EAI_SERVICE
#undef EAI_SERVICE
#endif
#ifdef EAI_SOCKTYPE
#undef EAI_SOCKTYPE
#endif
#ifdef EAI_SYSTEM
#undef EAI_SYSTEM
#endif
#ifdef AI_PASSIVE
#undef AI_PASSIVE
#endif
#ifdef AI_CANONNAME
#undef AI_CANONNAME
#endif
#ifdef AI_NUMERICHOST
#undef AI_NUMERICHOST
#endif
#ifdef AI_NUMERICSERV
#undef AI_NUMERICSERV
#endif
#ifdef AI_V4MAPPED
#undef AI_V4MAPPED
#endif
#ifdef AI_ALL
#undef AI_ALL
#endif
#ifdef AI_ADDRCONFIG
#undef AI_ADDRCONFIG
#endif
#ifdef AI_DEFAULT
#undef AI_DEFAULT
#endif
#ifdef NI_NOFQDN
#undef NI_NOFQDN
#endif
#ifdef NI_NUMERICHOST
#undef NI_NUMERICHOST
#endif
#ifdef NI_NAMEREQD
#undef NI_NAMEREQD
#endif
#ifdef NI_NUMERICSERV
#undef NI_NUMERICSERV
#endif
#ifdef NI_NUMERICSCOPE
#undef NI_NUMERICSCOPE
#endif
#ifdef NI_DGRAM
#undef NI_DGRAM
#endif
#ifdef NI_MAXHOST
#undef NI_MAXHOST
#endif
#ifdef NI_MAXSERV
#undef NI_MAXSERV
#endif
/*
* Fake struct and function names.
* <netdb.h> might declares all or some of them.
*/
#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO)
#define addrinfo my_addrinfo
#define gai_strerror my_gai_strerror
#define freeaddrinfo my_freeaddrinfo
#define getaddrinfo my_getaddrinfo
#define getnameinfo my_getnameinfo
#endif
/********************************************************************/
/*
* Error codes.
*/
#define EAI_ADDRFAMILY 1
#define EAI_AGAIN 2
#define EAI_BADFLAGS 3
#define EAI_FAIL 4
#define EAI_FAMILY 5
#define EAI_MEMORY 6
#define EAI_NONAME 7
#define EAI_OVERFLOW 8
#define EAI_SERVICE 9
#define EAI_SOCKTYPE 10
#define EAI_SYSTEM 11
/*
* Flags for getaddrinfo().
*/
#define AI_ADDRCONFIG 0x0001
#define AI_ALL 0x0002
#define AI_CANONNAME 0x0004
#define AI_NUMERICHOST 0x0008
#define AI_NUMERICSERV 0x0010
#define AI_PASSIVE 0x0020
#define AI_V4MAPPED 0x0040
#define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
/*
* Flags for getnameinfo().
*/
#define NI_DGRAM 0x0001
#define NI_NAMEREQD 0x0002
#define NI_NOFQDN 0x0004
#define NI_NUMERICHOST 0x0008
#define NI_NUMERICSCOPE 0x0010
#define NI_NUMERICSERV 0x0020
/*
* Maximum length of FQDN and servie name for getnameinfo().
*/
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
/*
* Address families and Protocol families.
*/
#ifndef AF_UNSPEC
#define AF_UNSPEC AF_INET
#endif
#ifndef PF_UNSPEC
#define PF_UNSPEC PF_INET
#endif
/*
* struct addrinfo.
*/
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
socklen_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
/*
* Functions.
*/
#ifdef __STDC__
const char *gai_strerror(int);
void freeaddrinfo(struct addrinfo *);
int getaddrinfo(const char *, const char *, const struct addrinfo *,
struct addrinfo **);
int getnameinfo(const struct sockaddr *, socklen_t, char *,
socklen_t, char *, socklen_t, int);
#else
const char *gai_strerror();
void freeaddrinfo();
int getaddrinfo();
int getnameinfo();
#endif
#endif /* not GETADDRINFO_H */

View File

@ -54,7 +54,7 @@ local function receiveheaders(sock, headers)
while line ~= "" do while line ~= "" do
-- get field-name and value -- get field-name and value
name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)")) name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
if not (name and value) then return nil, "malformed response headers" end if not (name and value) then return nil, "malformed reponse headers" end
name = string.lower(name) name = string.lower(name)
-- get next line (value might be folded) -- get next line (value might be folded)
line, err = sock:receive() line, err = sock:receive()
@ -62,7 +62,7 @@ local function receiveheaders(sock, headers)
-- unfold any folded values -- unfold any folded values
while string.find(line, "^%s") do while string.find(line, "^%s") do
value = value .. line value = value .. line
line, err = sock:receive() line = sock:receive()
if err then return nil, err end if err then return nil, err end
end end
-- save pair in table -- save pair in table
@ -81,7 +81,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
dirty = function() return sock:dirty() end dirty = function() return sock:dirty() end
}, { }, {
__call = function() __call = function()
-- get chunk size, skip extension -- get chunk size, skip extention
local line, err = sock:receive() local line, err = sock:receive()
if err then return nil, err end if err then return nil, err end
local size = base.tonumber(string.gsub(line, ";.*", ""), 16) local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
@ -219,11 +219,9 @@ local function adjustproxy(reqt)
local proxy = reqt.proxy or _M.PROXY local proxy = reqt.proxy or _M.PROXY
if proxy then if proxy then
proxy = url.parse(proxy) proxy = url.parse(proxy)
proxy.port = proxy.port or 3128 return proxy.host, proxy.port or 3128
proxy.create = SCHEMES[proxy.scheme].create(reqt)
return proxy.host, proxy.port, proxy.create
else else
return reqt.host, reqt.port, reqt.create return reqt.host, reqt.port
end end
end end
@ -281,7 +279,7 @@ local function adjustrequest(reqt)
if not (host and host ~= "") then if not (host and host ~= "") then
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'") socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
end end
-- compute uri if user hasn't overridden -- compute uri if user hasn't overriden
nreqt.uri = reqt.uri or adjusturi(nreqt) nreqt.uri = reqt.uri or adjusturi(nreqt)
-- adjust headers in request -- adjust headers in request
nreqt.headers = adjustheaders(nreqt) nreqt.headers = adjustheaders(nreqt)
@ -293,10 +291,7 @@ local function adjustrequest(reqt)
end end
-- ajust host and port if there is a proxy -- ajust host and port if there is a proxy
local proxy_create nreqt.host, nreqt.port = adjustproxy(nreqt)
nreqt.host, nreqt.port, proxy_create = adjustproxy(nreqt)
if not reqt.create then nreqt.create = proxy_create end
return nreqt return nreqt
end end

17
src/inet.c Normal file → Executable file
View File

@ -9,13 +9,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef PSP
int gethostname (char *__name, size_t __len) {
snprintf(__name, __len, "psp");
return 0;
}
#endif
/*=========================================================================*\ /*=========================================================================*\
* Internal function prototypes. * Internal function prototypes.
\*=========================================================================*/ \*=========================================================================*/
@ -297,7 +290,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
return 2; return 2;
} }
lua_pushstring(L, name); lua_pushstring(L, name);
lua_pushinteger(L, (int) strtol(port, (char **) NULL, 10)); lua_pushstring(L, port);
switch (family) { switch (family) {
case AF_INET: lua_pushliteral(L, "inet"); break; case AF_INET: lua_pushliteral(L, "inet"); break;
case AF_INET6: lua_pushliteral(L, "inet6"); break; case AF_INET6: lua_pushliteral(L, "inet6"); break;
@ -355,12 +348,10 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp)
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { const char *inet_trycreate(p_socket ps, int family, int type, int protocol) {
const char *err = socket_strerror(socket_create(ps, family, type, protocol)); const char *err = socket_strerror(socket_create(ps, family, type, protocol));
#ifdef IPV6_V6ONLY
if (err == NULL && family == AF_INET6) { if (err == NULL && family == AF_INET6) {
int yes = 1; int yes = 1;
setsockopt(*ps, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes)); setsockopt(*ps, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes));
} }
#endif
return err; return err;
} }
@ -378,7 +369,6 @@ const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm)
return socket_strerror(socket_connect(ps, (SA *) &sin, return socket_strerror(socket_connect(ps, (SA *) &sin,
sizeof(sin), tm)); sizeof(sin), tm));
} }
#ifndef NOIPV6
case AF_INET6: { case AF_INET6: {
struct sockaddr_in6 sin6; struct sockaddr_in6 sin6;
struct in6_addr addrany = IN6ADDR_ANY_INIT; struct in6_addr addrany = IN6ADDR_ANY_INIT;
@ -388,7 +378,6 @@ const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm)
return socket_strerror(socket_connect(ps, (SA *) &sin6, return socket_strerror(socket_connect(ps, (SA *) &sin6,
sizeof(sin6), tm)); sizeof(sin6), tm));
} }
#endif
} }
return NULL; return NULL;
} }
@ -447,9 +436,7 @@ const char *inet_tryaccept(p_socket server, int family, p_socket client,
socklen_t len; socklen_t len;
t_sockaddr_storage addr; t_sockaddr_storage addr;
switch (family) { switch (family) {
#ifndef NOIPV6
case AF_INET6: len = sizeof(struct sockaddr_in6); break; case AF_INET6: len = sizeof(struct sockaddr_in6); break;
#endif
case AF_INET: len = sizeof(struct sockaddr_in); break; case AF_INET: len = sizeof(struct sockaddr_in); break;
default: len = sizeof(addr); break; default: len = sizeof(addr); break;
} }
@ -537,11 +524,9 @@ int inet_pton(int af, const char *src, void *dst)
if (af == AF_INET) { if (af == AF_INET) {
struct sockaddr_in *in = (struct sockaddr_in *) res->ai_addr; struct sockaddr_in *in = (struct sockaddr_in *) res->ai_addr;
memcpy(dst, &in->sin_addr, sizeof(in->sin_addr)); memcpy(dst, &in->sin_addr, sizeof(in->sin_addr));
#ifndef NOIPV6
} else if (af == AF_INET6) { } else if (af == AF_INET6) {
struct sockaddr_in6 *in = (struct sockaddr_in6 *) res->ai_addr; struct sockaddr_in6 *in = (struct sockaddr_in6 *) res->ai_addr;
memcpy(dst, &in->sin6_addr, sizeof(in->sin6_addr)); memcpy(dst, &in->sin6_addr, sizeof(in->sin6_addr));
#endif
} else { } else {
ret = -1; ret = -1;
} }

View File

@ -18,10 +18,6 @@
#include "socket.h" #include "socket.h"
#include "timeout.h" #include "timeout.h"
#ifdef PSP
#include "getaddrinfo.h"
#endif
#ifdef _WIN32 #ifdef _WIN32
#define LUASOCKET_INET_ATON #define LUASOCKET_INET_ATON
#endif #endif

0
src/luasocket.c Normal file → Executable file
View File

View File

@ -10,7 +10,7 @@
/*-------------------------------------------------------------------------* \ /*-------------------------------------------------------------------------* \
* Current socket library version * Current socket library version
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
#define LUASOCKET_VERSION "LuaSocket 3.1.0" #define LUASOCKET_VERSION "LuaSocket 3.0.0"
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab" #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\

82
src/makefile Normal file → Executable file
View File

@ -1,6 +1,6 @@
# luasocket src/makefile # luasocket src/makefile
# #
# Definitions in this section can be overridden on the command line or in the # Definitions in this section can be overriden on the command line or in the
# environment. # environment.
# #
# These are equivalent: # These are equivalent:
@ -105,19 +105,6 @@ LUAPREFIX_solaris?=/usr/local
CDIR_solaris?=lib/lua/$(LUAV) CDIR_solaris?=lib/lua/$(LUAV)
LDIR_solaris?=share/lua/$(LUAV) LDIR_solaris?=share/lua/$(LUAV)
# LUAINC_psp:
# LUALIB_psp:
# where lua headers and libraries are found for psp builds
ifeq ($(PLAT),psp)
PSP_PREFIX=$(shell psp-config -P)
endif
LUAINC_psp?=$(PSP_PREFIX)/include
LUAPREFIX_psp?=/psp
CDIR_psp?=lib/lua/$(LUAV)
LDIR_psp?=share/lua/$(LUAV)
LUALIB_psp_base?=$(PSP_PREFIX)/lib
LUALIB_psp=$(LUALIB_psp_base)/liblua.a
# prefix: /usr/local /usr /opt/local /sw # prefix: /usr/local /usr /opt/local /sw
# the top of the default install tree # the top of the default install tree
prefix?=$(LUAPREFIX_$(PLAT)) prefix?=$(LUAPREFIX_$(PLAT))
@ -166,7 +153,7 @@ print:
#------ #------
# Supported platforms # Supported platforms
# #
PLATS= macosx linux win32 win64 mingw freebsd solaris psp PLATS= macosx linux win32 win64 mingw solaris
#------ #------
# Compiler and linker settings # Compiler and linker settings
@ -275,26 +262,6 @@ LDFLAGS_win64= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \
LD_win64=cl LD_win64=cl
SOCKET_win64=wsocket.obj SOCKET_win64=wsocket.obj
#------
# Compiler and linker settings
# for PSP
ifeq ($(PLAT),psp)
PSPSDK=$(shell psp-config -p)
endif
SO_psp=a
O_psp=o
A_psp=a
CC_psp=psp-gcc
DEF_psp=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN
CFLAGS_psp=$(LUAINC:%=-I%) $(PSPSDK:%=-I%)/include $(DEF) -Wall -Wshadow -Wextra \
-Wimplicit -O2 -ggdb3 -DHAVE_CONFIG_H -DSOCKET_SELECT -DNOIPV6
LDFLAGS_psp=$(LUALIB) && mv templib.a
LD_psp=psp-ar rcs templib.a
AR_psp=psp-ar rcs
SOCKET_psp=usocket.o
.SUFFIXES: .obj .SUFFIXES: .obj
.c.obj: .c.obj:
@ -305,16 +272,13 @@ SOCKET_psp=usocket.o
# #
SO=$(SO_$(PLAT)) SO=$(SO_$(PLAT))
O=$(O_$(PLAT)) O=$(O_$(PLAT))
SOCKET_V=3.1.0 SOCKET_V=3.0.0
MIME_V=1.0.3 MIME_V=1.0.3
SOCKET_SO=socket-$(SOCKET_V).$(SO) SOCKET_SO=socket-$(SOCKET_V).$(SO)
MIME_SO=mime-$(MIME_V).$(SO) MIME_SO=mime-$(MIME_V).$(SO)
UNIX_SO=unix.$(SO) UNIX_SO=unix.$(SO)
SERIAL_SO=serial.$(SO) SERIAL_SO=serial.$(SO)
SOCKET=$(SOCKET_$(PLAT)) SOCKET=$(SOCKET_$(PLAT))
STATIC_LIB=libluasocket.$(A_$(PLAT))
COMBINED_H=luasocket-combined.h
TARGET_H=luasocket.h
#------ #------
# Settings selected for platform # Settings selected for platform
@ -324,17 +288,9 @@ DEF=$(DEF_$(PLAT))
CFLAGS=$(MYCFLAGS) $(CFLAGS_$(PLAT)) CFLAGS=$(MYCFLAGS) $(CFLAGS_$(PLAT))
LDFLAGS=$(MYLDFLAGS) $(LDFLAGS_$(PLAT)) LDFLAGS=$(MYLDFLAGS) $(LDFLAGS_$(PLAT))
LD=$(LD_$(PLAT)) LD=$(LD_$(PLAT))
AR=$(AR_$(PLAT))
LUAINC= $(LUAINC_$(PLAT)) LUAINC= $(LUAINC_$(PLAT))
LUALIB= $(LUALIB_$(PLAT)) LUALIB= $(LUALIB_$(PLAT))
#------
# Platform-specific modules
#
PLATFORM_OBJS_psp= \
netdb-compat.$(O) \
getaddrinfo.$(O)
#------ #------
# Modules belonging to socket-core # Modules belonging to socket-core
# #
@ -431,9 +387,6 @@ mingw:
solaris: solaris:
$(MAKE) all-unix PLAT=solaris $(MAKE) all-unix PLAT=solaris
psp:
$(MAKE) static PLAT=psp
none: none:
@echo "Please run" @echo "Please run"
@echo " make PLATFORM" @echo " make PLATFORM"
@ -442,18 +395,7 @@ none:
all: $(SOCKET_SO) $(MIME_SO) all: $(SOCKET_SO) $(MIME_SO)
static: $(STATIC_LIB) $(COMBINED_H) $(SOCKET_SO): $(SOCKET_OBJS)
$(COMBINED_H): luasocket.h compat.h mime.h
sed '29,$$d' luasocket.h > $(COMBINED_H)
sed -e '1,2d' -e '$$d' compat.h >> $(COMBINED_H)
sed -n '30,$$p' luasocket.h >> $(COMBINED_H)
sed '11d' mime.h >> $(COMBINED_H)
$(STATIC_LIB): $(PLATFORM_OBJS_$(PLAT)) $(SOCKET_OBJS) $(MIME_OBJS) $(UNIX_OBJS) $(SERIAL_OBJS)
$(AR) $@ $(PLATFORM_OBJS_$(PLAT)) $(SOCKET_OBJS) $(MIME_OBJS) $(UNIX_OBJS) $(SERIAL_OBJS)
$(SOCKET_SO): $(PLATFORM_OBJS_$(PLAT)) $(SOCKET_OBJS)
$(LD) $(SOCKET_OBJS) $(LDFLAGS)$@ $(LD) $(SOCKET_OBJS) $(LDFLAGS)$@
$(MIME_SO): $(MIME_OBJS) $(MIME_SO): $(MIME_OBJS)
@ -481,22 +423,12 @@ install-unix: install
$(INSTALL_EXEC) $(UNIX_SO) $(INSTALL_SOCKET_CDIR)/$(UNIX_SO) $(INSTALL_EXEC) $(UNIX_SO) $(INSTALL_SOCKET_CDIR)/$(UNIX_SO)
$(INSTALL_EXEC) $(SERIAL_SO) $(INSTALL_SOCKET_CDIR)/$(SERIAL_SO) $(INSTALL_EXEC) $(SERIAL_SO) $(INSTALL_SOCKET_CDIR)/$(SERIAL_SO)
install-static:
$(INSTALL_DIR) $(INSTALL_TOP_LDIR)
$(INSTALL_DATA) $(TO_TOP_LDIR) $(INSTALL_TOP_LDIR)
$(INSTALL_DIR) $(INSTALL_SOCKET_LDIR)
$(INSTALL_DATA) $(TO_SOCKET_LDIR) $(INSTALL_SOCKET_LDIR)
$(INSTALL_DIR) $(INSTALL_TOP)/lib
$(INSTALL_EXEC) $(STATIC_LIB) $(INSTALL_TOP)/lib
$(INSTALL_DIR) $(INSTALL_TOP)/include
$(INSTALL_DATA) $(COMBINED_H) $(INSTALL_TOP)/include/$(TARGET_H)
local: local:
$(MAKE) install INSTALL_TOP_CDIR=.. INSTALL_TOP_LDIR=.. $(MAKE) install INSTALL_TOP_CDIR=.. INSTALL_TOP_LDIR=..
clean: clean:
rm -f $(SOCKET_SO) $(PLATFORM_OBJS_$(PLAT)) $(SOCKET_OBJS) $(SERIAL_OBJS) $(COMBINED_H) rm -f $(SOCKET_SO) $(SOCKET_OBJS) $(SERIAL_OBJS)
rm -f $(STATIC_LIB) $(MIME_SO) $(UNIX_SO) $(SERIAL_SO) $(MIME_OBJS) $(UNIX_OBJS) rm -f $(MIME_SO) $(UNIX_SO) $(SERIAL_SO) $(MIME_OBJS) $(UNIX_OBJS)
.PHONY: all $(PLATS) default clean echo none .PHONY: all $(PLATS) default clean echo none
@ -527,5 +459,3 @@ unix.$(O): unix.c auxiliar.h socket.h io.h timeout.h usocket.h \
options.h unix.h buffer.h options.h unix.h buffer.h
usocket.$(O): usocket.c socket.h io.h timeout.h usocket.h usocket.$(O): usocket.c socket.h io.h timeout.h usocket.h
wsocket.$(O): wsocket.c socket.h io.h timeout.h usocket.h wsocket.$(O): wsocket.c socket.h io.h timeout.h usocket.h
getaddrinfo.$(O): getaddrinfo.c getaddrinfo.h
netdb-compat.$(O): netdb-compat.c netdb-compat.h

0
src/mime.c Normal file → Executable file
View File

View File

@ -1,142 +0,0 @@
/*
* symbian_stubs.c
*
* Copyright (c) Nokia 2004-2005. All rights reserved.
* This code is licensed under the same terms as Perl itself.
*
* netdb-compat.c
* Copyright (c) Dima Pulkinen 2024
*
*/
#include "netdb-compat.h"
#include <string.h>
static const struct protoent protocols[] = {
{ "tcp", 0, 6 },
{ "udp", 0, 17 }
};
/* The protocol field (the last) is left empty to save both space
* and time because practically all services have both tcp and udp
* allocations in IANA. */
static const struct servent services[] = {
{ "http", 0, 80, 0 }, /* Optimization. */
{ "https", 0, 443, 0 },
{ "imap", 0, 143, 0 },
{ "imaps", 0, 993, 0 },
{ "smtp", 0, 25, 0 },
{ "irc", 0, 194, 0 },
{ "ftp", 0, 21, 0 },
{ "ssh", 0, 22, 0 },
{ "tftp", 0, 69, 0 },
{ "pop3", 0, 110, 0 },
{ "sftp", 0, 115, 0 },
{ "nntp", 0, 119, 0 },
{ "ntp", 0, 123, 0 },
{ "snmp", 0, 161, 0 },
{ "ldap", 0, 389, 0 },
{ "rsync", 0, 873, 0 },
{ "socks", 0, 1080, 0 }
};
struct protoent* getprotobynumber(int number) {
int i;
for (i = 0; i < sizeof(protocols)/sizeof(struct protoent); i++)
if (protocols[i].p_proto == number)
return (struct protoent*)(&(protocols[i]));
return 0;
}
struct protoent* getprotobyname(const char* name) {
int i;
for (i = 0; i < sizeof(protocols)/sizeof(struct protoent); i++)
if (strcmp(name, protocols[i].p_name) == 0)
return (struct protoent*)(&(protocols[i]));
return 0;
}
struct servent* getservbyname(const char* name, const char* proto) {
int i;
for (i = 0; i < sizeof(services)/sizeof(struct servent); i++)
if (strcmp(name, services[i].s_name) == 0)
return (struct servent*)(&(services[i]));
return 0;
}
struct servent* getservbyport(int port, const char* proto) {
int i;
for (i = 0; i < sizeof(services)/sizeof(struct servent); i++)
if (services[i].s_port == port)
return (struct servent*)(&(services[i]));
return 0;
}
/*
* Copyright (c) 1987, 1993
* The Regents of the University of California. 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.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*/
/*
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
static const char *h_errlist[] =
{
"Resolver Error 0 (no error)",
"Unknown host", /* 1 HOST_NOT_FOUND */
"Host name lookup failure", /* 2 TRY_AGAIN */
"Unknown server error", /* 3 NO_RECOVERY */
"No address associated with name", /* 4 NO_ADDRESS */
};
#define h_nerr (int)(sizeof h_errlist / sizeof h_errlist[0])
const char *hstrerror(int err)
{
if (err < 0)
return "Resolver internal error";
else if (err < h_nerr)
return h_errlist[err];
return "Unknown resolver error";
}

View File

@ -1,55 +0,0 @@
/*
* Phoenix-RTOS
*
* libphoenix
*
* netdb.h
*
* Copyright 2018 Phoenix Systems
* Author: Jan Sikorski, Michal Miroslaw
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*
* netdb-compat.h
* Copyright (c) Dima Pulkinen 2024
*
*/
#ifndef _NETDB_COMPAT_H_
#define _NETDB_COMPAT_H_
#ifdef __cplusplus
extern "C" {
#endif
struct servent {
char *s_name;
char **s_aliases;
int s_port;
char *s_proto;
};
struct protoent {
char *p_name;
char **p_aliases;
int p_proto;
};
const char *hstrerror(int err);
struct servent *getservbyname(const char *name, const char *proto);
struct servent *getservbyport(int port, const char *proto);
struct protoent *getprotobyname(const char *name);
struct protoent *getprotobynumber(int proto);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -12,9 +12,7 @@
* Internal functions prototypes * Internal functions prototypes
\*=========================================================================*/ \*=========================================================================*/
static int opt_setmembership(lua_State *L, p_socket ps, int level, int name); static int opt_setmembership(lua_State *L, p_socket ps, int level, int name);
#if defined(IPV6_ADD_MEMBERSHIP) || defined(IPV6_DROP_MEMBERSHIP)
static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name); static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name);
#endif
static int opt_setboolean(lua_State *L, p_socket ps, int level, int name); static int opt_setboolean(lua_State *L, p_socket ps, int level, int name);
static int opt_getboolean(lua_State *L, p_socket ps, int level, int name); static int opt_getboolean(lua_State *L, p_socket ps, int level, int name);
static int opt_setint(lua_State *L, p_socket ps, int level, int name); static int opt_setint(lua_State *L, p_socket ps, int level, int name);
@ -245,7 +243,6 @@ int opt_set_tcp_defer_accept(lua_State *L, p_socket ps)
#endif #endif
/*------------------------------------------------------*/ /*------------------------------------------------------*/
#ifdef IPV6_UNICAST_HOPS
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps)
{ {
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
@ -255,10 +252,8 @@ int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps)
{ {
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS);
} }
#endif
/*------------------------------------------------------*/ /*------------------------------------------------------*/
#ifdef IPV6_MULTICAST_HOPS
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps) int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps)
{ {
return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
@ -268,7 +263,6 @@ int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps)
{ {
return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
} }
#endif
/*------------------------------------------------------*/ /*------------------------------------------------------*/
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps) int opt_set_ip_multicast_loop(lua_State *L, p_socket ps)
@ -282,7 +276,6 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps)
} }
/*------------------------------------------------------*/ /*------------------------------------------------------*/
#ifdef IPV6_MULTICAST_LOOP
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps) int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps)
{ {
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
@ -292,7 +285,6 @@ int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps)
{ {
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP);
} }
#endif
/*------------------------------------------------------*/ /*------------------------------------------------------*/
int opt_set_linger(lua_State *L, p_socket ps) int opt_set_linger(lua_State *L, p_socket ps)
@ -370,22 +362,17 @@ int opt_set_ip_drop_membersip(lua_State *L, p_socket ps)
} }
/*------------------------------------------------------*/ /*------------------------------------------------------*/
#ifdef IPV6_ADD_MEMBERSHIP
int opt_set_ip6_add_membership(lua_State *L, p_socket ps) int opt_set_ip6_add_membership(lua_State *L, p_socket ps)
{ {
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP); return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP);
} }
#endif
#ifdef IPV6_DROP_MEMBERSHIP
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps) int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps)
{ {
return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP); return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP);
} }
#endif
/*------------------------------------------------------*/ /*------------------------------------------------------*/
#ifdef IPV6_V6ONLY
int opt_get_ip6_v6only(lua_State *L, p_socket ps) int opt_get_ip6_v6only(lua_State *L, p_socket ps)
{ {
return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
@ -395,7 +382,6 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps)
{ {
return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY);
} }
#endif
/*------------------------------------------------------*/ /*------------------------------------------------------*/
int opt_get_error(lua_State *L, p_socket ps) int opt_get_error(lua_State *L, p_socket ps)
@ -435,7 +421,6 @@ static int opt_setmembership(lua_State *L, p_socket ps, int level, int name)
return opt_set(L, ps, level, name, (char *) &val, sizeof(val)); return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
} }
#if defined(IPV6_ADD_MEMBERSHIP) || defined(IPV6_DROP_MEMBERSHIP)
static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name) static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)
{ {
struct ipv6_mreq val; /* obj, opt-name, table */ struct ipv6_mreq val; /* obj, opt-name, table */
@ -461,7 +446,6 @@ static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)
} }
return opt_set(L, ps, level, name, (char *) &val, sizeof(val)); return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
} }
#endif
static static
int opt_get(lua_State *L, p_socket ps, int level, int name, void *val, int* len) int opt_get(lua_State *L, p_socket ps, int level, int name, void *val, int* len)

View File

@ -78,23 +78,17 @@ int opt_set_tcp_fastopen(lua_State *L, p_socket ps);
int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps); int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps);
#endif #endif
#ifdef IPV6_UNICAST_HOPS
int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps); int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps);
int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps);
#endif
#ifdef IPV6_MULTICAST_HOPS
int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps); int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps);
int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps);
#endif
int opt_set_ip_multicast_loop(lua_State *L, p_socket ps); int opt_set_ip_multicast_loop(lua_State *L, p_socket ps);
int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); int opt_get_ip_multicast_loop(lua_State *L, p_socket ps);
#ifdef IPV6_MULTICAST_LOOP
int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps); int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps);
int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps);
#endif
int opt_set_linger(lua_State *L, p_socket ps); int opt_set_linger(lua_State *L, p_socket ps);
int opt_get_linger(lua_State *L, p_socket ps); int opt_get_linger(lua_State *L, p_socket ps);
@ -107,17 +101,11 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps);
int opt_set_ip_add_membership(lua_State *L, p_socket ps); int opt_set_ip_add_membership(lua_State *L, p_socket ps);
int opt_set_ip_drop_membersip(lua_State *L, p_socket ps); int opt_set_ip_drop_membersip(lua_State *L, p_socket ps);
#ifdef IPV6_ADD_MEMBERSHIP
int opt_set_ip6_add_membership(lua_State *L, p_socket ps); int opt_set_ip6_add_membership(lua_State *L, p_socket ps);
#endif
#ifdef IPV6_DROP_MEMBERSHIP
int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps); int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps);
#endif
#ifdef IPV6_V6ONLY
int opt_set_ip6_v6only(lua_State *L, p_socket ps); int opt_set_ip6_v6only(lua_State *L, p_socket ps);
int opt_get_ip6_v6only(lua_State *L, p_socket ps); int opt_get_ip6_v6only(lua_State *L, p_socket ps);
#endif
int opt_get_error(lua_State *L, p_socket ps); int opt_get_error(lua_State *L, p_socket ps);

View File

@ -12,7 +12,7 @@
#define PIE_CONNREFUSED "connection refused" #define PIE_CONNREFUSED "connection refused"
#define PIE_CONNABORTED "closed" #define PIE_CONNABORTED "closed"
#define PIE_CONNRESET "closed" #define PIE_CONNRESET "closed"
#define PIE_TIMEDOUT "timeout" #define PIE_TIMEDOUT "connection timeout"
#define PIE_AGAIN "temporary failure in name resolution" #define PIE_AGAIN "temporary failure in name resolution"
#define PIE_BADFLAGS "invalid value for ai_flags" #define PIE_BADFLAGS "invalid value for ai_flags"
#define PIE_BADHINTS "invalid value for hints" #define PIE_BADHINTS "invalid value for hints"

View File

@ -1,59 +0,0 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. 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. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*/
/*
* psp-un.h
* Copyright (c) Dima Pulkinen 2024
*/
#ifndef _PSP_UN_H_
#define _PSP_UN_H_
#include <sys/socket.h>
/*
* Historically, (struct sockaddr) needed to fit inside an mbuf.
* For this reason, UNIX domain sockets were therefore limited to
* 104 bytes. While this limit is no longer necessary, it is kept for
* binary compatibility reasons.
*/
#define SUNPATHLEN 104
/*
* Definitions for UNIX IPC domain.
*/
struct sockaddr_un {
unsigned char sun_len; /* sockaddr len including null */
sa_family_t sun_family; /* AF_UNIX */
char sun_path[SUNPATHLEN]; /* path name (gag) */
};
#endif /* !_PSP_UN_H_ */

View File

@ -10,11 +10,7 @@
#include "unix.h" #include "unix.h"
#include <string.h> #include <string.h>
#ifndef PSP
#include <sys/un.h> #include <sys/un.h>
#else
#include "psp-un.h"
#endif
/* /*
Reuses userdata definition from unix.h, since it is useful for all Reuses userdata definition from unix.h, since it is useful for all

View File

@ -225,7 +225,7 @@ local function adjust_headers(mesgt)
lower["date"] = lower["date"] or lower["date"] = lower["date"] or
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE) os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
-- this can't be overridden -- this can't be overriden
lower["mime-version"] = "1.0" lower["mime-version"] = "1.0"
return lower return lower
end end

0
src/socket.h Normal file → Executable file
View File

View File

@ -107,9 +107,7 @@ static t_opt optset[] = {
#ifdef TCP_KEEPINTVL #ifdef TCP_KEEPINTVL
{"tcp-keepintvl", opt_set_tcp_keepintvl}, {"tcp-keepintvl", opt_set_tcp_keepintvl},
#endif #endif
#ifdef IPV6_V6ONLY
{"ipv6-v6only", opt_set_ip6_v6only}, {"ipv6-v6only", opt_set_ip6_v6only},
#endif
{"linger", opt_set_linger}, {"linger", opt_set_linger},
{"recv-buffer-size", opt_set_recv_buf_size}, {"recv-buffer-size", opt_set_recv_buf_size},
{"send-buffer-size", opt_set_send_buf_size}, {"send-buffer-size", opt_set_send_buf_size},

20
src/udp.c Normal file → Executable file
View File

@ -80,24 +80,12 @@ static t_opt optset[] = {
{"ip-multicast-loop", opt_set_ip_multicast_loop}, {"ip-multicast-loop", opt_set_ip_multicast_loop},
{"ip-add-membership", opt_set_ip_add_membership}, {"ip-add-membership", opt_set_ip_add_membership},
{"ip-drop-membership", opt_set_ip_drop_membersip}, {"ip-drop-membership", opt_set_ip_drop_membersip},
#ifdef IPV6_UNICAST_HOPS
{"ipv6-unicast-hops", opt_set_ip6_unicast_hops}, {"ipv6-unicast-hops", opt_set_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_HOPS
{"ipv6-multicast-hops", opt_set_ip6_unicast_hops}, {"ipv6-multicast-hops", opt_set_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_LOOP
{"ipv6-multicast-loop", opt_set_ip6_multicast_loop}, {"ipv6-multicast-loop", opt_set_ip6_multicast_loop},
#endif
#ifdef IPV6_ADD_MEMBERSHIP
{"ipv6-add-membership", opt_set_ip6_add_membership}, {"ipv6-add-membership", opt_set_ip6_add_membership},
#endif
#ifdef IPV6_DROP_MEMBERSHIP
{"ipv6-drop-membership", opt_set_ip6_drop_membersip}, {"ipv6-drop-membership", opt_set_ip6_drop_membersip},
#endif
#ifdef IPV6_V6ONLY
{"ipv6-v6only", opt_set_ip6_v6only}, {"ipv6-v6only", opt_set_ip6_v6only},
#endif
{"recv-buffer-size", opt_set_recv_buf_size}, {"recv-buffer-size", opt_set_recv_buf_size},
{"send-buffer-size", opt_set_send_buf_size}, {"send-buffer-size", opt_set_send_buf_size},
{NULL, NULL} {NULL, NULL}
@ -112,18 +100,10 @@ static t_opt optget[] = {
{"ip-multicast-if", opt_get_ip_multicast_if}, {"ip-multicast-if", opt_get_ip_multicast_if},
{"ip-multicast-loop", opt_get_ip_multicast_loop}, {"ip-multicast-loop", opt_get_ip_multicast_loop},
{"error", opt_get_error}, {"error", opt_get_error},
#ifdef IPV6_UNICAST_HOPS
{"ipv6-unicast-hops", opt_get_ip6_unicast_hops}, {"ipv6-unicast-hops", opt_get_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_HOPS
{"ipv6-multicast-hops", opt_get_ip6_unicast_hops}, {"ipv6-multicast-hops", opt_get_ip6_unicast_hops},
#endif
#ifdef IPV6_MULTICAST_LOOP
{"ipv6-multicast-loop", opt_get_ip6_multicast_loop}, {"ipv6-multicast-loop", opt_get_ip6_multicast_loop},
#endif
#ifdef IPV6_V6ONLY
{"ipv6-v6only", opt_get_ip6_v6only}, {"ipv6-v6only", opt_get_ip6_v6only},
#endif
{"recv-buffer-size", opt_get_recv_buf_size}, {"recv-buffer-size", opt_get_recv_buf_size},
{"send-buffer-size", opt_get_send_buf_size}, {"send-buffer-size", opt_get_send_buf_size},
{NULL, NULL} {NULL, NULL}

View File

@ -12,14 +12,17 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef PSP
#include <sys/un.h> #include <sys/un.h>
#else
#include "psp-un.h"
#endif
#define UNIXDGRAM_DATAGRAMSIZE 8192 #define UNIXDGRAM_DATAGRAMSIZE 8192
/* provide a SUN_LEN macro if sys/un.h doesn't (e.g. Android) */
#ifndef SUN_LEN
#define SUN_LEN(ptr) \
((size_t) (((struct sockaddr_un *) 0)->sun_path) \
+ strlen ((ptr)->sun_path))
#endif
/*=========================================================================*\ /*=========================================================================*\
* Internal function prototypes * Internal function prototypes
\*=========================================================================*/ \*=========================================================================*/
@ -39,8 +42,8 @@ static int meth_receivefrom(lua_State *L);
static int meth_sendto(lua_State *L); static int meth_sendto(lua_State *L);
static int meth_getsockname(lua_State *L); static int meth_getsockname(lua_State *L);
static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len); static const char *unixdgram_tryconnect(p_unix un, const char *path);
static const char *unixdgram_trybind(p_unix un, const char *path, size_t len); static const char *unixdgram_trybind(p_unix un, const char *path);
/* unixdgram object methods */ /* unixdgram object methods */
static luaL_Reg unixdgram_methods[] = { static luaL_Reg unixdgram_methods[] = {
@ -130,12 +133,13 @@ static int meth_send(lua_State *L)
static int meth_sendto(lua_State *L) static int meth_sendto(lua_State *L)
{ {
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
size_t count, sent, len = 0; size_t count, sent = 0;
const char *data = luaL_checklstring(L, 2, &count); const char *data = luaL_checklstring(L, 2, &count);
const char *path = luaL_checklstring(L, 3, &len); const char *path = luaL_checkstring(L, 3);
p_timeout tm = &un->tm; p_timeout tm = &un->tm;
int err; int err;
struct sockaddr_un remote; struct sockaddr_un remote;
size_t len = strlen(path);
if (len >= sizeof(remote.sun_path)) { if (len >= sizeof(remote.sun_path)) {
lua_pushnil(L); lua_pushnil(L);
@ -144,7 +148,7 @@ static int meth_sendto(lua_State *L)
} }
memset(&remote, 0, sizeof(remote)); memset(&remote, 0, sizeof(remote));
memcpy(remote.sun_path, path, len); strcpy(remote.sun_path, path);
remote.sun_family = AF_UNIX; remote.sun_family = AF_UNIX;
timeout_markstart(tm); timeout_markstart(tm);
#ifdef UNIX_HAS_SUN_LEN #ifdef UNIX_HAS_SUN_LEN
@ -260,22 +264,18 @@ static int meth_dirty(lua_State *L) {
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Binds an object to an address * Binds an object to an address
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static const char *unixdgram_trybind(p_unix un, const char *path, size_t len) { static const char *unixdgram_trybind(p_unix un, const char *path) {
struct sockaddr_un local; struct sockaddr_un local;
int err; size_t len = strlen(path);
if (len >= sizeof(local.sun_path)) return "path too long"; if (len >= sizeof(local.sun_path)) return "path too long";
memset(&local, 0, sizeof(local)); memset(&local, 0, sizeof(local));
memcpy(local.sun_path, path, len); strcpy(local.sun_path, path);
local.sun_family = AF_UNIX; local.sun_family = AF_UNIX;
size_t addrlen = SUN_LEN(&local);
#ifdef UNIX_HAS_SUN_LEN #ifdef UNIX_HAS_SUN_LEN
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) local.sun_len = addrlen + 1;
+ len + 1;
err = socket_bind(&un->sock, (SA *) &local, local.sun_len);
#else
err = socket_bind(&un->sock, (SA *) &local,
sizeof(local.sun_family) + len);
#endif #endif
int err = socket_bind(&un->sock, (SA *) &local, addrlen);
if (err != IO_DONE) socket_destroy(&un->sock); if (err != IO_DONE) socket_destroy(&un->sock);
return socket_strerror(err); return socket_strerror(err);
} }
@ -283,9 +283,8 @@ static const char *unixdgram_trybind(p_unix un, const char *path, size_t len) {
static int meth_bind(lua_State *L) static int meth_bind(lua_State *L)
{ {
p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
size_t len; const char *path = luaL_checkstring(L, 2);
const char *path = luaL_checklstring(L, 2, &len); const char *err = unixdgram_trybind(un, path);
const char *err = unixdgram_trybind(un, path, len);
if (err) { if (err) {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, err); lua_pushstring(L, err);
@ -314,23 +313,20 @@ static int meth_getsockname(lua_State *L)
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Turns a master unixdgram object into a client object. * Turns a master unixdgram object into a client object.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len) static const char *unixdgram_tryconnect(p_unix un, const char *path)
{ {
struct sockaddr_un remote; struct sockaddr_un remote;
int err; size_t len = strlen(path);
if (len >= sizeof(remote.sun_path)) return "path too long"; if (len >= sizeof(remote.sun_path)) return "path too long";
memset(&remote, 0, sizeof(remote)); memset(&remote, 0, sizeof(remote));
memcpy(remote.sun_path, path, len); strcpy(remote.sun_path, path);
remote.sun_family = AF_UNIX; remote.sun_family = AF_UNIX;
timeout_markstart(&un->tm); timeout_markstart(&un->tm);
size_t addrlen = SUN_LEN(&remote);
#ifdef UNIX_HAS_SUN_LEN #ifdef UNIX_HAS_SUN_LEN
remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) remote.sun_len = addrlen + 1;
+ len + 1;
err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm);
#else
err = socket_connect(&un->sock, (SA *) &remote,
sizeof(remote.sun_family) + len, &un->tm);
#endif #endif
int err = socket_connect(&un->sock, (SA *) &remote, addrlen, &un->tm);
if (err != IO_DONE) socket_destroy(&un->sock); if (err != IO_DONE) socket_destroy(&un->sock);
return socket_strerror(err); return socket_strerror(err);
} }
@ -338,9 +334,8 @@ static const char *unixdgram_tryconnect(p_unix un, const char *path, size_t len)
static int meth_connect(lua_State *L) static int meth_connect(lua_State *L)
{ {
p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1);
size_t len; const char *path = luaL_checkstring(L, 2);
const char *path = luaL_checklstring(L, 2, &len); const char *err = unixdgram_tryconnect(un, path);
const char *err = unixdgram_tryconnect(un, path, len);
if (err) { if (err) {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, err); lua_pushstring(L, err);

View File

@ -10,11 +10,7 @@
#include "unixstream.h" #include "unixstream.h"
#include <string.h> #include <string.h>
#ifndef PSP
#include <sys/un.h> #include <sys/un.h>
#else
#include "psp-un.h"
#endif
/*=========================================================================*\ /*=========================================================================*\
* Internal function prototypes * Internal function prototypes
@ -37,8 +33,8 @@ static int meth_getstats(lua_State *L);
static int meth_setstats(lua_State *L); static int meth_setstats(lua_State *L);
static int meth_getsockname(lua_State *L); static int meth_getsockname(lua_State *L);
static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len); static const char *unixstream_tryconnect(p_unix un, const char *path);
static const char *unixstream_trybind(p_unix un, const char *path, size_t len); static const char *unixstream_trybind(p_unix un, const char *path);
/* unixstream object methods */ /* unixstream object methods */
static luaL_Reg unixstream_methods[] = { static luaL_Reg unixstream_methods[] = {
@ -185,12 +181,13 @@ static int meth_accept(lua_State *L) {
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Binds an object to an address * Binds an object to an address
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static const char *unixstream_trybind(p_unix un, const char *path, size_t len) { static const char *unixstream_trybind(p_unix un, const char *path) {
struct sockaddr_un local; struct sockaddr_un local;
size_t len = strlen(path);
int err; int err;
if (len >= sizeof(local.sun_path)) return "path too long"; if (len >= sizeof(local.sun_path)) return "path too long";
memset(&local, 0, sizeof(local)); memset(&local, 0, sizeof(local));
memcpy(local.sun_path, path, len); strcpy(local.sun_path, path);
local.sun_family = AF_UNIX; local.sun_family = AF_UNIX;
#ifdef UNIX_HAS_SUN_LEN #ifdef UNIX_HAS_SUN_LEN
local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
@ -207,9 +204,8 @@ static const char *unixstream_trybind(p_unix un, const char *path, size_t len) {
static int meth_bind(lua_State *L) { static int meth_bind(lua_State *L) {
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
size_t len; const char *path = luaL_checkstring(L, 2);
const char *path = luaL_checklstring(L, 2, &len); const char *err = unixstream_trybind(un, path);
const char *err = unixstream_trybind(un, path, len);
if (err) { if (err) {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, err); lua_pushstring(L, err);
@ -238,13 +234,14 @@ static int meth_getsockname(lua_State *L)
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Turns a master unixstream object into a client object. * Turns a master unixstream object into a client object.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len) static const char *unixstream_tryconnect(p_unix un, const char *path)
{ {
struct sockaddr_un remote; struct sockaddr_un remote;
int err; int err;
size_t len = strlen(path);
if (len >= sizeof(remote.sun_path)) return "path too long"; if (len >= sizeof(remote.sun_path)) return "path too long";
memset(&remote, 0, sizeof(remote)); memset(&remote, 0, sizeof(remote));
memcpy(remote.sun_path, path, len); strcpy(remote.sun_path, path);
remote.sun_family = AF_UNIX; remote.sun_family = AF_UNIX;
timeout_markstart(&un->tm); timeout_markstart(&un->tm);
#ifdef UNIX_HAS_SUN_LEN #ifdef UNIX_HAS_SUN_LEN
@ -262,9 +259,8 @@ static const char *unixstream_tryconnect(p_unix un, const char *path, size_t len
static int meth_connect(lua_State *L) static int meth_connect(lua_State *L)
{ {
p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1);
size_t len; const char *path = luaL_checkstring(L, 2);
const char *path = luaL_checklstring(L, 2, &len); const char *err = unixstream_tryconnect(un, path);
const char *err = unixstream_tryconnect(un, path, len);
if (err) { if (err) {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, err); lua_pushstring(L, err);

View File

@ -152,7 +152,7 @@ function _M.parse(url, default)
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:", url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
function(s) parsed.scheme = s; return "" end) function(s) parsed.scheme = s; return "" end)
-- get authority -- get authority
url = string.gsub(url, "^//([^/%?#]*)", function(n) url = string.gsub(url, "^//([^/]*)", function(n)
parsed.authority = n parsed.authority = n
return "" return ""
end) end)

View File

@ -29,16 +29,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
/* TCP options (nagle algorithm disable) */ /* TCP options (nagle algorithm disable) */
#include <netinet/tcp.h> #include <netinet/tcp.h>
#ifndef PSP
#include <net/if.h> #include <net/if.h>
#else
#include "getaddrinfo.h"
#ifndef INET6_ADDRSTRLEN
#define INET6_ADDRSTRLEN INET_ADDRSTRLEN
#endif
#endif
#ifndef SO_REUSEPORT #ifndef SO_REUSEPORT
#define SO_REUSEPORT SO_REUSEADDR #define SO_REUSEPORT SO_REUSEADDR

2
src/wsocket.c Normal file → Executable file
View File

@ -262,7 +262,6 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
if (err != WSAEWOULDBLOCK) { if (err != WSAEWOULDBLOCK) {
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err; if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
prev = err; prev = err;
continue;
} }
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
} }
@ -292,7 +291,6 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
if (err != WSAEWOULDBLOCK) { if (err != WSAEWOULDBLOCK) {
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err; if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
prev = err; prev = err;
continue;
} }
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err; if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
} }

0
vc32.bat Normal file → Executable file
View File

0
vc64.bat Normal file → Executable file
View File

0
win32.cmd Normal file → Executable file
View File

0
win64.cmd Normal file → Executable file
View File