Fossil SCM

Initial incomplete port to MorphOS. Needs some manual overrides to compile and has some locking issues in SQLite.

js 2025-04-22 01:10 trunk
Commit 66f279e14332a4e592c7434e833d135e09b3100be622e58ccd80488742b981b2
+23 -1
--- src/cgi.c
+++ src/cgi.c
@@ -80,11 +80,11 @@
8080
# include <sys/time.h>
8181
# include <sys/wait.h>
8282
# include <sys/select.h>
8383
# include <errno.h>
8484
#endif
85
-#ifdef __EMX__
85
+#if defined(__EMX__) || defined(__morphos__)
8686
typedef int socklen_t;
8787
#endif
8888
#include <time.h>
8989
#include <stdio.h>
9090
#include <stdlib.h>
@@ -2083,12 +2083,14 @@
20832083
** aliasing rules.
20842084
*/
20852085
typedef union {
20862086
struct sockaddr sa; /* Abstract superclass */
20872087
struct sockaddr_in sa4; /* IPv4 */
2088
+#ifdef AF_INET6
20882089
struct sockaddr_in6 sa6; /* IPv6 */
20892090
struct sockaddr_storage sas; /* Should be the maximum of the above 3 */
2091
+#endif
20902092
} address;
20912093
20922094
/*
20932095
** Determine the IP address on the other side of a connection.
20942096
** Return a pointer to a string. Or return 0 if unable.
@@ -2097,19 +2099,25 @@
20972099
** each call.
20982100
*/
20992101
char *cgi_remote_ip(int fd){
21002102
address remoteAddr;
21012103
socklen_t size = sizeof(remoteAddr);
2104
+#ifdef AF_INET6
21022105
static char zHost[NI_MAXHOST];
2106
+#endif
21032107
if( getpeername(0, &remoteAddr.sa, &size) ){
21042108
return 0;
21052109
}
2110
+#ifdef AF_INET6
21062111
if( getnameinfo(&remoteAddr.sa, size, zHost, sizeof(zHost), 0, 0,
21072112
NI_NUMERICHOST) ){
21082113
return 0;
21092114
}
21102115
return zHost;
2116
+#else
2117
+ return inet_ntoa(((struct sockaddr_in *)&remoteAddr.sa)->sin_addr);
2118
+#endif
21112119
}
21122120
21132121
/*
21142122
** This routine handles a single HTTP request which is coming in on
21152123
** g.httpIn and which replies on g.httpOut
@@ -2550,11 +2558,13 @@
25502558
fd_set readfds; /* Set of file descriptors for select() */
25512559
socklen_t lenaddr; /* Length of the inaddr structure */
25522560
int child; /* PID of the child process */
25532561
int nchildren = 0; /* Number of child processes */
25542562
struct timeval delay; /* How long to wait inside select() */
2563
+#ifdef AF_INET6
25552564
struct sockaddr_in6 inaddr6; /* Address for IPv6 */
2565
+#endif
25562566
struct sockaddr_in inaddr4; /* Address for IPv4 */
25572567
struct sockaddr_un uxaddr; /* The address for unix-domain sockets */
25582568
int opt = 1; /* setsockopt flag */
25592569
int rc; /* Result code from system calls */
25602570
int iPort = mnPort; /* Port to try to use */
@@ -2615,10 +2625,11 @@
26152625
file_set_owner(g.zSockName, listen4, g.zSockOwner);
26162626
}
26172627
fossil_print("Listening for %s requests on unix socket %s\n",
26182628
zRequestType, g.zSockName);
26192629
fflush(stdout);
2630
+#ifdef AF_INET6
26202631
}else if( zIpAddr && strchr(zIpAddr,':')!=0 ){
26212632
/* CASE 2: TCP on IPv6 IP address specified by zIpAddr and on port iPort.
26222633
*/
26232634
assert( mnPort==mxPort );
26242635
memset(&inaddr6, 0, sizeof(inaddr6));
@@ -2644,10 +2655,11 @@
26442655
mxListen = listen6;
26452656
listen4 = -1;
26462657
fossil_print("Listening for %s requests on [%s]:%d\n",
26472658
zRequestType, zIpAddr, iPort);
26482659
fflush(stdout);
2660
+#endif
26492661
}else if( zIpAddr && zIpAddr[0] ){
26502662
/* CASE 3: TCP on IPv4 IP address specified by zIpAddr and on port iPort.
26512663
*/
26522664
assert( mnPort==mxPort );
26532665
memset(&inaddr4, 0, sizeof(inaddr4));
@@ -2706,10 +2718,11 @@
27062718
iPort++;
27072719
continue;
27082720
}
27092721
mxListen = listen4;
27102722
2723
+#ifdef AF_INET6
27112724
/* If we get here, that means we found an open TCP port at iPort for
27122725
** IPv4. Try to set up a corresponding IPv6 socket on the same port.
27132726
*/
27142727
memset(&inaddr6, 0, sizeof(inaddr6));
27152728
inaddr6.sin6_family = AF_INET6;
@@ -2733,10 +2746,13 @@
27332746
zProto = "IPv4 only";
27342747
}else{
27352748
zProto = "IPv4 and IPv6";
27362749
if( listen6>listen4 ) mxListen = listen6;
27372750
}
2751
+#else
2752
+ zProto = "IPv4 only";
2753
+#endif
27382754
27392755
fossil_print("Listening for %s requests on TCP port %s%d, %s\n",
27402756
zRequestType,
27412757
(flags & HTTP_SERVER_LOCALHOST)!=0 ? "localhost:" : "",
27422758
iPort, zProto);
@@ -2790,22 +2806,28 @@
27902806
if( listen6>0 ) FD_SET( listen6, &readfds);
27912807
select( mxListen+1, &readfds, 0, 0, &delay);
27922808
if( listen4>0 && FD_ISSET(listen4, &readfds) ){
27932809
lenaddr = sizeof(inaddr4);
27942810
connection = accept(listen4, (struct sockaddr*)&inaddr4, &lenaddr);
2811
+#ifdef AF_INET6
27952812
}else if( listen6>0 && FD_ISSET(listen6, &readfds) ){
27962813
lenaddr = sizeof(inaddr6);
27972814
connection = accept(listen6, (struct sockaddr*)&inaddr6, &lenaddr);
2815
+#endif
27982816
}else{
27992817
connection = -1;
28002818
}
28012819
if( connection>=0 ){
2820
+#ifndef __morphos__
28022821
if( flags & HTTP_SERVER_NOFORK ){
28032822
child = 0;
28042823
}else{
28052824
child = fork();
28062825
}
2826
+#else
2827
+ child = 0;
2828
+#endif
28072829
if( child!=0 ){
28082830
if( child>0 ){
28092831
nchildren++;
28102832
nRequest++;
28112833
}
28122834
--- src/cgi.c
+++ src/cgi.c
@@ -80,11 +80,11 @@
80 # include <sys/time.h>
81 # include <sys/wait.h>
82 # include <sys/select.h>
83 # include <errno.h>
84 #endif
85 #ifdef __EMX__
86 typedef int socklen_t;
87 #endif
88 #include <time.h>
89 #include <stdio.h>
90 #include <stdlib.h>
@@ -2083,12 +2083,14 @@
2083 ** aliasing rules.
2084 */
2085 typedef union {
2086 struct sockaddr sa; /* Abstract superclass */
2087 struct sockaddr_in sa4; /* IPv4 */
 
2088 struct sockaddr_in6 sa6; /* IPv6 */
2089 struct sockaddr_storage sas; /* Should be the maximum of the above 3 */
 
2090 } address;
2091
2092 /*
2093 ** Determine the IP address on the other side of a connection.
2094 ** Return a pointer to a string. Or return 0 if unable.
@@ -2097,19 +2099,25 @@
2097 ** each call.
2098 */
2099 char *cgi_remote_ip(int fd){
2100 address remoteAddr;
2101 socklen_t size = sizeof(remoteAddr);
 
2102 static char zHost[NI_MAXHOST];
 
2103 if( getpeername(0, &remoteAddr.sa, &size) ){
2104 return 0;
2105 }
 
2106 if( getnameinfo(&remoteAddr.sa, size, zHost, sizeof(zHost), 0, 0,
2107 NI_NUMERICHOST) ){
2108 return 0;
2109 }
2110 return zHost;
 
 
 
2111 }
2112
2113 /*
2114 ** This routine handles a single HTTP request which is coming in on
2115 ** g.httpIn and which replies on g.httpOut
@@ -2550,11 +2558,13 @@
2550 fd_set readfds; /* Set of file descriptors for select() */
2551 socklen_t lenaddr; /* Length of the inaddr structure */
2552 int child; /* PID of the child process */
2553 int nchildren = 0; /* Number of child processes */
2554 struct timeval delay; /* How long to wait inside select() */
 
2555 struct sockaddr_in6 inaddr6; /* Address for IPv6 */
 
2556 struct sockaddr_in inaddr4; /* Address for IPv4 */
2557 struct sockaddr_un uxaddr; /* The address for unix-domain sockets */
2558 int opt = 1; /* setsockopt flag */
2559 int rc; /* Result code from system calls */
2560 int iPort = mnPort; /* Port to try to use */
@@ -2615,10 +2625,11 @@
2615 file_set_owner(g.zSockName, listen4, g.zSockOwner);
2616 }
2617 fossil_print("Listening for %s requests on unix socket %s\n",
2618 zRequestType, g.zSockName);
2619 fflush(stdout);
 
2620 }else if( zIpAddr && strchr(zIpAddr,':')!=0 ){
2621 /* CASE 2: TCP on IPv6 IP address specified by zIpAddr and on port iPort.
2622 */
2623 assert( mnPort==mxPort );
2624 memset(&inaddr6, 0, sizeof(inaddr6));
@@ -2644,10 +2655,11 @@
2644 mxListen = listen6;
2645 listen4 = -1;
2646 fossil_print("Listening for %s requests on [%s]:%d\n",
2647 zRequestType, zIpAddr, iPort);
2648 fflush(stdout);
 
2649 }else if( zIpAddr && zIpAddr[0] ){
2650 /* CASE 3: TCP on IPv4 IP address specified by zIpAddr and on port iPort.
2651 */
2652 assert( mnPort==mxPort );
2653 memset(&inaddr4, 0, sizeof(inaddr4));
@@ -2706,10 +2718,11 @@
2706 iPort++;
2707 continue;
2708 }
2709 mxListen = listen4;
2710
 
