示例#1
0
文件: ji.c 项目: placek/ji
static int
roster_hook(int x, struct xmpp *xmpp)
{
  struct xml_data *d;
  char *jid, *name, *sub;

  for (d = xml_node_data(xml_node_find(x, "query", &xmpp->xml.mem),
                         &xmpp->xml.mem);
       d; d = xml_data_next(d, &xmpp->xml.mem)) {
    if (d->type != XML_NODE)
      continue;
    jid = xml_node_find_attr(d->value, "jid", &xmpp->xml.mem);
    name = xml_node_find_attr(d->value, "name", &xmpp->xml.mem);
    sub = xml_node_find_attr(d->value, "subscription", &xmpp->xml.mem);
    print_msg(0, "", "* %s - %s - [%s]\n", name ? name : "", jid, sub);
  }
  print_msg(0, "", "End of /R list.\n");
  for (d = xml_node_data(xml_node_find(x, "query", &xmpp->xml.mem),
                         &xmpp->xml.mem);
       d; d = xml_data_next(d, &xmpp->xml.mem)) {
    if (d->type != XML_NODE)
      continue;
    jid = xml_node_find_attr(d->value, "jid", &xmpp->xml.mem);
    request_presence(xmpp, jid);
  }
  return 0;
}
示例#2
0
文件: sjc.c 项目: gravicappa/libxmpps
static void
roster_handler(int x, struct xmpp *xmpp)
{
    struct xml_data *d;
    char *jid, *name, *sub;
    for (d = xml_node_data(xml_node_find(x, "query", &xmpp->xml.mem),
                           &xmpp->xml.mem);
            d;
            d = xml_data_next(d, &xmpp->xml.mem)) {
        if (d->type != XML_NODE)
            continue;
        jid = xml_node_find_attr(d->value, "jid", &xmpp->xml.mem);
        name = xml_node_find_attr(d->value, "name", &xmpp->xml.mem);
        sub = xml_node_find_attr(d->value, "subscription", &xmpp->xml.mem);
        print_msg("* %s - %s - [%s]\n", name ? name : "", jid, sub);
    }
    print_msg("End of roster\n");
    for (d = xml_node_data(xml_node_find(x, "query", &xmpp->xml.mem),
                           &xmpp->xml.mem);
            d;
            d = xml_data_next(d, &xmpp->xml.mem)) {
        if (d->type != XML_NODE)
            continue;
        jid = xml_node_find_attr(d->value, "jid", &xmpp->xml.mem);
        if (jid)
            xmpp_printf(xmpp, "<presence type='probe' to='%s'/>", jid);
    }
}
示例#3
0
unsigned long pi_configlock_event_load (plugin_user_t * user, void *dummy, unsigned long event,
                                        void *arg)
{
    FILE *fp;
    configlock_t *lock;
    config_element_t *elem;
    xml_node_t *base, *node;

    if (!arg)
        goto leave;

    while (locklist) {
        lock = locklist;
        locklist = locklist->next;
        free (lock);
    }

    fp = fopen ("configlock.xml", "r");
    if (!fp)
        goto leave;

    base = xml_read (fp);
    if (!base) {
        fclose (fp);
        goto leave;
    }

    if (strcmp (base->name, HUBSOFT_NAME)) {
        xml_free (base);
        goto leave;
    }

    config_load (base);

    node = xml_node_find (base, "Config");
    for (node = node->children; node; node = xml_next (node)) {
        elem = config_find (node->name);
        if (!elem)
            continue;

        lock = malloc (sizeof (configlock_t));
        memset (lock, 0, sizeof (configlock_t));

        lock->elem = elem;
        strncpy (lock->name, elem->name, CONFIG_NAMELENGTH);

        xml_node_get (node, elem->type, &lock->data.v_ptr);

        lock->next = locklist;
        locklist = lock;
    }

    xml_free (base);

    fclose (fp);

    return PLUGIN_RETVAL_CONTINUE;

leave:
    return pi_configlock_event_load_old (user, dummy, event, NULL);
}
示例#4
0
int pi_rrd_load (xml_node_t * base)
{
  xml_node_t *node;
  rrd_ctxt_t *rrd;
  unsigned char *name = NULL, *file = NULL, *dp = NULL, *spec = NULL;
  unsigned long period;

  base = xml_node_find (base, "RRDs");
  if (!base)
    return PLUGIN_RETVAL_CONTINUE;

  for (rrd = rrdlist.next; rrd != &rrdlist; rrd = rrdlist.next)
    pi_rrd_delete (rrd);

  for (node = base->children; node; node = xml_next (node)) {
    if (!xml_child_get (node, "Name", XML_TYPE_STRING, &name))
      continue;
    if (!xml_child_get (node, "File", XML_TYPE_STRING, &file))
      continue;
    if (!xml_child_get (node, "Period", XML_TYPE_ULONG, &period))
      continue;


    rrd = pi_rrd_create (name, file, period);
    if (!rrd)
      continue;

    base = node;
    node = xml_node_find (base, "DataPoints");
    for (node = node->children; node; node = xml_next (node)) {
      if (!xml_child_get (node, "Name", XML_TYPE_STRING, &name))
	continue;
      if (!xml_child_get (node, "Specification", XML_TYPE_STRING, &spec))
	continue;

      rrd->npoints++;
      pi_rrd_datapoint_create (NULL, &rrd->points, name, spec);
    }

    node = xml_node_find (base, "RRAs");
    for (node = node->children; node; node = xml_next (node)) {
      pi_rrd_datapoint_create (NULL, &rrd->rras, NULL, node->value);
      rrd->nrras++;
    }

    node = base;

    pi_rrd_start (rrd);
  }

  if (name)
    free (name);
  if (file)
    free (file);
  if (dp)
    free (dp);
  if (spec)
    free (spec);

  return PLUGIN_RETVAL_CONTINUE;
}