Beispiel #1
0
int MicroHttpMain(int npar,char **par) {
int i,Limit=1000000;
if (npar==1) {
    printf("microHttp.exe -p[port] -r[rootDir] -d[debugLevel] -m[ext=mime[&..]]) -L[limitPPS:1000000]\n");
    return 0;
    }
for(i=1;i<npar;i++) {
    char *cmd = par[i];
    if (*cmd=='-') cmd++;
    switch(*cmd) {
    case 'p': sscanf(cmd+1,"%d",&port); break;
    //case 'S': sscanf(cmd+1,"%d",&sleepTime); break;
    case 'd': sscanf(cmd+1,"%d",&logLevel); break;
    case 'k': sscanf(cmd+1,"%d",&keepAlive); break;
    case 'T': sscanf(cmd+1,"%d",&runTill); break;
    case 'L': sscanf(cmd+1,"%d",&Limit); break;
    case 'r': rootDir=cmd+1; break;
    case 'm': mimes = cmd+1; break;
    }
    }
net_init();
TimeUpdate();
httpSrv *srv = httpSrvCreate(0); // New Instance, no ini
srv->log =  srv->srv.log = logOpen("microHttp.log"); // Create a logger
srv->logLevel = srv->srv.logLevel = logLevel;
srv->keepAlive=keepAlive;
srv->readLimit.Limit = Limit;
IFLOG(srv,0,"...starting microHttp {port:%d,logLevel:%d,rootDir:'%s',keepAlive:%d,Limit:%d},\n   mimes:'%s'\n",
  port,logLevel,rootDir,keepAlive,Limit,
  mimes);
//printf("...Creating a http server\n");
srv->defmime= vssCreate("text/plain;charset=windows-1251",-1);
httpSrvAddMimes(srv,mimes);
//httpMime *m = httpSrvGetMime(srv,vssCreate("1.HHtm",-1));printf("Mime here %*.*s\n",VSS(m->mime));
//httpSrvAddFS(srv,"/c/","c:/",0); // Adding some FS mappings
httpSrvAddFS(srv,"/",rootDir,0); // Adding some FS mappings
httpSrvAddMap(srv, strNew("/.stat",-1), onHttpStat, 0);
if (httpSrvListen(srv,port)<=0) { // Starts listen port
   Logf("-FAIL start listener on port %d\n",port); return 1;
   }
Logf(".. listener is ready, Ctrl+C to abort\n");
if (runTill) srv->runTill = TimeNow + runTill;
httpSrvProcess(srv); // Run All messages till CtrlC...
TimeUpdate();
IFLOG(srv,0,"...stop microHttp, done:{connects:%d,requests:%d,runtime:%d}\n",
     srv->srv.connects,srv->srv.requests,TimeNow - srv->created);
return 0;
}
Beispiel #2
0
/*
 * bgp_new_peer()
 *       DESCRIPTION
 *           Create & Initiate a peer
 *       RETURN VALUES
 *            pointer to new struct rpcb
 */
struct rpcb *
bgp_new_peer()
{
  struct rpcb *bnp;

  MALLOC(bnp, struct rpcb);

  bnp->rp_next   = bnp;
  bnp->rp_prev   = bnp;
  bnp->rp_state  = BGPSTATE_IDLE;

  IFLOG(LOG_BGPSTATE)
    syslog(LOG_NOTICE, "<%s>: BGP state shift[%s] peer: %s", __FUNCTION__,
	   bgp_statestr[bnp->rp_state], bgp_peerstr(bnp));

  bnp->rp_socket = -1;    /* none */
  bnp->rp_prefer = htonl(BGP_DEF_LOCALPREF);
  bnp->rp_sfd[0] = -1;    /* none */
  bnp->rp_sfd[1] = -1;    /* none */
  bnp->rp_inputmode = BGP_READ_HEADER;
  
  return bnp;
}
Beispiel #3
0
int MicroHttpMain(int npar,char **par) {
int i,Limit=1000000;
if (npar==1) {
    printf("microHttp.exe -p[port] -r[rootDir] -d[debugLevel] -m[ext=mime[&..]]) -L[limitPPS:1000000] -S[cert.pem]\n");
    return 0;
    }
for(i=1;i<npar;i++) {
    char *cmd = par[i];
    if (*cmd=='-') cmd++;
    switch(*cmd) {
    case 'p': sscanf(cmd+1,"%d",&port); break;
    //case 'S': sscanf(cmd+1,"%d",&sleepTime); break;
    case 'd': sscanf(cmd+1,"%d",&logLevel); break;
    case 'k': sscanf(cmd+1,"%d",&keepAlive); break;
    case 'T': sscanf(cmd+1,"%d",&runTill); break;
    case 'L': sscanf(cmd+1,"%d",&Limit); break;
    case 'r': rootDir=cmd+1; break;
    case 'm': mimes = cmd+1; break;
    case 'S': pem = cmd+1; break;
    }
    }
net_init();
TimeUpdate();
httpSrv *srv = httpSrvCreate(0); // New Instance, no ini
srv->log =  srv->srv.log = logOpen("microHttp.log"); // Create a logger
srv->logLevel = srv->srv.logLevel = logLevel;
srv->keepAlive=keepAlive;
srv->readLimit.Limit = Limit;

#ifdef VOS_SSL
if (pem) {
srv->srv.pem_file=pem; // if have SSL
printf("SSL will use pem_file: %s\n",pem);
} else printf("==NO SSL==, use plain tcp_sockets\n");
#endif

ws = wsSrvCreate();
ws->onMessage = onWebMessage;

IFLOG(srv,0,"...starting microHttp {port:%d,logLevel:%d,rootDir:'%s',keepAlive:%d,Limit:%d},\n   mimes:'%s'\n",
  port,logLevel,rootDir,keepAlive,Limit,
  mimes);
//printf("...Creating a http server\n");
srv->defmime= vssCreate("text/plain;charset=utf-8",-1);
httpSrvAddMimes(srv,mimes);
//httpMime *m = httpSrvGetMime(srv,vssCreate("1.HHtm",-1));printf("Mime here %*.*s\n",VSS(m->mime));
//httpSrvAddFS(srv,"/c/","c:/",0); // Adding some FS mappings
httpSrvAddFS(srv,"/",rootDir,0); // Adding some FS mappings
httpSrvAddMap(srv, strNew("/.stat",-1), onHttpStat, 0);
httpSrvAddMap(srv, strNew("/.chat",-1), onWebSock, 0);

if (httpSrvListen(srv,port)<=0) { // Starts listen port
   Logf("-FAIL start listener on port %d\n",port); return 1;
   }
Logf(".. listener is ready, Ctrl+C to abort\n");
if (runTill) srv->runTill = TimeNow + runTill;

//httpSrvProcess(srv); // Run All messages till CtrlC...

while(!aborted) {
  TimeUpdate(); // TimeNow & szTimeNow
  int cnt = SocketPoolRun(&srv->srv);
      cnt+=wsSrvStep(ws);
  //printf("SockPoolRun=%d time:%s\n",cnt,szTimeNow); msleep(1000);
  RunSleep(cnt); // Empty socket circle -)))
  if (srv->runTill && TimeNow>=srv->runTill) break; // Done???
  }


TimeUpdate();
IFLOG(srv,0,"...stop microHttp, done:{connects:%d,requests:%d,runtime:%d}\n",
     srv->srv.connects,srv->srv.requests,TimeNow - srv->created);
return 0;
}