This application serves a static HTML file as a response to a request.
extern "C"{
void *getmyfirstapp(void *);
}
char *str,str1[512],buffer[1024];
int count=0;
class myfirstapp:public OASApplication
{
protected:
virtual void *Work(void *ptr);
};
class myFirstAppMgr: public OASApplicationManager
{
public:
myFirstAppMgr();
virtual OASApplication* getApplicationInstance(void);
virtual ~myFirstAppMgr();
};
myFirstAppMgr::myFirstAppMgr()
{
str=(char *)malloc(4096*sizeof(char));
if(!str)throw ERROR_MEMORY;
sprintf(str1,"Content-type: text/html\r\nSet-Cookie: sessionid=100,\
Username=shridhar_daithankar; path=/cgi-bin\r\n\r\n");
int fd=open("/mnt1/apache2039/htdocs/Alpha-HOWTO-5.html",O_RDONLY);
if(fd<0)
{
fprintf(stderr,"Can not read the source file\n");
throw ERROR_SYSTEM;
}
int i=read(fd,str,4096);
str[i]='\0';
close(fd);
}
myFirstAppMgr::~myFirstAppMgr()
{
free(str);
}
OASApplication* myFirstAppMgr::getApplicationInstance(void)
{
myfirstapp *t=new myfirstapp;
return (OASApplication *)t;
}
void *getmyfirstapp(void *ptr)
{
myFirstAppMgr *t=new myFirstAppMgr;
return (void *)t;
}
void *myfirstapp::Work(void *ptr)
{
int fd=*(int *)ptr,i;
while(read(fd,buffer,512)>=512);
write(fd,str1,strlen(str1));
write(fd,str,strlen(str));
close(fd);
return(0);
}