...
 
Commits (1)
# GNUmakefile
#########################################################################
# Makefile for SBBSINST #
# For use with GNU make and GNU C Compiler #
# @format.tab-size 4, @format.use-tabs true #
# #
# Linux: gmake #
# FreeBSD: gmake os=FreeBSD #
# #
# Optional build targets: dlls, utils, mono, all (default) #
#########################################################################
# $Id: GNUmakefile,v 1.23 2020/03/31 06:48:50 deuce Exp $
SRC_ROOT = ../..
include $(SRC_ROOT)/build/Common.gmake
CFLAGS += -I../ -I../../comio
ifdef STATIC
LDFLAGS += -static
endif
ifeq ($(os),sunos)
LDFLAGS += -lnsl
endif
CFLAGS += $(UIFC-MT_CFLAGS) $(CIOLIB-MT_CFLAGS) $(XPDEV-MT_CFLAGS) $(SMBLIB_CFLAGS) $(HASH_CFLAGS)
LDFLAGS += $(UIFC-MT_LDFLAGS) $(CIOLIB-MT_LDFLAGS) $(XPDEV-MT_LDFLAGS) $(SMBLIB_LDFLAGS) $(HASH_LDFLAGS)
$(SBBSINST): $(OBJS)
$(QUIET)echo Linking $@
$(QUIET)$(CC) -o $@ $(MT_LDFLAGS) $(OBJS) $(LDFLAGS) $(UIFC-MT_LIBS) $(CIOLIB-MT_LIBS) $(XPDEV-MT_LIBS) $(HASH_LIBS)
#include <stdio.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <ctype.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include "sockwrap.h"
#define MAX_SCHEME_LEN 10
#define MAX_HOST_LEN 128
#define MAX_INACTIVITY 30 /* Seconds */
#define MAX_HEADER 1024
u_long resolve_ip(char *addr)
{
struct hostent* host;
char* p;
if(*addr==0)
return(INADDR_NONE);
for(p=addr;*p;p++)
if(*p!='.' && !isdigit(*p))
break;
if(!(*p))
return(inet_addr(addr));
if((host=gethostbyname(addr))==NULL)
return(INADDR_NONE);
return(*((u_long*)host->h_addr_list[0]));
}
int sockreadline(int sock, char *buf, size_t length, char *error)
{
char ch;
int i;
int rd;
#if 0
time_t start;
start=time(NULL);
for(i=0;TRUE;) {
if(!socket_check(sock,&rd,NULL,1000)) {
if(error != NULL)
strcpy(error, "Socket error");
return(-1);
}
if(!rd) {
if(time(NULL)-start>MAX_INACTIVITY) {
if(error != NULL)
strcpy(error,"Timed out");
return(-1); /* time-out */
}
continue; /* no data */
}
if(recv(sock, &ch, 1, 0)!=1)
break;
if(ch=='\n')
break;
if(i<length)
buf[i++]=ch;
}
#else
for(i=0;1;) {
if(!socket_check(sock,&rd,NULL,60000) || !rd || recv(sock, &ch, 1, 0)!=1) {
if(error != NULL)
strcpy(error,"Timed out");
return(-1); /* time-out */
}
if(ch=='\n')
break;
if(i<length)
buf[i++]=ch;
}
#endif
/* Terminate at length if longer */
if(i>length)
i=length;
if(i>0 && buf[i-1]=='\r')
buf[--i]=0;
else
buf[i]=0;
return(i);
}
/* Error will hold the error message on a failed return... */
/* Must be at least 128 bytes long */
int http_get_fd(char *URL, size_t *len, char *error)
{
char host[MAX_HOST_LEN+1];
ulong ip_addr;
int s=-1;
int port=80;
char *p;
char *path;
struct sockaddr_in addr;
char header[MAX_HEADER+1];
if(len != NULL)
*len=0;
if(error != NULL)
*error=0;
if(strncasecmp(URL, "http://", 7)) {
if(error!=NULL)
strcpy(error, "URL is not http");
return(-1);
}
strncpy(host, URL+7, MAX_HOST_LEN);
host[MAX_HOST_LEN]=0;
if((p=strchr(host,'/'))==NULL) {
if(error!=NULL)
strcpy(error, "Host too long or no path info found");
return(-1);
}
*p=0;
if((p=strchr(host,':'))!=NULL) {
*p=0;
port=atoi(p+1);
}
if((ip_addr=resolve_ip(host))==INADDR_NONE) {
if(error!=NULL)
strcpy(error, "Unable to resolve host");
return(-1);
}
if((path=strchr(URL+7, '/'))==NULL) {
if(error!=NULL)
strcpy(error, "Path info not found");
return(-1);
}
if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) {
if(error!=NULL)
strcpy(error, "Unable to create socket");
return(-1);
}
memset(&addr,0,sizeof(addr));
addr.sin_addr.s_addr = ip_addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
if (connect(s, (struct sockaddr*)&addr, sizeof (addr)) < 0) {
close(s);
if(error!=NULL)
strcpy(error, "Unable to connect");
return(-1);
}
if(error!=NULL)
strcpy(error,"Unable to send request");
if(write(s, "GET ", 4)!=4) {
close(s);
return(-1);
}
if(write(s, path, strlen(path))!=strlen(path)) {
close(s);
return(-1);
}
if(write(s, " HTTP/1.0\r\nHost: ", 17)!=17) {
close(s);
return(-1);
}
if(write(s, host, strlen(host))!=strlen(host)) {
close(s);
return(-1);
}
if(write(s, "\r\nConnection: close\r\n\r\n",23)!=23) {
close(s);
return(-1);
}
if(error!=NULL)
*error=0;
if(sockreadline(s, header, sizeof(header), error) < 0) {
close(s);
return(-1);
}
if(atoi(header+9)!=200) {
if(error != NULL) {
strncpy(error, header, 128);
error[127]=0;
}
close(s);
return(-1);
}
while(header[0]) {
if(sockreadline(s, header, sizeof(header), error) < 0) {
close(s);
return(-1);
}
if(len != NULL && strncasecmp(header,"content-length:",15)==0) {
*len=atol(header+15);
}
}
return(s);
}
/* Error will hold the error message on a failed return... */
/* Must be at least 40 bytes long */
int http_get_fd(char *URL, size_t *len, char *error);
int sockreadline(int sock, char *buf, size_t length, char *error);
# objects.mk
# Make 'include file' listing object files for Synchronet SBBSINST
# $Id: objects.mk,v 1.6 2004/09/13 22:57:09 deuce Exp $
# MTOBJODIR, DIRSEP, and OFILE must be pre-defined
OBJS = $(MTOBJODIR)$(DIRSEP)sbbsinst$(OFILE)\
$(MTOBJODIR)$(DIRSEP)httpio$(OFILE)
Distribution list format:
R <sp> File revision information
C <sp> Text description of release
Indicates a CVS release... contains one AND ONLY ONE tag line,
then a number of server lines.
T <sp> Text description of release
Indicates a Tarball release... contains multiples file lines
then numtiple server lines
t <sp> Text
A tag line defines a CVS tag to use.
m <sp> Make options
A list of command-line options to pass to make/gmake.
f <sp> Text
A file line.
%s is replaced with sysname-machine from uname.
s <sp> Address <tab> Text description of server
A server line. Address is either the CVSROOT for C sections or the URL
for T sections %s is replaced by the current file name for URLs.
D <sp> <sysname-machine>[,<PLATFORM> ...] <sp> <LINE>
A depends line. Line is only parsed if the current sysname/machine is <sysname-machine>
Lines that start with anything but a C, T, f, t, D or s are ignored.
R $Revision: 1.15 $
T Current Source Tarball (v3.11A beta)
m NOCVS=1
f sbbs_src.tgz
f lib-%s.tgz
s ftp://ftp.synchro.net/ Official FTP server (T1)
s ftp://vert.synchro.net/ Vertrauen FTP server (256kbps)
s ftp://rob.synchro.net/ Vertrauen FTP server (256kbps)
s ftp://cvs.synchro.net/ Vertrauen FTP server (256kbps)
s ftp://freebsd.synchro.net/Synchronet/ Deuce's FTP server (128kbps)
s http://freebsd.synchro.net/synchronet/3.10a/ Deuce's HTTP server (128kbps)
T v3.10L beta Tarball
m NOCVS=1
f sbbs_src.tgz
f lib-%s.tgz
s ftp://ftp.synchro.net/ Official FTP server (T1)
s ftp://vert.synchro.net/ Vertrauen FTP server (256kbps)
s ftp://rob.synchro.net/ Vertrauen FTP server (256kbps)
s ftp://cvs.synchro.net/ Vertrauen FTP server (256kbps)
s ftp://freebsd.synchro.net/Synchronet/ Deuce's FTP server (128kbps)
s http://freebsd.synchro.net/synchronet/3.10l/ Deuce's HTTP server (128kbps)
C Current Development Code from CVS (unstable)
t HEAD
s :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs Official CVS Server (256kbps)
s :pserver:anonymous@cvs-mirror.synchro.net:/cvsroot/sbbs Deuce's CVS Mirror (128kbps)
C Version 3.12A beta from CVS (stable)
t sbbs312a
s :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs Official CVS Server (256kbps)
s :pserver:anonymous@cvs-mirror.synchro.net:/cvsroot/sbbs Deuce's CVS Mirror (128kbps)
C Version 3.11B beta from CVS (stable)
t sbbs311b
s :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs Official CVS Server (256kbps)
s :pserver:anonymous@cvs-mirror.synchro.net:/cvsroot/sbbs Deuce's CVS Mirror (128kbps)
C Version 3.11A beta from CVS (stable)
t sbbs311a
s :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs Official CVS Server (256kbps)
s :pserver:anonymous@cvs-mirror.synchro.net:/cvsroot/sbbs Deuce's CVS Mirror (128kbps)
C Version 3.10L beta from CVS (stable)
t sbbs310l
s :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs Official CVS Server (256kbps)
s :pserver:anonymous@cvs-mirror.synchro.net:/cvsroot/sbbs Deuce's CVS Mirror (128kbps)
This diff is collapsed.
# targets.mk
# Make 'include file' defining targets for Synchronet SBBSINST project
# $Id: targets.mk,v 1.4 2004/09/16 19:02:02 deuce Exp $
# ODIR, SLASH, LIBFILE, EXEFILE, and DELETE must be pre-defined
SBBSINST = $(EXEODIR)$(DIRSEP)sbbsinst$(EXEFILE)
all: xpdev-mt ciolib-mt uifc-mt $(EXEODIR) \
$(MTOBJODIR) \
$(SBBSINST)
$(SBBSINST): $(XPDEV-MT_LIB) $(CIOLIB-MT) $(UIFCLIB-MT)