Exemplo n.º 1
0
Arquivo: ji.c Projeto: placek/ji
static int
node_handler(int x, void *user)
{
  struct xmpp *xmpp = (struct xmpp *)user;
  int r;
  char *name;

  r = xmpp_default_node_hook(x, xmpp, user);
  if (r < 0)
    return -1;
  if (r)
    return 0;
  name = xml_node_name(x, &xmpp->xml.mem);
  if (!name)
    return -1;
  if (!strcmp(name, "message"))
    return msg_hook(x, xmpp);
  if (!strcmp(name, "presence"))
    return presence_hook(x, xmpp);
  if (!strcmp(name, "iq")) {
    name = xml_node_find_attr(x, "id", &xmpp->xml.mem);
    if (name && !strcmp(name, "roster"))
      return roster_hook(x, xmpp);
  }
  return 0;
}
Exemplo n.º 2
0
static int
node_handler(int x, void *user)
{
    struct xmpp *xmpp = (struct xmpp *)user;
    char *name, *msg, *from, *show, *status, *type;
    int r, n;

    r = xmpp_default_node_hook(x, xmpp, user);
    if (r < 0) {
        if (!xmpp->is_authorized)
            fprintf(stderr, "Authorization error.\n");
        return -1;
    }
    if (r)
        return 0;

    name = xml_node_name(x, &xmpp->xml.mem);
    if (!name)
        return -1;
    from = xml_node_find_attr(x, "from", &xmpp->xml.mem);
    if (!strcmp(name, "message")) {
        from = from ? jid_partial(from, &n) : 0;
        if (!from)
            return -1;
        snprintf(jid_from, sizeof(jid_from), "%.*s", n, from);
        msg = xml_node_find_text(x, "body", &xmpp->xml.mem);
        if (!msg)
            return -1;
        print_msg("<%.*s> %s\n", n, from, msg);
    } else if (!strcmp(name, "presence")) {
        if (!from)
            return -1;
        show = xml_node_find_text(x, "show", &xmpp->xml.mem);
        status = xml_node_find_text(x, "status", &xmpp->xml.mem);
        type = xml_node_find_attr(x, "type", &xmpp->xml.mem);
        if (type)
            print_msg("-!- %s sends %s\n", from, type);
        print_msg("-!- %s is %s (%s)\n", from,
                  show ? show : (type ? type : "online"), status ? status : "");
    } else if (!strcmp(name, "iq")) {
        name = xml_node_find_attr(x, "id", &xmpp->xml.mem);
        if (name && !strcmp(name, "roster"))
            roster_handler(x, xmpp);
    }
    return 0;
}