2003-12-10 21:53:35 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2003-12-10 21:53:35 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2003-12-10 21:53:35 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2003-12-10 21:53:35 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
#include "curl_setup.h"
|
2012-04-07 05:35:15 +08:00
|
|
|
|
2019-03-08 08:06:59 +08:00
|
|
|
#ifdef __AMIGA__
|
2022-08-07 21:42:19 +08:00
|
|
|
|
2022-10-19 02:22:09 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2022-08-07 21:42:19 +08:00
|
|
|
#include "hostip.h"
|
|
|
|
#include "amigaos.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_PROTO_BSDSOCKET_H
|
|
|
|
# if defined(__amigaos4__)
|
|
|
|
# include <bsdsocket/socketbasetags.h>
|
|
|
|
# elif !defined(USE_AMISSL)
|
2019-03-08 08:06:59 +08:00
|
|
|
# include <amitcp/socketbasetags.h>
|
|
|
|
# endif
|
|
|
|
# ifdef __libnix__
|
|
|
|
# include <stabs.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
2003-12-10 21:53:35 +08:00
|
|
|
|
2019-03-08 08:06:59 +08:00
|
|
|
/* The last #include files should be: */
|
|
|
|
#include "curl_memory.h"
|
|
|
|
#include "memdebug.h"
|
2012-04-07 05:35:15 +08:00
|
|
|
|
2022-08-07 21:42:19 +08:00
|
|
|
#ifdef HAVE_PROTO_BSDSOCKET_H
|
2022-08-08 00:04:47 +08:00
|
|
|
|
|
|
|
#ifdef __amigaos4__
|
2022-08-07 21:42:19 +08:00
|
|
|
/*
|
|
|
|
* AmigaOS 4.x specific code
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hostip4.c - Curl_ipv4_resolve_r() replacement code
|
|
|
|
*
|
|
|
|
* Logic that needs to be considered are the following build cases:
|
|
|
|
* - newlib networking
|
|
|
|
* - clib2 networking
|
|
|
|
* - direct bsdsocket.library networking (usually AmiSSL builds)
|
|
|
|
* Each with the threaded resolver enabled or not.
|
|
|
|
*
|
|
|
|
* With the threaded resolver enabled, try to use gethostbyname_r() where
|
|
|
|
* available, otherwise (re)open bsdsocket.library and fallback to
|
|
|
|
* gethostbyname().
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <proto/bsdsocket.h>
|
|
|
|
|
|
|
|
static struct SocketIFace *__CurlISocket = NULL;
|
|
|
|
static uint32 SocketFeatures = 0;
|
|
|
|
|
|
|
|
#define HAVE_BSDSOCKET_GETHOSTBYNAME_R 0x01
|
|
|
|
#define HAVE_BSDSOCKET_GETADDRINFO 0x02
|
|
|
|
|
|
|
|
CURLcode Curl_amiga_init(void)
|
|
|
|
{
|
|
|
|
struct SocketIFace *ISocket;
|
|
|
|
struct Library *base = OpenLibrary("bsdsocket.library", 4);
|
|
|
|
|
|
|
|
if(base) {
|
|
|
|
ISocket = (struct SocketIFace *)GetInterface(base, "main", 1, NULL);
|
|
|
|
if(ISocket) {
|
|
|
|
ULONG enabled = 0;
|
|
|
|
|
|
|
|
SocketBaseTags(SBTM_SETVAL(SBTC_CAN_SHARE_LIBRARY_BASES), TRUE,
|
|
|
|
SBTM_GETREF(SBTC_HAVE_GETHOSTADDR_R_API), (ULONG)&enabled,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
if(enabled) {
|
|
|
|
SocketFeatures |= HAVE_BSDSOCKET_GETHOSTBYNAME_R;
|
|
|
|
}
|
|
|
|
|
|
|
|
__CurlISocket = ISocket;
|
|
|
|
|
|
|
|
atexit(Curl_amiga_cleanup);
|
|
|
|
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
CloseLibrary(base);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CURLE_FAILED_INIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Curl_amiga_cleanup(void)
|
|
|
|
{
|
|
|
|
if(__CurlISocket) {
|
|
|
|
struct Library *base = __CurlISocket->Data.LibBase;
|
|
|
|
DropInterface((struct Interface *)__CurlISocket);
|
|
|
|
CloseLibrary(base);
|
|
|
|
__CurlISocket = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CURLRES_AMIGA
|
|
|
|
/*
|
|
|
|
* Because we need to handle the different cases in hostip4.c at run-time,
|
|
|
|
* not at compile-time, based on what was detected in Curl_amiga_init(),
|
|
|
|
* we replace it completely with our own as to not complicate the baseline
|
|
|
|
* code. Assumes malloc/calloc/free are thread safe because Curl_he2ai()
|
|
|
|
* allocates memory also.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
|
|
|
|
int port)
|
|
|
|
{
|
|
|
|
struct Curl_addrinfo *ai = NULL;
|
|
|
|
struct hostent *h;
|
|
|
|
struct SocketIFace *ISocket = __CurlISocket;
|
|
|
|
|
|
|
|
if(SocketFeatures & HAVE_BSDSOCKET_GETHOSTBYNAME_R) {
|
|
|
|
LONG h_errnop = 0;
|
|
|
|
struct hostent *buf;
|
|
|
|
|
|
|
|
buf = calloc(1, CURL_HOSTENT_SIZE);
|
|
|
|
if(buf) {
|
|
|
|
h = gethostbyname_r((STRPTR)hostname, buf,
|
|
|
|
(char *)buf + sizeof(struct hostent),
|
|
|
|
CURL_HOSTENT_SIZE - sizeof(struct hostent),
|
|
|
|
&h_errnop);
|
|
|
|
if(h) {
|
|
|
|
ai = Curl_he2ai(h, port);
|
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#ifdef CURLRES_THREADED
|
|
|
|
/* gethostbyname() is not thread safe, so we need to reopen bsdsocket
|
|
|
|
* on the thread's context
|
|
|
|
*/
|
|
|
|
struct Library *base = OpenLibrary("bsdsocket.library", 4);
|
|
|
|
if(base) {
|
|
|
|
ISocket = (struct SocketIFace *)GetInterface(base, "main", 1, NULL);
|
|
|
|
if(ISocket) {
|
|
|
|
h = gethostbyname((STRPTR)hostname);
|
|
|
|
if(h) {
|
|
|
|
ai = Curl_he2ai(h, port);
|
|
|
|
}
|
|
|
|
DropInterface((struct Interface *)ISocket);
|
|
|
|
}
|
|
|
|
CloseLibrary(base);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* not using threaded resolver - safe to use this as-is */
|
|
|
|
h = gethostbyname(hostname);
|
|
|
|
if(h) {
|
|
|
|
ai = Curl_he2ai(h, port);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return ai;
|
|
|
|
}
|
|
|
|
#endif /* CURLRES_AMIGA */
|
2022-08-08 00:04:47 +08:00
|
|
|
|
|
|
|
#ifdef USE_AMISSL
|
|
|
|
int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds,
|
|
|
|
fd_set *errorfds, struct timeval *timeout)
|
|
|
|
{
|
|
|
|
int r = WaitSelect(nfds, readfds, writefds, errorfds, timeout, 0);
|
|
|
|
/* Ensure Ctrl-C signal is actioned */
|
|
|
|
if((r == -1) && (SOCKERRNO == EINTR))
|
|
|
|
raise(SIGINT);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
#endif /* USE_AMISSL */
|
|
|
|
|
2022-08-07 21:42:19 +08:00
|
|
|
#elif !defined(USE_AMISSL) /* __amigaos4__ */
|
|
|
|
/*
|
|
|
|
* Amiga OS3 specific code
|
|
|
|
*/
|
|
|
|
|
2003-12-10 21:53:35 +08:00
|
|
|
struct Library *SocketBase = NULL;
|
2005-07-14 02:06:40 +08:00
|
|
|
extern int errno, h_errno;
|
|
|
|
|
|
|
|
#ifdef __libnix__
|
|
|
|
void __request(const char *msg);
|
|
|
|
#else
|
2016-04-04 02:28:34 +08:00
|
|
|
# define __request(msg) Printf(msg "\n\a")
|
2005-07-14 02:06:40 +08:00
|
|
|
#endif
|
2003-12-10 21:53:35 +08:00
|
|
|
|
2022-08-07 21:42:19 +08:00
|
|
|
void Curl_amiga_cleanup(void)
|
2003-12-10 21:53:35 +08:00
|
|
|
{
|
2009-02-27 16:53:10 +08:00
|
|
|
if(SocketBase) {
|
|
|
|
CloseLibrary(SocketBase);
|
|
|
|
SocketBase = NULL;
|
|
|
|
}
|
2003-12-10 21:53:35 +08:00
|
|
|
}
|
|
|
|
|
2022-08-07 21:42:19 +08:00
|
|
|
CURLcode Curl_amiga_init(void)
|
2003-12-10 21:53:35 +08:00
|
|
|
{
|
2009-02-27 16:53:10 +08:00
|
|
|
if(!SocketBase)
|
|
|
|
SocketBase = OpenLibrary("bsdsocket.library", 4);
|
|
|
|
|
|
|
|
if(!SocketBase) {
|
|
|
|
__request("No TCP/IP Stack running!");
|
2022-08-07 21:42:19 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
2009-02-27 16:53:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (ULONG) &errno,
|
2016-10-18 19:59:54 +08:00
|
|
|
SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG) "curl",
|
2009-02-27 16:53:10 +08:00
|
|
|
TAG_DONE)) {
|
|
|
|
__request("SocketBaseTags ERROR");
|
2022-08-07 21:42:19 +08:00
|
|
|
return CURLE_FAILED_INIT;
|
2009-02-27 16:53:10 +08:00
|
|
|
}
|
|
|
|
|
2005-07-14 02:06:40 +08:00
|
|
|
#ifndef __libnix__
|
2012-04-07 05:35:15 +08:00
|
|
|
atexit(Curl_amiga_cleanup);
|
2005-07-14 02:06:40 +08:00
|
|
|
#endif
|
2009-02-27 16:53:10 +08:00
|
|
|
|
2022-08-07 21:42:19 +08:00
|
|
|
return CURLE_OK;
|
2003-12-10 21:53:35 +08:00
|
|
|
}
|
2005-07-14 02:06:40 +08:00
|
|
|
|
|
|
|
#ifdef __libnix__
|
2015-03-17 20:41:49 +08:00
|
|
|
ADD2EXIT(Curl_amiga_cleanup, -50);
|
2009-10-28 00:38:42 +08:00
|
|
|
#endif
|
|
|
|
|
2022-08-07 21:42:19 +08:00
|
|
|
#endif /* !USE_AMISSL */
|
|
|
|
|
2019-03-08 08:06:59 +08:00
|
|
|
#endif /* HAVE_PROTO_BSDSOCKET_H */
|
|
|
|
|
|
|
|
#endif /* __AMIGA__ */
|