diff -ruN curl-7.34.0/include/curl/curlbuild.h curl-7.34.0.new/include/curl/curlbuild.h --- curl-7.34.0/include/curl/curlbuild.h 2013-12-17 08:51:32.000000000 +0100 +++ curl-7.34.0.new/include/curl/curlbuild.h 2014-01-24 11:17:04.000000000 +0100 @@ -522,6 +522,20 @@ # define CURL_TYPEOF_CURL_SOCKLEN_T int # define CURL_SIZEOF_CURL_SOCKLEN_T 4 +#elif defined(__MORPHOS__) +# define CURL_SIZEOF_LONG 4 +# define CURL_TYPEOF_CURL_OFF_T long long +# define CURL_FORMAT_CURL_OFF_T "lld" +# define CURL_FORMAT_CURL_OFF_TU "llu" +# define CURL_FORMAT_OFF_T "%lld" +# define CURL_SIZEOF_CURL_OFF_T 8 +# define CURL_SUFFIX_CURL_OFF_T LL +# define CURL_SUFFIX_CURL_OFF_TU ULL +# define CURL_TYPEOF_CURL_SOCKLEN_T int +# define CURL_SIZEOF_CURL_SOCKLEN_T 4 +# define CURL_PULL_SYS_TYPES_H 1 + + /* ===================================== */ /* KEEP GENERIC GCC THE LAST ENTRY */ /* ===================================== */ diff -ruN curl-7.34.0/lib/amigaos.c curl-7.34.0.new/lib/amigaos.c --- curl-7.34.0/lib/amigaos.c 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/amigaos.c 2014-01-24 11:17:06.000000000 +0100 @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -18,60 +18,82 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * + * $Id: curl-7.34.0.diff,v 1.1 2014/01/29 18:25:05 fab Exp $ ***************************************************************************/ -#include "curl_setup.h" - -#if defined(__AMIGA__) && !defined(__ixemul__) - -#include +#ifdef __AMIGA__ /* Any AmigaOS flavour */ #include "amigaos.h" +#include "vapor.h" +#include struct Library *SocketBase = NULL; extern int errno, h_errno; +// Threads support +struct MinList repliedMessages; +struct MsgPort *curlMsgPort = NULL; + +#undef __libnix__ + #ifdef __libnix__ #include void __request(const char *msg); #else -# define __request( msg ) Printf( msg "\n\a") +# define __request( msg ) Printf( msg "\n\a") #endif void Curl_amiga_cleanup() { - if(SocketBase) { - CloseLibrary(SocketBase); - SocketBase = NULL; - } + if(curlMsgPort) { + DeleteMsgPort(curlMsgPort); + curlMsgPort = NULL; + } + + if(SocketBase) { + CloseLibrary(SocketBase); + SocketBase = NULL; + } } bool Curl_amiga_init() { - if(!SocketBase) - SocketBase = OpenLibrary("bsdsocket.library", 4); + if(!SocketBase) + SocketBase = OpenLibrary("bsdsocket.library", 4); + + if(!SocketBase) { + __request("No TCP/IP Stack running!"); + return FALSE; + } + + if(SocketBaseTags( + SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (ULONG) &errno, +// SBTM_SETVAL(SBTC_HERRNOLONGPTR), (ULONG) &h_errno, + SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG) "cURL", + TAG_DONE)) { + return FALSE; + } + + if(!curlMsgPort) { + curlMsgPort = CreateMsgPort(); + } + + if(!curlMsgPort) { + Curl_amiga_cleanup(); + return FALSE; + } - if(!SocketBase) { - __request("No TCP/IP Stack running!"); - return FALSE; - } - - if(SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (ULONG) &errno, - SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG) "cURL", - TAG_DONE)) { - __request("SocketBaseTags ERROR"); - return FALSE; - } + NEWLIST(&repliedMessages); #ifndef __libnix__ - atexit(Curl_amiga_cleanup); + atexit(Curl_amiga_cleanup); #endif - return TRUE; + return TRUE; } #ifdef __libnix__ ADD2EXIT(Curl_amiga_cleanup,-50); #endif -#endif /* __AMIGA__ && ! __ixemul__ */ +#endif /* __AMIGA__ */ diff -ruN curl-7.34.0/lib/amigaos.h curl-7.34.0.new/lib/amigaos.h --- curl-7.34.0/lib/amigaos.h 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/amigaos.h 2014-01-24 11:17:06.000000000 +0100 @@ -23,7 +23,7 @@ ***************************************************************************/ #include "curl_setup.h" -#if defined(__AMIGA__) && !defined(__ixemul__) +#if defined(__AMIGA__) || defined(__MORPHOS__) /* Any AmigaOS flavour */ bool Curl_amiga_init(); void Curl_amiga_cleanup(); diff -ruN curl-7.34.0/lib/asyn-thread.c curl-7.34.0.new/lib/asyn-thread.c --- curl-7.34.0/lib/asyn-thread.c 2013-10-23 22:55:34.000000000 +0200 +++ curl-7.34.0.new/lib/asyn-thread.c 2014-01-24 11:17:06.000000000 +0100 @@ -45,6 +45,10 @@ # include # endif #endif +#ifdef __MORPHOS__ +#include +#include +#endif #if (defined(NETWARE) && defined(__NOVELL_LIBC__)) #undef in_addr_t @@ -136,6 +140,9 @@ return CURLE_OK; } +#ifdef __MORPHOS__ +static void abort_resolver_thread(struct connectdata *); +#endif static void destroy_async_data(struct Curl_async *); /* @@ -143,6 +150,9 @@ */ void Curl_resolver_cancel(struct connectdata *conn) { +#ifdef __MORPHOS__ + abort_resolver_thread(conn); +#endif destroy_async_data(&conn->async); } @@ -165,6 +175,9 @@ #ifdef HAVE_GETADDRINFO struct addrinfo hints; #endif +#ifdef __MORPHOS__ + struct Library *localSocketBase; +#endif }; struct thread_data { @@ -181,6 +194,17 @@ #define CONN_THREAD_SYNC_DATA(conn) &(((conn)->async.os_specific)->tsd); +#ifdef __MORPHOS__ +void abort_resolver_thread(struct connectdata *conn) +{ + if(conn->async.os_specific) { + struct thread_data *td = (struct thread_data*) conn->async.os_specific; + if(td->thread_hnd != curl_thread_t_null) + Curl_thread_destroy(td->thread_hnd); + } +} +#endif + /* Destroy resolver thread synchronization data */ static void destroy_thread_sync_data(struct thread_sync_data * tsd) @@ -294,7 +318,12 @@ { struct thread_sync_data *tsd = (struct thread_sync_data *)arg; +#ifdef __MORPHOS__ + tsd->localSocketBase = OpenLibrary("bsdsocket.library", 0); + tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port, tsd->localSocketBase); +#else tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port); +#endif if(!tsd->res) { tsd->sock_error = SOCKERRNO; @@ -306,6 +335,11 @@ tsd->done = 1; Curl_mutex_release(tsd->mtx); +#ifdef __MORPHOS__ + CloseLibrary(tsd->localSocketBase); + tsd->localSocketBase = NULL; +#endif + return 0; } @@ -542,7 +576,7 @@ } /* fall-back to blocking version */ - return Curl_ipv4_resolve_r(hostname, port); + return Curl_ipv4_resolve_r(hostname, port, SocketBase); } #else /* !HAVE_GETADDRINFO */ diff -ruN curl-7.34.0/lib/config.h curl-7.34.0.new/lib/config.h --- curl-7.34.0/lib/config.h 1970-01-01 01:00:00.000000000 +0100 +++ curl-7.34.0.new/lib/config.h 2014-01-24 11:17:06.000000000 +0100 @@ -0,0 +1,163 @@ +#ifndef LIBCURL_CONFIG_AMIGAOS_H +#define LIBCURL_CONFIG_AMIGAOS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * 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. + * + * $Id: curl-7.34.0.diff,v 1.1 2014/01/29 18:25:05 fab Exp $ + ***************************************************************************/ + +#if defined(__AMIGA__) || defined(__MORPHOS__) /* Any AmigaOS flavour */ + +#define HAVE_ARPA_INET_H 1 +#define HAVE_FCNTL_H 1 +#define HAVE_CLOSESOCKET_CAMEL 1 +#define HAVE_GETHOSTBYADDR 1 +#define HAVE_INET_ADDR 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_IOCTLSOCKET_CAMEL 1 +#define HAVE_IOCTLSOCKET_CAMEL_FIONBIO 1 +#define HAVE_LIBCRYPTO 1 +#define HAVE_LIBSSL 1 +#define HAVE_LIBZ 1 +#define HAVE_LONGLONG 1 +#define HAVE_MALLOC_H 1 +#define HAVE_MEMORY_H 1 +#define HAVE_NETDB_H 1 +#define HAVE_NETINET_IN_H 1 +#define HAVE_NET_IF_H 1 +#define HAVE_OPENSSL_CRYPTO_H 1 +#define HAVE_OPENSSL_ERR_H 1 +#define HAVE_OPENSSL_PEM_H 1 +#define HAVE_OPENSSL_RSA_H 1 +#define HAVE_OPENSSL_SSL_H 1 +#define HAVE_OPENSSL_X509_H 1 +#define HAVE_PERROR 1 +#define HAVE_PWD_H 1 +#define HAVE_RAND_EGD 1 +#define HAVE_RAND_STATUS 1 +#define HAVE_SELECT 1 +#define HAVE_SETJMP_H 1 +#define HAVE_SGTTY_H 1 +#define HAVE_SIGNAL 1 +#define HAVE_SIGNAL_H 1 +#define HAVE_SIG_ATOMIC_T 1 +#define HAVE_SOCKET 1 +#define HAVE_STRCASECMP 1 +#define HAVE_STRDUP 1 +#define HAVE_STRFTIME 1 +#define HAVE_STRICMP 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRSTR 1 +#define HAVE_STRUCT_TIMEVAL 1 +#define HAVE_SYS_PARAM_H 1 +#define HAVE_SYS_SOCKET_H 1 +#define HAVE_SYS_SOCKIO_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_TERMIOS_H 1 +#define HAVE_TERMIO_H 1 +#define HAVE_TIME_H 1 +#define HAVE_UNAME 1 +#define HAVE_UNISTD_H 1 +#define HAVE_UTIME 1 +#define HAVE_UTIME_H 1 +#define HAVE_WRITABLE_ARGV 1 +#define HAVE_ZLIB_H 1 +#define HAVE_SYS_IOCTL_H 1 + +#define NEED_MALLOC_H 1 + +#define SIZEOF_SIZE_T 4 +#define SIZEOF_INT 4 +#define SIZEOF_SHORT 2 + +#define USE_OPENSSL 1 +#define USE_SSLEAY 1 +#define CURL_DISABLE_LDAP 1 + + +#define OS "MorphOS" + +#define PACKAGE "curl" +#define PACKAGE_BUGREPORT "curl-bug@haxx.se" +#define PACKAGE_NAME "curl" +#define PACKAGE_STRING "curl -" +#define PACKAGE_TARNAME "curl" +#define PACKAGE_VERSION "-" +#define CURL_CA_BUNDLE "PROGDIR:curl-ca-bundle.crt" + +#define RETSIGTYPE void +#define SELECT_TYPE_ARG1 int +#define SELECT_TYPE_ARG234 (fd_set *) +#define SELECT_TYPE_ARG5 (struct timeval *) + +#define STDC_HEADERS 1 +#define TIME_WITH_SYS_TIME 1 + +#define in_addr_t int + +#ifndef O_RDONLY +# define O_RDONLY 0x0000 +#endif + +#define HAVE_GETNAMEINFO 1 +#define GETNAMEINFO_QUAL_ARG1 const +#define GETNAMEINFO_TYPE_ARG1 struct sockaddr * +#define GETNAMEINFO_TYPE_ARG2 int +#define GETNAMEINFO_TYPE_ARG46 size_t +#define GETNAMEINFO_TYPE_ARG7 int + +#define HAVE_RECV 1 +#define RECV_TYPE_ARG1 long +#define RECV_TYPE_ARG2 char * +#define RECV_TYPE_ARG3 long +#define RECV_TYPE_ARG4 long +#define RECV_TYPE_RETV long + +#define HAVE_RECVFROM 1 +#define RECVFROM_TYPE_ARG1 long +#define RECVFROM_TYPE_ARG2 char +#define RECVFROM_TYPE_ARG3 long +#define RECVFROM_TYPE_ARG4 long +#define RECVFROM_TYPE_ARG5 struct sockaddr +#define RECVFROM_TYPE_ARG6 long +#define RECVFROM_TYPE_RETV long + +#define HAVE_SEND 1 +#define SEND_TYPE_ARG1 int +#define SEND_QUAL_ARG2 const +#define SEND_TYPE_ARG2 char * +#define SEND_TYPE_ARG3 int +#define SEND_TYPE_ARG4 int +#define SEND_TYPE_RETV int + +#ifndef socklen_t +# define socklen_t int +#endif + +#define USE_THREADS_MORPHOS 1 + +//#undef HAVE_LIBRTMP +//#undef HAVE_LIBRTMP_RTMP_H + +#endif /* __AMIGA__ */ +#endif /* LIBCURL_CONFIG_AMIGAOS_H */ diff -ruN curl-7.34.0/lib/connect.c curl-7.34.0.new/lib/connect.c --- curl-7.34.0/lib/connect.c 2013-12-16 23:02:35.000000000 +0100 +++ curl-7.34.0.new/lib/connect.c 2014-01-24 11:17:06.000000000 +0100 @@ -556,7 +556,7 @@ else { /* happy eyeballs - try the other protocol family */ int firstfamily = conn->tempaddr[0]->ai_family; - family = (firstfamily == AF_INET) ? AF_INET6 : AF_INET; + family = /* (firstfamily == AF_INET) ? AF_INET6 : */AF_INET; ai = conn->tempaddr[0]->ai_next; } diff -ruN curl-7.34.0/lib/curl_setup.h curl-7.34.0.new/lib/curl_setup.h --- curl-7.34.0/lib/curl_setup.h 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/curl_setup.h 2014-01-24 11:17:06.000000000 +0100 @@ -58,8 +58,8 @@ # include "config-riscos.h" #endif -#ifdef __AMIGA__ -# include "config-amigaos.h" +#if defined(__AMIGA__) || defined(__MORPHOS__) +# include "config.h" #endif #ifdef __SYMBIAN32__ @@ -327,7 +327,9 @@ # include # include # include +#ifndef __MORPHOS__ # define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0) +#endif # endif #endif @@ -544,7 +546,7 @@ /* now undef the stock libc functions just to avoid them being used */ # undef HAVE_GETADDRINFO # undef HAVE_GETHOSTBYNAME -#elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) +#elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) || defined(USE_THREADS_MORPHOS) # define CURLRES_ASYNCH # define CURLRES_THREADED #else diff -ruN curl-7.34.0/lib/curl_threads.c curl-7.34.0.new/lib/curl_threads.c --- curl-7.34.0/lib/curl_threads.c 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/curl_threads.c 2014-01-24 11:17:06.000000000 +0100 @@ -94,6 +94,240 @@ return ret; } +#elif defined(USE_THREADS_MORPHOS) + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "vapor.h" + +#define D(x) + +struct ThreadStartMsg +{ + struct Message tsm_Msg; + void* tsm_Result; +}; + +struct ThreadHandle +{ + ULONG td_PID; + struct Process* td_Thread; + struct MsgPort* td_MsgPort; +}; + +struct ThreadStartMsgNode +{ + struct MinNode tsmn_Node; + struct ThreadHandle *tsmn_Thread; + struct ThreadStartMsg *tsmn_Msg; + ULONG tsmn_Replied; +}; + + +struct curl_actual_call +{ + unsigned int (*func)(void *); + void *arg; +}; + +static void *curl_thread_create_thunk(void *arg) +{ + struct curl_actual_call * ac = arg; + unsigned int (*func)(void *) = ac->func; + void *real_arg = ac->arg; + + free(ac); + + (*func)(real_arg); + + return 0; +} + +extern struct MsgPort *curlMsgPort; +extern struct MinList repliedMessages; + +curl_thread_t Curl_thread_create(unsigned int (*func) (void*), void *arg) +{ + curl_thread_t t; + struct curl_actual_call *ac = malloc(sizeof(struct curl_actual_call)); + + D(kprintf("[CURL] Curl_thread_create()\n")); + + if(!ac) + return curl_thread_t_null; + + t = (curl_thread_t) malloc(sizeof(*t)); + + if(t) + { + ac->func = func; + ac->arg = arg; + + t->td_PID = 0; + t->td_MsgPort = curlMsgPort; + + if(t->td_MsgPort) + { + struct ThreadStartMsgNode *n; + + n = (struct ThreadStartMsgNode *) malloc(sizeof(struct ThreadStartMsgNode)); + if(n) + { + struct ThreadStartMsg* startup_msg; + + startup_msg = (struct ThreadStartMsg*) malloc(sizeof(struct ThreadStartMsg)); + if(startup_msg) + { + memset(startup_msg, 0, sizeof(struct ThreadStartMsg)); + + startup_msg->tsm_Msg.mn_Node.ln_Type = NT_MESSAGE; + startup_msg->tsm_Msg.mn_ReplyPort = t->td_MsgPort; + startup_msg->tsm_Msg.mn_Length = sizeof (*startup_msg); + + t->td_Thread = CreateNewProcTags(NP_Entry, (ULONG) curl_thread_create_thunk, + NP_Name, (ULONG) "CURL resolver thread", + NP_CodeType, CODETYPE_PPC, + NP_StartupMsg, (ULONG) startup_msg, + NP_PPC_Arg1, (ULONG) ac, + TAG_DONE); + if(t->td_Thread) + { + NewGetTaskAttrs((struct Task *) t->td_Thread, &t->td_PID, sizeof(t->td_PID), TASKINFOTYPE_PID); + n->tsmn_Replied = FALSE; + n->tsmn_Thread = t; + n->tsmn_Msg = startup_msg; + ADDTAIL(&repliedMessages, n); + D(kprintf("[CURL] Adding node %p (thread %p, msg %p)\n", n, t, startup_msg)); + return t; + } + + free(startup_msg); + } + + free(n); + } + } + free(t); + } + + D(kprintf("[CURL] Curl_create_thread failed\n")); + + free(ac); + return curl_thread_t_null; +} + +void Curl_thread_destroy(curl_thread_t hnd) +{ + D(kprintf("Curl_thread_destroy %p\n", hnd)); + if(hnd != curl_thread_t_null) + { + struct Task *task; + Forbid(); + if(hnd->td_PID != 0 && (task = FindTaskByPID(hnd->td_PID))) + { + Signal(task, SIGBREAKF_CTRL_C); + } + Permit(); + } +} + +int Curl_thread_join(curl_thread_t *hnd) +{ + struct ThreadStartMsg* tsm; + ULONG processed = FALSE; + APTR n, m; + + D(kprintf("[CURL] Curl_thread_join(%p)\n", *hnd)); + + // Check if there were some replied messages for this thread already + ITERATELISTSAFE(n, m, &repliedMessages) + { + struct ThreadStartMsgNode *msgnode = (struct ThreadStartMsgNode *) n; + + // IF the thread has already replied before, free it and return + if(msgnode->tsmn_Thread == *hnd && msgnode->tsmn_Replied) + { + D(kprintf("[CURL] Found a previous reply for thread %p in node %p\n", msgnode->tsmn_Thread, n)); + + REMOVE(msgnode); + free(msgnode->tsmn_Msg); + free(msgnode); + processed = TRUE; + break; + } + } + + // The thread hasn't replied yet, wait for it + while(!processed) + { + D(kprintf("[CURL] Waiting for any thread termination\n")); + + WaitPort((*hnd)->td_MsgPort); + tsm = (struct ThreadStartMsg*) GetMsg((*hnd)->td_MsgPort); + if(tsm) + { + // We received a message, but not necessarily the one we're waiting for. See who it belongs to + APTR n, m; + + D(kprintf("[CURL] Received message %p\n", tsm)); + + ITERATELISTSAFE(n, m, &repliedMessages) + { + struct ThreadStartMsgNode *msgnode = (struct ThreadStartMsgNode *) n; + + if(msgnode->tsmn_Msg == tsm) + { + D(kprintf("[CURL] message %p belongs to node %p\n", tsm, msgnode)); + + // That's the thread we're waiting for + if(msgnode->tsmn_Thread == *hnd) + { + D(kprintf("[CURL] This message is for us\n")); + + REMOVE(msgnode); + free(msgnode->tsmn_Msg); + free(msgnode); + processed = TRUE; + break; + } + // It's not the thread we're waiting for. Mark it as replied and wait again + else + { + D(kprintf("[CURL] This message is NOT for us, mark it as replied\n")); + msgnode->tsmn_Replied = TRUE; + break; + } + } + } + } + } + + free(*hnd); + *hnd = curl_thread_t_null; + + D(kprintf("[CURL] Curl_thread_join() ok\n", *hnd)); + + return 1; +} + +void Curl_thread_abort_all(void) +{ + APTR n, m; + ITERATELISTSAFE(n, m, &repliedMessages) + { + struct ThreadStartMsgNode *msgnode = (struct ThreadStartMsgNode *) n; + Curl_thread_join(&(msgnode->tsmn_Thread)); + } +} + #elif defined(USE_THREADS_WIN32) curl_thread_t Curl_thread_create(unsigned int (CURL_STDCALL *func) (void*), diff -ruN curl-7.34.0/lib/curl_threads.h curl-7.34.0.new/lib/curl_threads.h --- curl-7.34.0/lib/curl_threads.h 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/curl_threads.h 2014-01-24 11:17:06.000000000 +0100 @@ -41,9 +41,20 @@ # define Curl_mutex_acquire(m) EnterCriticalSection(m) # define Curl_mutex_release(m) LeaveCriticalSection(m) # define Curl_mutex_destroy(m) DeleteCriticalSection(m) +#elif defined(USE_THREADS_MORPHOS) +struct ThreadHandle; +struct SignalSemaphore; +# define CURL_STDCALL +# define curl_mutex_t struct SignalSemaphore +# define curl_thread_t struct ThreadHandle * +# define curl_thread_t_null (struct ThreadHandle *)0 +# define Curl_mutex_init(m) InitSemaphore(m) +# define Curl_mutex_acquire(m) ObtainSemaphore(m) +# define Curl_mutex_release(m) ReleaseSemaphore(m) +# define Curl_mutex_destroy(m) #endif -#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) +#if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32) || defined(__MORPHOS__) curl_thread_t Curl_thread_create(unsigned int (CURL_STDCALL *func) (void*), void *arg); diff -ruN curl-7.34.0/lib/file.c curl-7.34.0.new/lib/file.c --- curl-7.34.0/lib/file.c 2013-10-23 22:55:34.000000000 +0200 +++ curl-7.34.0.new/lib/file.c 2014-01-24 11:17:06.000000000 +0100 @@ -44,7 +44,7 @@ #include #endif -#ifdef HAVE_FCNTL_H +#if defined(HAVE_FCNTL_H) || defined(__MORPHOS__) #include #endif @@ -191,7 +191,7 @@ char *real_path; struct FILEPROTO *file = data->req.protop; int fd; -#ifdef DOS_FILESYSTEM +#if defined(DOS_FILESYSTEM) || defined(__MORPHOS__) int i; char *actual_path; #endif @@ -230,6 +230,11 @@ fd = open_readonly(actual_path, O_RDONLY|O_BINARY); file->path = actual_path; +#elif __MORPHOS__ + actual_path = real_path; + actual_path++; + fd = open(actual_path, O_RDONLY); /* no CR/LF translation! */ + file->path = actual_path; #else fd = open_readonly(real_path, O_RDONLY); file->path = real_path; @@ -539,7 +544,7 @@ if(data->state.resume_from) { if(data->state.resume_from != - lseek(fd, data->state.resume_from, SEEK_SET)) + lseek(fd, data->state.resume_from, SEEK_SET)) return CURLE_BAD_DOWNLOAD_RESUME; } diff -ruN curl-7.34.0/lib/hostip4.c curl-7.34.0.new/lib/hostip4.c --- curl-7.34.0/lib/hostip4.c 2013-10-23 22:55:34.000000000 +0200 +++ curl-7.34.0.new/lib/hostip4.c 2014-01-24 11:17:06.000000000 +0100 @@ -75,6 +75,11 @@ #ifdef CURLRES_SYNCH +#ifdef __MORPHOS__ +#include +extern struct Library *SocketBase; +#endif + /* * Curl_getaddrinfo() - the ipv4 synchronous version. * @@ -104,7 +109,7 @@ *waitp = 0; /* synchronous response only */ - ai = Curl_ipv4_resolve_r(hostname, port); + ai = Curl_ipv4_resolve_r(hostname, port, SocketBase); if(!ai) infof(conn->data, "Curl_ipv4_resolve_r failed for %s\n", hostname); @@ -113,6 +118,7 @@ #endif /* CURLRES_SYNCH */ #endif /* CURLRES_IPV4 */ +#ifndef __MORPHOS__ #if defined(CURLRES_IPV4) && !defined(CURLRES_ARES) /* @@ -307,4 +313,46 @@ return ai; } + #endif /* defined(CURLRES_IPV4) && !defined(CURLRES_ARES) */ +#else + +#define my_gethostbyname(__p0) \ + LP1(210, struct hostent *, gethostbyname, \ + const UBYTE *, __p0, a0, \ + , localSocketBase, 0, 0, 0, 0, 0, 0) + +Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, + int port, void *localSocketBase) +{ + Curl_addrinfo *ai = NULL; + struct hostent *h = NULL; + struct in_addr in; + + if(Curl_inet_pton(AF_INET, hostname, &in) > 0) + { + /* This is a dotted IP address 123.123.123.123-style */ + return Curl_ip2addr(AF_INET, &in, hostname, port); + + /* + * Here is code for platforms that don't have a thread safe + * getaddrinfo() nor gethostbyname_r() function or for which + * gethostbyname() is the preferred one. + */ + } + else + { + if(localSocketBase) + { + h = my_gethostbyname((void*)hostname); + } + } + + if(h) + { + ai = Curl_he2ai(h, port); + } + + return ai; +} +#endif diff -ruN curl-7.34.0/lib/hostip.h curl-7.34.0.new/lib/hostip.h --- curl-7.34.0/lib/hostip.h 2013-10-23 22:55:34.000000000 +0200 +++ curl-7.34.0.new/lib/hostip.h 2014-01-24 11:17:06.000000000 +0100 @@ -144,7 +144,7 @@ #endif /* IPv4 threadsafe resolve function used for synch and asynch builds */ -Curl_addrinfo *Curl_ipv4_resolve_r(const char * hostname, int port); +Curl_addrinfo *Curl_ipv4_resolve_r(const char * hostname, int port, void *localSocketBase); CURLcode Curl_async_resolved(struct connectdata *conn, bool *protocol_connect); diff -ruN curl-7.34.0/lib/makefile curl-7.34.0.new/lib/makefile --- curl-7.34.0/lib/makefile 1970-01-01 01:00:00.000000000 +0100 +++ curl-7.34.0.new/lib/makefile 2014-01-24 11:17:05.000000000 +0100 @@ -0,0 +1,25 @@ +# +# libcurl Makefile for AmigaOS ... +# + +# change the follow to where you have the AmiTCP SDK v4.3 includes: + +ATCPSDKI= /GG/netinclude + +CC = ppc-morphos-gcc +CFLAGS = -O2 -noixemul -D__MORPHOS_SHAREDLIBS -Dsocklen_t=int -D__AMIGA__ -fno-strict-aliasing -I. -I../include -I../include/curl -I../../../instdir/include -W -Wall -include /gg/includestd/errno.h + +include Makefile.inc +CSOURCES += amigaos.c +OBJS = $(CSOURCES:.c=.o) + +all: $(OBJS) + ar cru libcurl.a $(OBJS) + ranlib libcurl.a + +clean: + @rm -rf *.o *.a + +install: + $(INSTALL) -c ./libcurl.a /lib/libcurl.a + diff -ruN curl-7.34.0/lib/makefile.amiga curl-7.34.0.new/lib/makefile.amiga --- curl-7.34.0/lib/makefile.amiga 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/makefile.amiga 2014-01-24 11:17:06.000000000 +0100 @@ -6,9 +6,8 @@ ATCPSDKI= /GG/netinclude - -CC = m68k-amigaos-gcc -CFLAGS = -I$(ATCPSDKI) -m68020-60 -O2 -msoft-float -noixemul -g -I. -I../include -W -Wall +CC = gcc +CFLAGS = -O2 -noixemul -Dsocklen_t=int -D__AMIGA__ -fno-strict-aliasing -I. -I../include -I../include/curl -W -Wall include Makefile.inc OBJS = $(CSOURCES:.c=.o) @@ -17,5 +16,9 @@ ar cru libcurl.a $(OBJS) ranlib libcurl.a +clean: + @rm -rf *.o *.a + install: $(INSTALL) -c ./libcurl.a /lib/libcurl.a + diff -ruN curl-7.34.0/lib/nonblock.c curl-7.34.0.new/lib/nonblock.c --- curl-7.34.0/lib/nonblock.c 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/nonblock.c 2014-01-24 11:17:06.000000000 +0100 @@ -76,8 +76,13 @@ #elif defined(HAVE_IOCTLSOCKET_CAMEL_FIONBIO) /* Amiga */ +#ifdef __MORPHOS__ + char f = (char) nonblock; + return IoctlSocket(sockfd, FIONBIO, (char *)&f); +#else long flags = nonblock ? 1L : 0L; return IoctlSocket(sockfd, FIONBIO, flags); +#endif #elif defined(HAVE_SETSOCKOPT_SO_NONBLOCK) diff -ruN curl-7.34.0/lib/select.c curl-7.34.0.new/lib/select.c --- curl-7.34.0/lib/select.c 2013-09-09 00:11:15.000000000 +0200 +++ curl-7.34.0.new/lib/select.c 2014-01-24 11:17:05.000000000 +0100 @@ -26,6 +26,10 @@ #include #endif +#ifdef __MORPHOS__ +#include +#endif + #if !defined(HAVE_SELECT) && !defined(HAVE_POLL_FINE) #error "We can't compile without select() or poll() support." #endif diff -ruN curl-7.34.0/lib/vapor.h curl-7.34.0.new/lib/vapor.h --- curl-7.34.0/lib/vapor.h 1970-01-01 01:00:00.000000000 +0100 +++ curl-7.34.0.new/lib/vapor.h 2014-01-24 11:17:06.000000000 +0100 @@ -0,0 +1,76 @@ +#ifndef VAPOR_MACROS_H +#define VAPOR_MACROS_H + +/* Exec list support macros */ +#ifndef EXEC_LISTS_H +#include +#endif + +/* following 2 macros DON'T return NULL when the list is empty ! */ +#ifndef FIRSTNODE +#define FIRSTNODE(l) ((APTR)((struct List*)l)->lh_Head) +#endif + +#ifndef LASTNODE +#define LASTNODE(l) ((APTR)((struct List*)l)->lh_TailPred) +#endif + +#ifndef NEXTNODE +#define NEXTNODE(n) ((APTR)((struct Node*)n)->ln_Succ) +#endif + +#ifndef PREVNODE +#define PREVNODE(n) ((APTR)((struct Node*)n)->ln_Pred) +#endif + +#ifndef FINDNAME +#define FINDNAME(l,n) ((APTR)FindName((struct List*)l,n)) +#endif + +#ifndef REMHEAD +#define REMHEAD(l) ((APTR)RemHead((struct List*)l)) +#endif + +#ifndef REMTAIL +#define REMTAIL(l) ((APTR)RemTail((struct List*)l)) +#endif + +#ifndef REMOVE +#define REMOVE(n) Remove((struct Node*)n) +#endif + +#ifndef ADDHEAD +#define ADDHEAD(l,n) AddHead((struct List*)l,(struct Node*)n) +#endif + +#ifndef ADDTAIL +#define ADDTAIL(l,n) AddTail((struct List*)l,(struct Node*)n) +#endif + +#ifndef ENQUEUE +#define ENQUEUE(l,n) Enqueue((struct List*)l,(struct Node*)n) +#endif + +#ifndef NEWLIST +#define NEWLIST(l) NewList((struct List*)l) +#endif + +#ifndef ISLISTEMPTY +#define ISLISTEMPTY(l) IsListEmpty(((struct List*)l)) +#endif + +/* + * Those functions are safe to use in an empty list, but do NOT remove list members + * within them ! + */ +#define ITERATELIST(node,list) for(node=FIRSTNODE(list);NEXTNODE(node);node=NEXTNODE(node)) +#define TRAVERSELIST(node,list) ITERATELIST(node,list) + +/* + * These routines are like the ones above, except that it's safe to remove and/or + * re-insert/free the node. + */ +#define ITERATELISTSAFE(node,nextnode,list) for(node=FIRSTNODE(list);(nextnode=NEXTNODE(node));node=nextnode) +#define TRAVERSELISTSAFE(node,nextnode,list) ITERATELISTSAFE(node,nextnode,list) + +#endif /* VAPOR_MACROS_H */