Exemplo n.º 1
0
int
main(int argc, char **argv)
{
    struct xmpp xmpp = { 0 };
    int i, port = XMPP_PORT, fd, ret = 1;
    char *jid = 0, *pwdfile = 0, *srv = 0;

    for (i = 1; i < argc - 1 && argv[i][0] == '-'; i++)
        switch (argv[i][1]) {
        case 'j':
            jid = argv[++i];
            break;
        case 'k':
            pwdfile = argv[++i];
            break;
        case 's':
            srv = argv[++i];
            break;
        case 'l':
            show_log = atoi(argv[++i]);
            break;
        case 'p':
            port = atoi(argv[++i]);
            break;
        default:
            die_usage();
        }
    if (!jid)
        die_usage();

    xmpp.io_context = &fd;
    xmpp.send = io_send;
    xmpp.tls_fn = use_tls ? start_tls : 0;
    xmpp.stream_fn = stream_handler;
    xmpp.node_fn = node_handler;
    xmpp.auth_fn = auth_handler;
    xmpp.use_sasl = use_sasl;
    xmpp.jid = jid;

    read_pw(pwdfile, &xmpp);

    if (xmpp_init(&xmpp, 4096))
        return 1;

    if (!srv)
        srv = xmpp.server;

    fd = tcp_connect(srv, port);
    if (fd < 0)
        return 1;

    if (!(xmpp_start(&xmpp) || process_connection(fd, &xmpp)))
        ret = 0;

    xmpp_printf(&xmpp, "</stream:stream>");
    xmpp_clean(&xmpp);
    close(fd);
    shutdown(fd, 2);
    return ret;
}
Exemplo n.º 2
0
Arquivo: ji.c Projeto: placek/ji
int
main(int argc, char **argv)
{
  struct xmpp xmpp = {0};
  char path_buf[PATH_BUF];
  int i, port = XMPP_PORT, ret = 1;
  char *jid = 0, *srv = 0, *s;

  s = getenv("HOME");
  snprintf(path_buf, sizeof(path_buf), "%s/%s", (s) ? s : ".", root);
  s = getenv("USER");
  snprintf(me, sizeof(me), "%s", (s) ? s : "me");

  for (i = 1; i < argc - 1 && argv[i][0] == '-'; i++)
    switch (argv[i][1]) {
    case 'r': snprintf(path_buf, sizeof(path_buf), "%s", argv[++i]); break;
    case 'n': snprintf(me, sizeof(me), "%s", argv[++i]); break;
    case 'j': jid = argv[++i]; break;
    case 's': srv = argv[++i]; break;
    case 'p': port = atoi(argv[++i]); break;
    case 'l': log_level = atoi(argv[++i]); break;
    case 'e': snprintf(evfifo, sizeof(evfifo), "%s", argv[++i]); break;
    default: die_usage();
    }
  if (!jid)
    die_usage();

  xmpp.send = io_send;
  xmpp.tls_fn = start_tls;
  xmpp.stream_fn = stream_handler;
  xmpp.node_fn = node_handler;
  xmpp.auth_fn = auth_handler;
  xmpp.use_sasl = use_sasl;
  xmpp.jid = jid;

  if (read_line(0, sizeof(xmpp.pwd), xmpp.pwd))
    xmpp.pwd[0] = 0;

  if (xmpp_init(&xmpp, 4096))
    return 1;

  if (!srv)
    srv = xmpp.server;

  s = jid_partial(xmpp.jid, &i);
  snprintf(rootdir, sizeof(rootdir), "%s/%.*s", path_buf, i, s);

  fd = tcp_connect(srv, port);
  if (fd < 0)
    return 1;

  if (!(xmpp_start(&xmpp) != 0 || process_connection(fd, &xmpp)))
    ret = 0;

  xmpp_clean(&xmpp);
  close(fd);
  shutdown(fd, 2);
  return ret;
}
void
test_connector_server_start (TestConnectorServer *self)
{
  TestConnectorServerPrivate *priv;

  DEBUG("test_connector_server_start");

  priv = self->priv;
  priv->state = SERVER_STATE_START;
  DEBUG ("connection: %p", priv->conn);
  if (priv->problem.connector->xmpp & XMPP_PROBLEM_OLD_SSL)
    {
      startssl (self);
    }
  else
    {
      xmpp_init (NULL,NULL,self);
    }
}
static void
handshake_cb (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  TestConnectorServer *self = TEST_CONNECTOR_SERVER (user_data);
  TestConnectorServerPrivate *priv = self->priv;
  WockyTLSConnection *tls_conn;
  GError *error = NULL;

  DEBUG ("TLS/SSL handshake finished");

  tls_conn = wocky_tls_session_handshake_finish (
    WOCKY_TLS_SESSION (source),
    result,
    &error);

  if (server_dec_outstanding (self))
    goto out;

  if (tls_conn == NULL)
    {
      DEBUG ("SSL or TLS Server Setup failed: %s", error->message);
      g_io_stream_close (priv->stream, NULL, NULL);
      goto out;
    }

  if (priv->conn != NULL)
    g_object_unref (priv->conn);

  priv->state = SERVER_STATE_START;
  priv->conn = wocky_xmpp_connection_new (G_IO_STREAM (tls_conn));
  g_object_unref (tls_conn);
  priv->tls_started = TRUE;
  xmpp_init (NULL,NULL,self);

out:
  if (error != NULL)
    g_error_free (error);
}