예제 #1
0
static PyObject * p_hdf_get_attr (PyObject *self, PyObject *args)
{
  HDFObject *ho = (HDFObject *)self;
  PyObject *rv, *item;
  char *name;
  HDF_ATTR *attr;

  if (!PyArg_ParseTuple(args, "s:getAttrs(name)", &name))
    return NULL;

  rv = PyList_New(0);
  if (rv == NULL) return NULL;
  Py_INCREF(rv);
  attr = hdf_get_attr (ho->data, name);
  while (attr != NULL)
  {
    item = Py_BuildValue("(s,s)", attr->key, attr->value);
    if (item == NULL)
    {
      Py_DECREF(rv); 
      return NULL;
    }
    if (PyList_Append(rv, item) == -1)
    {
      Py_DECREF(rv); 
      return NULL;
    }
    attr = attr->next;
  }
  return rv;
}
예제 #2
0
파일: mcs.c 프로젝트: pombredanne/cmoon
char* mcs_hdf_attr(HDF *hdf, char *name, char*key)
{
    if (hdf == NULL || key == NULL)
        return NULL;
    
    HDF_ATTR *attr = hdf_get_attr(hdf, name);
    while (attr != NULL) {
        if (!strcmp(attr->key, key)) {
            return attr->value;
        }
        attr = attr->next;
    }
    return NULL;
}
예제 #3
0
파일: mscli.c 프로젝트: bigclean/moc
/*
 * application logic message, called by msparse_buf()
 */
static NEOERR* msparse_msg(moc_srv *srv, unsigned char *buf, size_t len, moc_arg *arg)
{
    uint32_t id, reply;
    unsigned char *payload;
    size_t psize, rv;

    MOC_NOT_NULLB(arg, arg->evth);
    
    if (!srv || !buf || len < 8) return nerr_raise(NERR_ASSERT, "illegal packet");

    //MSG_DUMP("recv: ", buf, len);

    /* The header is:
     * 4 bytes    ID
     * 4 bytes    Reply Code
     * Variable   Payload
     */
    id = ntohl(* ((uint32_t *) buf));
    reply = ntohl(* ((uint32_t *) buf + 1));

    payload = buf + 8;
    psize = len - 8;

    if (id == 0 && reply == 10000) {
        /*
         * server push
         */
        if (psize < 4) return nerr_raise(NERR_ASSERT, "server pushed empty message");

        struct msqueue_entry *e = msqueue_entry_create();
        if (!e) return nerr_raise(NERR_NOMEM, "alloc msqueue entry");
        
        rv = unpack_hdf(payload + 4, psize - 4, &(e->hdfrcv));
        if (rv <= 0) return nerr_raise(NERR_ASSERT, "server pushed illegal message");

        //TRACE_HDF(e->hdfrcv);

        char *cmd = NULL;
        HDF_ATTR *attr = hdf_get_attr(e->hdfrcv, "_Reserve");
        while (attr != NULL) {
            if (!strcmp(attr->key, "cmd")) cmd = attr->value;
            attr = attr->next;
        }
        if (!cmd) return nerr_raise(NERR_ASSERT, "cmd not supplied");

        e->ename = strdup(srv->evt->ename);
        e->cmd = strdup(cmd);

        mtc_dbg("receive cmd %s", cmd);
        
        hdf_remove_tree(e->hdfrcv, "_Reserve");

        mssync_lock(&arg->callbacksync);
        msqueue_put(arg->callbackqueue, e);
        mssync_unlock(&arg->callbacksync);

        /*
         * notify callback thread
         */
        mssync_signal(&arg->callbacksync);
    } else {
        /*
         * server response
         */
        if (id < g_reqid)
            return nerr_raise(NERR_ASSERT, "id not match %d %d", g_reqid, id);

        if (psize >= 4) {
            mssync_lock(&(arg->mainsync));
            rv = unpack_hdf(payload + 4, psize - 4, &(srv->evt->hdfrcv));
            mssync_unlock(&(arg->mainsync));
            if (rv <= 0)
                return nerr_raise(NERR_ASSERT, "server responsed illegal message");

            //TRACE_HDF(srv->evt->hdfrcv);
        }

        /*
         * notify main thread
         */
        mssync_signal(&(arg->mainsync));
    }
    
    return STATUS_OK;
}