The HTTPsync Incremental Update Utility
by Forrest J. Cavalier III 



Figure 1: 

#-#httpsync 101 Packing List for httpsync 1.01
# Visit the httpsync home page: http://www.mibsoftware.com/httpsync/
#
# This list was created from a simple list of files, relative
# to '.', one per line.
./Astring/astring.h 4934 Tue, 21 Jul 1998 10:38:58 GMT 644
#
# Next is an obsolete file.
O./include/comm.h
./Include/tsd.h 57 Mon, 17 Aug 1998 14:59:29 GMT 664


Listing One
/**********************************************************/
/* Macros and environment for portable sockets code
 * 1. Code is written using readsocket, writesocket, closesocket,
 *    INVALID_SOCKET, SOCKET_ERROR, SOCKET, and INADDR_NONE
 * 2. Always use SocketStartup() and SocketCleanup()
 * 3. Conditional includes and definitions for those macros
 *    allow operation under Windows and BSD-style sockets.
 */
#ifdef WIN32 /* Windows systems */

#include <winsock.h>
#include <io.h>
#define readsocket(a,b,c) recv(a,b,c,0)
#define writesocket(a,b,c) send(a,b,c,0)
/* closesocket() does not need a macro. INVALID_SOCKET, SOCKET_ERROR, 
 * SOCKET, and INADDR_NONE are already defined in winsock.h
 */
WSADATA libmibWSAdata;
#define SocketStartup() if (WSAStartup(0x101,&libmibWSAdata)) exit(-1)
#define SocketCleanup() WSACleanup()

#else /* Unix-style systems */

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

#define readsocket read
#define writesocket write
#define closesocket close
#define SocketStartup()
#define SocketCleanup()
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define SOCKET int
/* define INADDR_NONE if not already */
#ifndef INADDR_NONE
#define INADDR_NONE ((unsigned long) -1)
#endif

#endif


Listing Two
struct HTTPaccess_s theHTA;
char *pszReason;
char buf[8192]; /* Retrieve fails if all headers don't fit in this buffer */
FILE *fDEST;
char *pszProxy = 0; /* Set to hostname if proxy should be used */
char *pszHost = "host.domain.com"; 
int nPort = 80; /* Default HTTP port */
char *pszURI = "/source/packing.lst";

SocketStartup();
HTTPaccess_Initialize(&theHTA, pszProxy, pszHost, nPort, buf, sizeof(buf));
pHTA->cAttempt = 0;
while(1) {
    /* Initialize for read */
    fDEST = fopen(pszDest,"wb");
    if (!fDEST) {
      fprintf(stderr, "Terminated. Could not open %s for writing\n",pszDest);
      exit(-1);
    }
    pszReason = HTTPaccess_Retrieve(&theHTA, pszURI, fnWriteFile, fDEST); 
    fclose(fDEST);
    if (!pszReason) break; /* success */
    if (atoi(pszReason+2)!=3) {
    fprintf(stderr, "Terminated. Could not transfer %s\n",pszDest);
    exit(-1);
    }
    /* retry */
}
closesocket(theHTA.s);
SocketCleanup();



2


