Logo Search packages:      
Sourcecode: jabberd2 version File versions  Download package

int os_object_get ( os_t  os,
os_object_t  o,
const char *  key,
void **  val,
os_type_t  type,
os_type_t ot 
)

get a field from the object of type type (result in val), ret 0 == not found

Definition at line 221 of file object.c.

References os_object_st::hash, os_type_BOOLEAN, os_type_INTEGER, os_type_NAD, os_type_STRING, os_type_UNKNOWN, os_st::p, os_field_st::type, and os_field_st::val.

Referenced by os_object_get_nad().

                                                                                                      {
    os_field_t osf;
    nad_t nad;

   /* Type complexity is to deal with string/NADs. If an object contains xml, it will only be 
      parsed and returned as a NAD if type == os_type_NAD, otherwise if type == os_type_UNKNOWN
      it will be returned as string, unless it's already been converted to a NAD */

    osf = (os_field_t) xhash_get(o->hash, key);
    if(osf == NULL) {
        *val = NULL;
        return 0;
    }

    if (ot != NULL)
      *ot = osf->type; 

    if (type == os_type_UNKNOWN)
      type = osf->type;

    switch(type) {
        case os_type_BOOLEAN:
        case os_type_INTEGER:
            * (int *) val = * (int *) osf->val;
            break;

        case os_type_STRING:
            *val = osf->val;
            break;

        case os_type_NAD:
            /* check to see whether it's already a NAD */
            if (osf->type == os_type_NAD) {
                   *val = osf->val;  
            } else {
                 /* parse the string into a NAD */
                   nad = nad_parse(NULL, ((char *) osf->val) + 3, strlen(osf->val) - 3); 
                   if(nad == NULL) {
                            /* unparseable NAD */
                            log_debug(ZONE, "cell returned from storage for key %s has unparseable XML content (%lu bytes)", key, strlen(osf->val)-3); 
                            return 0;
                   } 

                   /* replace the string with a NAD */
                   osf->val = (void *) nad;

                   pool_cleanup(os->p, (pool_cleaner) nad_free, (void *) nad);

                   *val = osf->val;
                   osf->type = os_type_NAD;

            }
            break;

        default:
            *val = NULL;
    }

    log_debug(ZONE, "got field %s (val %x type %d) to object", key, *val, type);

    return 1;
}


Generated by  Doxygen 1.6.0   Back to index