コード例 #1
0
void			create_server(t_server *serv)
{
    int			s;
    int			i;
    struct sockaddr_in	sin;
    int			nb_port;

    memset(serv->fd_type, FD_FREE, MAX_FD * sizeof(int));
    xgethostname(serv->hostname, MAX_HOST_NAME_LEN);
    cfg_port(serv->port);
    cfg_timeout(&(serv->timeout));
    cfg_key(&(serv->key));
    nb_port = count_nb_port(serv->port);
    printf("*** IRC Server  ***\n");
    for (i = 0; i < nb_port; i++)
    {
        s = socket(PF_INET, SOCK_STREAM, 0);
        sin.sin_family = AF_INET;
        sin.sin_port = htons(serv->port[i]);
        sin.sin_addr.s_addr = INADDR_ANY;
        bind(s, (struct sockaddr *)&sin, sizeof(sin));
        listen(s, MAX_LISTEN);
        printf("Listen on port: %d\n", serv->port[i]);
        serv->fd_type[s] = FD_SERVER;
        serv->fct_read[s] = server_socket_read;
        serv->fct_write[s] = 0;
    }
    serv->channel = 0;
}
コード例 #2
0
ファイル: ebxml_sender.c プロジェクト: tdunnick/phineas
/*
 * Build and return the mime payload container
 */
MIME *ebxml_getpayload (XML *xml, QUEUEROW *r)
{
  int l, mapi;
  XML *exml;
  MIME *msg;
  char *b,			/* buffer for payload		*/
       *type,
       *unc = NULL,		/* encryption info		*/
       *pw = NULL,
       dn[DNSZ],
       *organization,
       pid[MAX_PATH],
       buf[MAX_PATH],
       fname[MAX_PATH];

  debug ("getpayload container...\n");
  if ((mapi = ebxml_pid (xml, r, pid)) < 0)
    return (NULL);
  ppathf (fname, cfg_map (xml, mapi, "Processed"), "%s",
    queue_field_get (r, "PAYLOADFILE"));

  /* invoke the filter if given					*/
  b = cfg_map (xml, mapi, "Filter");
  if (*b)
  {
    char *emsg;
    DBUF *rbuf = dbuf_alloc ();

    debug ("filter read %s with %s\n", fname, b);
    if (filter_run (b, fname, NULL, NULL, rbuf, &emsg, cfg_timeout (xml)))
    {
      error ("Can't filter %s - %s\n", fname, strerror (errno));
      dbuf_free (rbuf);
      return (NULL);
    }
    if (*emsg)
      warn ("filter %s returned %s\n", b, emsg);
    free (emsg);
    l = dbuf_size (rbuf);
    b = dbuf_extract (rbuf);
  }
  else
  {
    debug ("reading data from %s\n", fname);
    if ((b = readfile (fname, &l)) == NULL)
    {
      error ("Can't read %s - %s\n", fname, strerror (errno));
      return (NULL);
    }
  }

  organization = cfg_org (xml);
  type = cfg_map (xml, mapi, "Encryption.Type");
  if ((type != NULL) && *type)	/* encrypted			*/
  {
    unc = cfg_map (xml, mapi, "Encryption.Unc");
    pw = cfg_map (xml, mapi, "Encryption.Password");
    strcpy (dn, cfg_map (xml, mapi, "Encryption.Id"));
  }

  msg = payload_create (b, l, fname, organization, unc, dn, pw);

  free (b);
  if (msg == NULL)
    error ("Can't create payload container for %s\n", fname);
  return (msg);
}