2711 /* If we get here, that means we found an open TCP port at iPort for
2712 ** IPv4. Try to set up a corresponding IPv6 socket on the same port.
2713 */
2714 memset(&inaddr6, 0, sizeof(inaddr6));
2715 inaddr6.sin6_family = AF_INET6;
@@ -2733,10 +2746,13 @@
2733 zProto = "IPv4 only";
2734 }else{
2735 zProto = "IPv4 and IPv6";
2736 if( listen6>listen4 ) mxListen = listen6;
2737 }
 
 
 
2738
2739 fossil_print("Listening for %s requests on TCP port %s%d, %s\n",
2740 zRequestType,
2741 (flags & HTTP_SERVER_LOCALHOST)!=0 ? "localhost:" : "",
2742 iPort, zProto);
@@ -2790,22 +2806,28 @@
2790 if( listen6>0 ) FD_SET( listen6, &readfds);
2791 select( mxListen+1, &readfds, 0, 0, &delay);
2792 if( listen4>0 && FD_ISSET(listen4, &readfds) ){
2793 lenaddr = sizeof(inaddr4);
2794 connection = accept(listen4, (struct sockaddr*)&inaddr4, &lenaddr);
 
2795 }else if( listen6>0 && FD_ISSET(listen6, &readfds) ){
2796 lenaddr = sizeof(inaddr6);
2797 connection = accept(listen6, (struct sockaddr*)&inaddr6, &lenaddr);
 
2798 }else{
2799 connection = -1;
2800 }
2801 if( connection>=0 ){
 
2802 if( flags & HTTP_SERVER_NOFORK ){
2803 child = 0;
2804 }else{
2805 child = fork();
2806 }
 
 
 
2807 if( child!=0 ){
2808 if( child>0 ){
2809 nchildren++;
2810 nRequest++;
2811 }
2812
--- src/cgi.c
+++ src/cgi.c
@@ -80,11 +80,11 @@
80 # include <sys/time.h>
81 # include <sys/wait.h>
82 # include <sys/select.h>
83 # include <errno.h>
84 #endif
85 #if defined(__EMX__) || defined(__morphos__)
86 typedef int socklen_t;
87 #endif
88 #include <time.h>
89 #include <stdio.h>
90 #include <stdlib.h>
@@ -2083,12 +2083,14 @@
2083 ** aliasing rules.
2084 */
2085 typedef union {
2086 struct sockaddr sa; /* Abstract superclass */
2087 struct sockaddr_in sa4; /* IPv4 */
2088 #ifdef AF_INET6
2089 struct sockaddr_in6 sa6; /* IPv6 */
2090 struct sockaddr_storage sas; /* Should be the maximum of the above 3 */
2091 #endif
2092 } address;
2093
2094 /*
2095 ** Determine the IP address on the other side of a connection.
2096 ** Return a pointer to a string. Or return 0 if unable.
@@ -2097,19 +2099,25 @@
2099 ** each call.
2100 */
2101 char *cgi_remote_ip(int fd){
2102 address remoteAddr;
2103 socklen_t size = sizeof(remoteAddr);
2104 #ifdef AF_INET6
2105 static char zHost[NI_MAXHOST];
2106 #endif
2107 if( getpeername(0, &remoteAddr.sa, &size) ){
2108 return 0;
2109 }
2110 #ifdef AF_INET6
2111 if( getnameinfo(&remoteAddr.sa, size, zHost, sizeof(zHost), 0, 0,
2112 NI_NUMERICHOST) ){
2113 return 0;
2114 }
2115 return zHost;
2116 #else
2117 return inet_ntoa(((struct sockaddr_in *)&remoteAddr.sa)->sin_addr);
2118 #endif
2119 }
2120
2121 /*
2122 ** This routine handles a single HTTP request which is coming in on
2123 ** g.httpIn and which replies on g.httpOut
@@ -2550,11 +2558,13 @@
2558 fd_set readfds; /* Set of file descriptors for select() */
2559 socklen_t lenaddr; /* Length of the inaddr structure */
2560 int child; /* PID of the child process */
2561 int nchildren = 0; /* Number of child processes */
2562 struct timeval delay; /* How long to wait inside select() */
2563 #ifdef AF_INET6
2564 struct sockaddr_in6 inaddr6; /* Address for IPv6 */
2565 #endif
2566 struct sockaddr_in inaddr4; /* Address for IPv4 */
2567 struct sockaddr_un uxaddr; /* The address for unix-domain sockets */
2568 int opt = 1; /* setsockopt flag */
2569 int rc; /* Result code from system calls */
2570 int iPort = mnPort; /* Port to try to use */
@@ -2615,10 +2625,11 @@
2625 file_set_owner(g.zSockName, listen4, g.zSockOwner);
2626 }
2627 fossil_print("Listening for %s requests on unix socket %s\n",
2628 zRequestType, g.zSockName);
2629 fflush(stdout);
2630 #ifdef AF_INET6
2631 }else if( zIpAddr && strchr(zIpAddr,':')!=0 ){
2632 /* CASE 2: TCP on IPv6 IP address specified by zIpAddr and on port iPort.
2633 */
2634 assert( mnPort==mxPort );
2635 memset(&inaddr6, 0, sizeof(inaddr6));
@@ -2644,10 +2655,11 @@
2655 mxListen = listen6;
2656 listen4 = -1;
2657 fossil_print("Listening for %s requests on [%s]:%d\n",
2658 zRequestType, zIpAddr, iPort);
2659 fflush(stdout);
2660 #endif
2661 }else if( zIpAddr && zIpAddr[0] ){
2662 /* CASE 3: TCP on IPv4 IP address specified by zIpAddr and on port iPort.
2663 */
2664 assert( mnPort==mxPort );
2665 memset(&inaddr4, 0, sizeof(inaddr4));
@@ -2706,10 +2718,11 @@
2718 iPort++;
2719 continue;
2720 }
2721 mxListen = listen4;
2722
2723 #ifdef AF_INET6
2724 /* If we get here, that means we found an open TCP port at iPort for
2725 ** IPv4. Try to set up a corresponding IPv6 socket on the same port.
2726 */
2727 memset(&inaddr6, 0, sizeof(inaddr6));
2728 inaddr6.sin6_family = AF_INET6;
@@ -2733,10 +2746,13 @@
2746 zProto = "IPv4 only";
2747 }else{
2748 zProto = "IPv4 and IPv6";
2749 if( listen6>listen4 ) mxListen = listen6;
2750 }
2751 #else
2752 zProto = "IPv4 only";
2753 #endif
2754
2755 fossil_print("Listening for %s requests on TCP port %s%d, %s\n",
2756 zRequestType,
2757 (flags & HTTP_SERVER_LOCALHOST)!=0 ? "localhost:" : "",
2758 iPort, zProto);
@@ -2790,22 +2806,28 @@
2806 if( listen6>0 ) FD_SET( listen6, &readfds);
2807 select( mxListen+1, &readfds, 0, 0, &delay);
2808 if( listen4>0 && FD_ISSET(listen4, &readfds) ){
2809 lenaddr = sizeof(inaddr4);
2810 connection = accept(listen4, (struct sockaddr*)&inaddr4, &lenaddr);
2811 #ifdef AF_INET6
2812 }else if( listen6>0 && FD_ISSET(listen6, &readfds) ){
2813 lenaddr = sizeof(inaddr6);
2814 connection = accept(listen6, (struct sockaddr*)&inaddr6, &lenaddr);
2815 #endif
2816 }else{
2817 connection = -1;
2818 }
2819 if( connection>=0 ){
2820 #ifndef __morphos__
2821 if( flags & HTTP_SERVER_NOFORK ){
2822 child = 0;
2823 }else{
2824 child = fork();
2825 }
2826 #else
2827 child = 0;
2828 #endif
2829 if( child!=0 ){
2830 if( child>0 ){
2831 nchildren++;
2832 nRequest++;
2833 }
2834
+3 -1
--- src/fshell.c
+++ src/fshell.c
@@ -47,12 +47,14 @@
4747
**
4848
** This command only works on unix-like platforms that support fork().
4949
** It is non-functional on Windows.
5050
*/
5151
void shell_cmd(void){
52
-#ifdef _WIN32
52
+#if defined(_WIN32)
5353
fossil_fatal("the 'shell' command is not supported on windows");
54
+#elif defined(__morphos__)
55
+ fossil_fatal("the 'shell' command is not supported on MorphOS");
5456
#else
5557
int nArg;
5658
int mxArg = 0;
5759
int n, i;
5860
char **azArg = 0;
5961
--- src/fshell.c
+++ src/fshell.c
@@ -47,12 +47,14 @@
47 **
48 ** This command only works on unix-like platforms that support fork().
49 ** It is non-functional on Windows.
50 */
51 void shell_cmd(void){
52 #ifdef _WIN32
53 fossil_fatal("the 'shell' command is not supported on windows");
 
 
54 #else
55 int nArg;
56 int mxArg = 0;
57 int n, i;
58 char **azArg = 0;
59
--- src/fshell.c
+++ src/fshell.c
@@ -47,12 +47,14 @@
47 **
48 ** This command only works on unix-like platforms that support fork().
49 ** It is non-functional on Windows.
50 */
51 void shell_cmd(void){
52 #if defined(_WIN32)
53 fossil_fatal("the 'shell' command is not supported on windows");
54 #elif defined(__morphos__)
55 fossil_fatal("the 'shell' command is not supported on MorphOS");
56 #else
57 int nArg;
58 int mxArg = 0;
59 int n, i;
60 char **azArg = 0;
61
+4
--- src/gzip.c
+++ src/gzip.c
@@ -23,10 +23,14 @@
2323
*/
2424
#include "config.h"
2525
#include <assert.h>
2626
#include <zlib.h>
2727
#include "gzip.h"
28
+
29
+#ifdef __morphos__
30
+struct Library *ZBase;
31
+#endif
2832
2933
/*
3034
** State information for the GZIP file under construction.
3135
*/
3236
struct gzip_state {
3337
--- src/gzip.c
+++ src/gzip.c
@@ -23,10 +23,14 @@
23 */
24 #include "config.h"
25 #include <assert.h>
26 #include <zlib.h>
27 #include "gzip.h"
 
 
 
 
28
29 /*
30 ** State information for the GZIP file under construction.
31 */
32 struct gzip_state {
33
--- src/gzip.c
+++ src/gzip.c
@@ -23,10 +23,14 @@
23 */
24 #include "config.h"
25 #include <assert.h>
26 #include <zlib.h>
27 #include "gzip.h"
28
29 #ifdef __morphos__
30 struct Library *ZBase;
31 #endif
32
33 /*
34 ** State information for the GZIP file under construction.
35 */
36 struct gzip_state {
37
--- src/http_socket.c
+++ src/http_socket.c
@@ -42,14 +42,19 @@
4242
#else
4343
# include <netinet/in.h>
4444
# include <arpa/inet.h>
4545
# include <sys/socket.h>
4646
# include <netdb.h>
47
+# include <errno.h>
4748
#endif
4849
#include <assert.h>
4950
#include <sys/types.h>
5051
#include <signal.h>
52
+
53
+#if defined(__EMX__) || defined(__morphos__)
54
+ typedef int socklen_t;
55
+#endif
5156
5257
/*
5358
** There can only be a single socket connection open at a time.
5459
** State information about that socket is stored in the following
5560
** local variables:
@@ -144,18 +149,26 @@
144149
**
145150
** Return the number of errors.
146151
*/
147152
int socket_open(UrlData *pUrlData){
148153
int rc = 0;
154
+#ifdef AF_INET6
149155
struct addrinfo *ai = 0;
150156
struct addrinfo *p;
151157
struct addrinfo hints;
152158
char zPort[30];
153159
char zRemote[NI_MAXHOST];
160
+#else
161
+ struct hostent *hostent;
162
+ struct sockaddr_in sa;
163
+ socklen_t size = sizeof(sa);
164
+ int i;
165
+#endif
154166
155167
socket_global_init();
156168
socket_close();
169
+#ifdef AF_INET6
157170
memset(&hints, 0, sizeof(struct addrinfo));
158171
hints.ai_family = g.fIPv4 ? AF_INET : AF_UNSPEC;
159172
hints.ai_socktype = SOCK_STREAM;
160173
hints.ai_protocol = IPPROTO_TCP;
161174
sqlite3_snprintf(sizeof(zPort),zPort,"%d", pUrlData->port);
@@ -183,16 +196,45 @@
183196
if( p==0 ){
184197
socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
185198
pUrlData->port);
186199
rc = 1;
187200
}
201
+#else
202
+ hostent = gethostbyname(pUrlData->name);
203
+ if ( !hostent ){
204
+ socket_set_errmsg("gethostbyname() failed: %s", strerror(errno));
205
+ goto end_socket_open;
206
+ }
207
+ iSocket = socket(AF_INET, SOCK_STREAM, 0);
208
+ if( iSocket< 0 ){
209
+ socket_set_errmsg("socket() failed: %s", strerror(errno));
210
+ goto end_socket_open;
211
+ }
212
+ memset(&sa, 0, sizeof(sa));
213
+ sa.sin_family = AF_INET;
214
+ for (i=0; hostent->h_addr_list[i]!=0; i++){
215
+ sa.sin_addr = *(struct in_addr *)hostent->h_addr_list[i];
216
+ if( connect(iSocket,(struct sockaddr *)&sa,size)<0 ){
217
+ sa.sin_addr.s_addr = 0;
218
+ continue;
219
+ }
220
+ g.zIpAddr = mprintf("%s", inet_ntoa(sa.sin_addr));
221
+ }
222
+ if( sa.sin_addr.s_addr==0 ){
223
+ socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
224
+ pUrlData->port);
225
+ rc = 1;
226
+ }
227
+#endif
188228
#if !defined(_WIN32)
189229
signal(SIGPIPE, SIG_IGN);
190230
#endif
191231
end_socket_open:
192232
if( rc && iSocket>=0 ) socket_close();
233
+#ifdef AF_INET6
193234
if( ai ) freeaddrinfo(ai);
235
+#endif
194236
return rc;
195237
}
196238
197239
/*
198240
** Send content out over the open socket connection.
199241
--- src/http_socket.c
+++ src/http_socket.c
@@ -42,14 +42,19 @@
42 #else
43 # include <netinet/in.h>
44 # include <arpa/inet.h>
45 # include <sys/socket.h>
46 # include <netdb.h>
 
47 #endif
48 #include <assert.h>
49 #include <sys/types.h>
50 #include <signal.h>
 
 
 
 
51
52 /*
53 ** There can only be a single socket connection open at a time.
54 ** State information about that socket is stored in the following
55 ** local variables:
@@ -144,18 +149,26 @@
144 **
145 ** Return the number of errors.
146 */
147 int socket_open(UrlData *pUrlData){
148 int rc = 0;
 
149 struct addrinfo *ai = 0;
150 struct addrinfo *p;
151 struct addrinfo hints;
152 char zPort[30];
153 char zRemote[NI_MAXHOST];
 
 
 
 
 
 
154
155 socket_global_init();
156 socket_close();
 
157 memset(&hints, 0, sizeof(struct addrinfo));
158 hints.ai_family = g.fIPv4 ? AF_INET : AF_UNSPEC;
159 hints.ai_socktype = SOCK_STREAM;
160 hints.ai_protocol = IPPROTO_TCP;
161 sqlite3_snprintf(sizeof(zPort),zPort,"%d", pUrlData->port);
@@ -183,16 +196,45 @@
183 if( p==0 ){
184 socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
185 pUrlData->port);
186 rc = 1;
187 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188 #if !defined(_WIN32)
189 signal(SIGPIPE, SIG_IGN);
190 #endif
191 end_socket_open:
192 if( rc && iSocket>=0 ) socket_close();
 
193 if( ai ) freeaddrinfo(ai);
 
194 return rc;
195 }
196
197 /*
198 ** Send content out over the open socket connection.
199
--- src/http_socket.c
+++ src/http_socket.c
@@ -42,14 +42,19 @@
42 #else
43 # include <netinet/in.h>
44 # include <arpa/inet.h>
45 # include <sys/socket.h>
46 # include <netdb.h>
47 # include <errno.h>
48 #endif
49 #include <assert.h>
50 #include <sys/types.h>
51 #include <signal.h>
52
53 #if defined(__EMX__) || defined(__morphos__)
54 typedef int socklen_t;
55 #endif
56
57 /*
58 ** There can only be a single socket connection open at a time.
59 ** State information about that socket is stored in the following
60 ** local variables:
@@ -144,18 +149,26 @@
149 **
150 ** Return the number of errors.
151 */
152 int socket_open(UrlData *pUrlData){
153 int rc = 0;
154 #ifdef AF_INET6
155 struct addrinfo *ai = 0;
156 struct addrinfo *p;
157 struct addrinfo hints;
158 char zPort[30];
159 char zRemote[NI_MAXHOST];
160 #else
161 struct hostent *hostent;
162 struct sockaddr_in sa;
163 socklen_t size = sizeof(sa);
164 int i;
165 #endif
166
167 socket_global_init();
168 socket_close();
169 #ifdef AF_INET6
170 memset(&hints, 0, sizeof(struct addrinfo));
171 hints.ai_family = g.fIPv4 ? AF_INET : AF_UNSPEC;
172 hints.ai_socktype = SOCK_STREAM;
173 hints.ai_protocol = IPPROTO_TCP;
174 sqlite3_snprintf(sizeof(zPort),zPort,"%d", pUrlData->port);
@@ -183,16 +196,45 @@
196 if( p==0 ){
197 socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
198 pUrlData->port);
199 rc = 1;
200 }
201 #else
202 hostent = gethostbyname(pUrlData->name);
203 if ( !hostent ){
204 socket_set_errmsg("gethostbyname() failed: %s", strerror(errno));
205 goto end_socket_open;
206 }
207 iSocket = socket(AF_INET, SOCK_STREAM, 0);
208 if( iSocket< 0 ){
209 socket_set_errmsg("socket() failed: %s", strerror(errno));
210 goto end_socket_open;
211 }
212 memset(&sa, 0, sizeof(sa));
213 sa.sin_family = AF_INET;
214 for (i=0; hostent->h_addr_list[i]!=0; i++){
215 sa.sin_addr = *(struct in_addr *)hostent->h_addr_list[i];
216 if( connect(iSocket,(struct sockaddr *)&sa,size)<0 ){
217 sa.sin_addr.s_addr = 0;
218 continue;
219 }
220 g.zIpAddr = mprintf("%s", inet_ntoa(sa.sin_addr));
221 }
222 if( sa.sin_addr.s_addr==0 ){
223 socket_set_errmsg("cannot connect to host %s:%d", pUrlData->name,
224 pUrlData->port);
225 rc = 1;
226 }
227 #endif
228 #if !defined(_WIN32)
229 signal(SIGPIPE, SIG_IGN);
230 #endif
231 end_socket_open:
232 if( rc && iSocket>=0 ) socket_close();
233 #ifdef AF_INET6
234 if( ai ) freeaddrinfo(ai);
235 #endif
236 return rc;
237 }
238
239 /*
240 ** Send content out over the open socket connection.
241

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button