Exemplo n.º 1
0
/*
 * configure SSL
 */
SSL_CTX *server_ctx (XML *xml)
{
  SSL_CTX *ctx;
  char *ch,
       *passwd,
       cert[MAX_PATH], 
       key[MAX_PATH], 
       auth[MAX_PATH];

  info ("Initializing SSL context\n");
  ch = xml_get_text (xml, "Phineas.Server.SSL.CertFile");
  if (*ch == 0)
    return (NULL);
  pathf (cert, "%s", ch);
  ch = xml_get_text (xml, "Phineas.Server.SSL.KeyFile");
  if (*ch == 0)
    strcpy (key, cert);
  else
    pathf (key, "%s", ch);
  passwd = xml_get_text (xml, "Phineas.Server.SSL.Password");
  if (*passwd == 0)
    passwd = NULL;
  ch = xml_get_text (xml, "Phineas.Server.SSL.AuthFile");
  if (*ch == 0)
    ch = NULL;
  else
    ch = pathf (auth, "%s", ch);
  if ((ctx = net_ctx (cert, key, passwd, ch, 1)) == NULL)
    error ("Failed getting SSL context for server\n");
  return (ctx);
}
Exemplo n.º 2
0
/*
 * Poll and process one queue
 */
int qpoller_poll (XML *xml, int mapid, TASKQ *tq)
{
  int mpos;
  char *ch;
  QPOLLER *p;
  QUEUE *q;
  QUEUEROW *r;
  char mpath[80];

  mpos = sprintf (mpath, QP_QUEUE"[%d].", mapid);
  strcpy (mpath + mpos, "Type");
  ch = xml_get_text (xml, mpath);
  for (p = Qpoller; p != NULL; p = p->next)
  {
    if (strcmp (p->type, ch) == 0)
      break;
  }
  if (p == NULL)
  {
    debug ("No processor found for Queue type %s\n", ch);
    return (-1);
  }
  strcpy (mpath + mpos, "Name");
  ch = xml_get_text (xml, mpath);
  debug ("Processor %s for Queue %s\n", p->type, ch);
  if ((q = queue_find (ch)) == NULL)
  {
    debug ("Can't find queue %s\n", ch);
    return (-1);
  }
  while ((r = queue_pop (q)) != NULL)
  {
    qpoller_start (p, xml, r, tq);
  }
  return (0);
}
Exemplo n.º 3
0
/*
 * return response for a request
 */
DBUF *server_response (XML *xml, char *req)
{
  char *url, *ch;
  DBUF *console_response (XML *, char *);
  extern char Software[];

  if (strstarts (req, "GET "))
    url = req + 4;
  else if (strstarts (req, "POST "))
    url = req + 5;
  else
    return (NULL);
#ifdef __RECEIVER__
  ch = xml_get_text (xml, "Phineas.Receiver.Url");
  if (strstarts (url, ch))
  {
    if (url == req + 5)		/* this a POST?			*/
    {
      debug ("getting ebXML response\n");
      if ((ch = ebxml_process_req (xml, req)) != NULL)
        return (dbuf_setbuf (NULL, ch, strlen (ch)));
    }
    return (server_respond (200, "<h3>%s</h3>Receiver", Software));
  }
#endif
#ifdef __CONSOLE__
  ch = xml_get_text (xml, "Phineas.Console.Url");
  if (strstarts (url, ch) || strstarts (url, "/favicon.ico"))
    return (console_response (xml, req));
#endif
  if ((ch = strchr (url, '\n')) == NULL)
    ch = url + strlen (url);
  warn ("request not found for %.*s\n", ch - url, url);
  return (server_respond (400, "404 - <bold>%.*s</bold> not found", 
    ch - url, url));
}
Exemplo n.º 4
0
/*
 * TASK to handle an incoming request
 */
int server_request (void *parm)
{
  SERVERPARM *s;
  DBUF *req, *res;
  char *curl;

  s = (SERVERPARM *) parm;
  curl = xml_get_text (s->xml, "Phineas.Console.Url");
  res = NULL;
  while ((req = server_receive (s->conn)) != NULL)
  {
    debug ("received %d bytes\n", dbuf_size (req));
    if (dbuf_size (req) == 0)
    {
      dbuf_free (req);
      net_close (s->conn);
      return (-1);
    }
    dbuf_putc (req, 0);
    /*
     * log the request, but filter out GET requests for the console... 
     * noise
     */
    if (!(*curl && strstarts (dbuf_getbuf (req) + 4, curl)))
      server_logrequest (s->conn, dbuf_size (req), dbuf_getbuf (req));
    if ((res = server_response (s->xml, dbuf_getbuf (req))) == NULL)
    {
      res = server_respond (500,
	    "<h3>Failure processing ebXML request</h3>");
    }
    server_header (res);
    net_write (s->conn, dbuf_getbuf (res), dbuf_size (res));
    dbuf_free (res);
    dbuf_free (req);
  }
  net_close (s->conn);
  debug ("request completed\n");
  return (0);
}
Exemplo n.º 5
0
/*
 * parse a reply message and update the queue row with status
 */
