Beispiel #1
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;
}
Beispiel #2
0
Datei: ji.c Projekt: placek/ji
static int
presence_hook(int x, struct xmpp *xmpp)
{
  char *show, *s, *status, *from, *part, *type;
  struct contact *u;
  int npart;

  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);
  from = xml_node_find_attr(x, "from", &xmpp->xml.mem);
  if (!from)
    return 0;

  show = (!show && type && !strcmp("unavailable", type)) ? type : show;
  show = show ? show : STR_ONLINE;
  status = status ? status : "";

  for (s = status; *s; ++s)
    if (*s == '\n')
      *s = '\\';

  part = jid_partial(from, &npart);
  find_contact(u, npart, part);
  if (type && type[0] && (!u || strcmp(u->type, "groupchat")))
    print_msg(0, "", "-!- %s sends %s\n", from, type);
  if (!u || strcmp(u->type, "groupchat"))
    print_msg(0, "", "-!- %s is %s (%s)\n", from, show, status);
  if (u) {
    if (!strcmp(u->type, "groupchat")) {
      if (!strcasecmp(show, STR_ONLINE) || !strcasecmp(show, STR_OFFLINE))
        print_msg(npart, part, "-!- %s is %s\n", from, show);
    } else {
      print_msg(npart, part, "-!- %s is %s (%s)\n", from, show, status);
      snprintf(u->show, sizeof(u->show), "%s", show);
      snprintf(u->status, sizeof(u->status), "%s", status);
    }
  }
  return 0;
}
Beispiel #3
0
Datei: ji.c Projekt: placek/ji
static int
msg_hook(int x, struct xmpp *xmpp)
{
  char *s, *from, *part, *n, *type;
  int npart, len;
  struct contact *u;

  s = xml_node_find_text(x, "body", &xmpp->xml.mem);
  from = xml_node_find_attr(x, "from", &xmpp->xml.mem);
  part = from ? jid_partial(from, &npart) : 0;
  if (!part || !s)
    return 0;
  u = add_contact(npart, part);
  type = xml_node_find_attr(x, "type", &xmpp->xml.mem);
  if (type && !strcmp(type, "groupchat")) {
    u->type = "groupchat";
    n = jid_resource(from, &len);
  } else
    n = jid_name(from, &len);
  print_msg(npart, from, "<%.*s> %s\n", len, n, s);
  notify(u->type, npart, from, len, n, s);
  return 0;
}