/* IPUSH.C is a simple gif animation script using server a push technique.
* it is based on Rob McCools hack DOIT.C and contains much of the original
* code. I have modified it to allow for the image name, number of frames
* and the refresh rate to be sent as paramters. The ONLY line that needs
* to be edited in this code is the IMAGEPATH below. Set this directory to
* where you keep the image files.
*
* USAGE:
* would server the images dog1.gif through dog8.gif with a
* refresh rate of 1.
*
* Hope you enjoy!!!
*
* Chris Stephens stephenc@pcmail.cbil.vcu.edu
* http://darkwing.cbil.vcu.edu/cworld/cworld.gmml
*/
#include
#include
#include
#include
#include
#include
#define HEADER \
"Content-type: multipart/x-mixed-replace;boundary=ThisRandomString\n" \
#define IMAGEPATH "../htdocs/cworld/"
#define RANDOMSTRING "\n--ThisRandomString\n"
#define ENDSTRING "\n--ThisRandomString--\n"
#define CTSTRING "Content-type: image/gif\n\n"
int main(int argc, char *argv[])
{
struct stat fi;
char fn[32];
caddr_t fp;
int x;
int fd;
int lastimage;
int refresh;
if(write(STDOUT_FILENO, HEADER, strlen(HEADER)) == -1)
exit(0);
if(write(STDOUT_FILENO, RANDOMSTRING, strlen(RANDOMSTRING)) == -1)
exit(0);
sscanf(argv[2],"%d",&lastimage);
sscanf(argv[3],"%d",&refresh);
x = 1;
while(1) {
sleep(refresh);
if(write(STDOUT_FILENO, CTSTRING, strlen(CTSTRING)) == -1)
exit(0);
sprintf(fn, "%s%s%d.gif",IMAGEPATH,argv[1], x);
if( (fd = open(fn, O_RDONLY)) == -1)
continue;
fstat(fd, &fi);
fp = mmap(NULL, fi.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if(fp == (caddr_t) -1)
exit(0);
if(write(STDOUT_FILENO, (void *) fp, fi.st_size) == -1)
exit(0);
munmap(fp, fi.st_size);
close(fd);
if(write(STDOUT_FILENO, RANDOMSTRING, strlen(RANDOMSTRING)) == -1)
exit(0);
if(x == lastimage) goto thats_it;
else ++x;
}
thats_it:
exit (0);
}