int ebxml_parse_reply (char *reply, QUEUEROW *r)
{
  MIME *msg, *part;
  XML *xml;
  char *ch, buf[PTIMESZ];

  if (ebxml_status (reply))
    return (-1);
  if ((msg = mime_parse (reply)) == NULL)
  {
    error ("Failed parsing reply message\n");
    return (-1);
  }
  /* check the ebxml envelope for ack or error */
  if ((part = mime_getMultiPart (msg, 1)) == NULL)
  {
    error ("Reply missing ebxml envelope\n");
    mime_free (msg);
    return (-1);
  }
  if ((xml = xml_parse (mime_getBody (part))) == NULL)
  {
    error ("Failed parsing ebxml envelop\n");
    mime_free (msg);
    return (-1);
  }
  strcpy (buf, xml_get_text (xml, SOAPACTION));
  if (!strcmp (buf, "MessageError"))
  {
    debug ("Error reply received!\n");
    queue_field_set (r, "PROCESSINGSTATUS", "done");
    queue_field_set (r, "TRANSPORTSTATUS", "failed");
    ch = xml_get_attribute (xml, SOAPERROR, "eb:errorCode");
    debug ("%s eb:errorCode %s\n", SOAPERROR, ch);
    queue_field_set (r, "TRANSPORTERRORCODE", ch);
    queue_field_set (r, "APPLICATIONSTATUS", "not-set");
    queue_field_set (r, "APPLICATIONERRORCODE", "none");
    ch = xml_get_text (xml, SOAPERROR);
    debug ("SOAPERROR %s\n", ch);
    queue_field_set (r, "APPLICATIONRESPONSE", ch);
    queue_field_set (r, "MESSAGERECEIVEDTIME", ptime (NULL, buf));
    xml_free (xml);
    mime_free (msg);
    return (0);
  }
  xml_free (xml);

  /* Ping reply */
  if (strcmp (queue_field_get (r, "ACTION"), "Ping") == 0)
  {
    if (strcmp (buf, "Pong"))
    {
      error ("Expected 'Pong' action but got '%s'\n", buf);
      mime_free (msg);
      return (-1);
    }
    queue_field_set (r, "APPLICATIONSTATUS", "not-set");
    queue_field_set (r, "APPLICATIONERRORCODE", "none");
    queue_field_set (r, "APPLICATIONRESPONSE", "none");
    queue_field_set (r, "MESSAGERECEIVEDTIME", ptime (NULL, buf));
  }
  else /* regular reply */
  {
    if ((part = mime_getMultiPart (msg, 2)) == NULL)
    {
      error ("Reply missing status part\n");
      mime_free (msg);
      return (-1);
    }
    debug ("Body is...\n%s\n", mime_getBody (part));
    if ((xml = xml_parse (mime_getBody (part))) == NULL)
    {
      error ("Miss formatted Reply status\n");
      mime_free (msg);
      return (-1);
    }
    queue_field_set (r, "APPLICATIONSTATUS",
      xml_get_text (xml, "response.msh_response.status"));
    queue_field_set (r, "APPLICATIONERRORCODE",
      xml_get_text (xml, "response.msh_response.error"));
    queue_field_set (r, "APPLICATIONRESPONSE",
      xml_get_text (xml, "response.msh_response.appdata"));
    queue_field_set (r, "MESSAGERECEIVEDTIME", ptime (NULL, buf));
  
    /* TODO...
    queue_field_set (r, "RESPONSEMESSAGEID", "");
    queue_field_set (r, "RESPONSEARGUMENTS", "");
    queue_field_set (r, "RESPONSELOCALFILE", "");
    queue_field_set (r, "RESPONSEFILENAME", "");
    queue_field_set (r, "RESPONSEMESSAGEORIGIN", "");
    queue_field_set (r, "RESPONSEMESSAGESIGNATURE", "");
     */
    xml_free (xml);
  }
  queue_field_set (r, "PROCESSINGSTATUS", "done");
  queue_field_set (r, "TRANSPORTSTATUS", "success");
  queue_field_set (r, "TRANSPORTERRORCODE", "none");

  mime_free (msg);
  return (0);
}