Example #1
0
void
SessionMain(
	ScreenData 	*scr)
{
	Port	*port;
	int		fd;
	NETFILE	*fp;

ENTER_FUNC;
	port = ParPort(TermPort,PORT_WFC);
	fd = ConnectSocket(port,SOCK_STREAM);
	DestroyPort(port);
	if ( fd > 0 ){
		fp = SocketToNet(fd);
		if (SendPanda(scr,fp)) {
			RecvPanda(scr,fp);
			CloseNet(fp);
		} else {
			scr->status = SCREEN_DATA_END;
		}
	} else {
		scr->status = SCREEN_DATA_END;
	}
LEAVE_FUNC;
}
Example #2
0
extern void InitMessage(char *id, char *fn) {
  char *tempformat, *tempfn;
#ifdef USE_MSGD
  int fd;
  Port *port;
#endif

#ifdef USE_SYSLOG
  static char buff[SIZE_LOG];

  snprintf(buff, SIZE_LOG, "%s/%s", PACKAGE, id);
  openlog(buff, LOG_PID, syslog_facility);
#endif

  if (fn == NULL) {
    tempfn = getenv("LOG_FILE_NAME");
    if (tempfn != NULL) {
      fn = StrDup(tempfn);
    }
  }
  fpLog = NULL;
  Processid = StrDup(id);
  tempformat = getenv("LOG_DATA_FORMAT");
  if (tempformat != NULL) {
    Format = StrDup(tempformat);
  }
#ifdef USE_MSGD
  if (fn != NULL) {
    if (*fn == '@') {
      port = ParPort(fn + 1, PORT_MSGD);
      if ((fd = ConnectSocket(port, SOCK_STREAM)) >= 0) {
        fpLog = SocketToNet(fd);
        if (Format == NULL) {
          Format = "%F:%i:%f:%L:%B";
        }
      }
      DestroyPort(port);
    } else {
      if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600)) >= 0) {
        fpLog = FileToNet(fd);
      }
    }
  }
  if (fpLog == NULL) {
    if (Format == NULL) {
      Format = "%Y/%M/%D/%h:%m:%s %F:%f:%L:%B";
    }
    fpLog = FileToNet(STDOUT_FILENO);
  }
#else
  if ((fn == NULL) || ((fpLog = fopen(fn, "w+")) == NULL)) {
    fpLog = stdout;
  }
#endif
  if (Format == NULL) {
    Format = "%Y/%M/%D/%h:%m:%s %F:%f:%L:%B";
  }
  MessageFunction = __Message;
}
Example #3
0
static NETFILE *ConnectBlobAPI(char *socketfile) {
  NETFILE *fp;
  Port *port;
  int fd;

  fp = NULL;
  port = ParPort(socketfile, NULL);
  fd = ConnectSocket(port, SOCK_STREAM);
  DestroyPort(port);
  if (fd > 0) {
    fp = SocketToNet(fd);
  } else {
    Error("cannot connect blob api");
  }
  return fp;
}
Example #4
0
extern	NETFILE	*
OpenPort(
	char	*url,
	char	*defport)
{
	int		fd;
	Port	*port;
	NETFILE	*fp;

	port = ParPort(url,defport);
	if		(  ( fd = ConnectSocket(port,SOCK_STREAM) )  >  0  ) {
		fp = SocketToNet(fd);
	} else {
		fp = NULL;
	}
	DestroyPort(port);
	return	(fp);
}
Example #5
0
void
SessionExit(
	ScreenData 	*scr)
{
	Port	*port;
	int		fd;
	NETFILE	*fp;

ENTER_FUNC;
	port = ParPort(TermPort,PORT_WFC);
	fd = ConnectSocket(port,SOCK_STREAM);
	DestroyPort(port);
	if ( fd > 0 ){
		fp = SocketToNet(fd);
		SendTermServerEnd(fp,scr);
	} else {
		scr->status = SCREEN_DATA_NULL;
	}
LEAVE_FUNC;
}
Example #6
0
extern void ExecuteServer(char *fn) {
  int _fhLog;
  fd_set ready;
  int maxfd;
  Port *port;

  pthread_create(&_FileThread, NULL, (void *(*)(void *))FileThread, (void *)fn);
  port = ParPortName(PortNumber);
  _fhLog = InitServerPort(port, Back);
  maxfd = _fhLog;

  while (TRUE) {
    FD_ZERO(&ready);
    FD_SET(_fhLog, &ready);
    select(maxfd + 1, &ready, NULL, NULL, NULL);
    if (FD_ISSET(_fhLog, &ready)) {
      ConnectLog(_fhLog);
    }
  }
  DestroyPort(port);
}
Example #7
0
static void ExecuteServer(void) {
  int pid;
  int fd;
  int soc_len;
  int soc[MAX_SOCKET];

  NETFILE *fpComm;
  Port *port;
#ifdef USE_SSL
  SSL_CTX *ctx;
  char *ssl_warning;
#endif
  port = ParPortName(PortNumber);
  soc_len = InitServerMultiPort(port, Back, soc);
#ifdef USE_SSL
  ctx = NULL;
  if (fSsl) {
    ctx = MakeSSL_CTX(KeyFile, CertFile, CA_File, CA_Path, Ciphers);
    if (ctx == NULL) {
      Warning(GetSSLErrorMessage());
      Error("CTX make error");
    }
    if (!fVerifyPeer) {
      SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
    }
    ssl_warning = GetSSLWarningMessage();
    if (strlen(ssl_warning) > 0) {
      Warning(ssl_warning);
    }
  }
#endif
  while (TRUE) {
    if ((fd = AcceptLoop(soc, soc_len)) < 0) {
      continue;
    }
    if ((pid = fork()) > 0) { /*	parent	*/
      close(fd);
    } else if (pid == 0) { /*	child	*/
#ifdef USE_SSL
      if (fSsl) {
        fpComm = MakeSSL_Net(ctx, fd);
        if (StartSSLServerSession(fpComm) != TRUE) {
          CloseNet(fpComm);
          Warning(GetSSLErrorMessage());
          exit(0);
        }
      } else {
        fpComm = SocketToNet(fd);
      }
#else
      fpComm = SocketToNet(fd);
#endif
      alarm(API_TIMEOUT_SEC);
      HTTP_Method(fpComm);
// FIXME avoid segv gl protocol timeout
#if 0
			CloseNet(fpComm);
#endif
      exit(0);
    }
  }
  DestroyPort(port);
}