Exemplo n.º 1
0
rc_t TarNode_MakeXML(const KXMLNode* xml_node, FSNode** self, char* errmsg, const char* rel_path)
{
    rc_t rc = 0;

    if( xml_node == NULL || self == NULL ) {
        rc = RC(rcExe, rcNode, rcConstructing, rcParam, rcNull);
    } else {
        char name[4096];
        size_t sz;

        rc = KXMLNodeReadAttrCString(xml_node, "name", name, sizeof(name), &sz);
        if( rc != 0 || sz == 0 || name[0] == '\0' ) {
            strcpy(errmsg, "attribute 'name'");
            rc = rc ? rc : RC(rcExe, rcDoc, rcValidating, rcAttr, rcInvalid);
        } else if( (rc = FSNode_Make(self, name, &TarNode_vtbl)) == 0 ) {
            ((TarNode*)*self)->rel_path = rel_path;
            strcpy(errmsg, "processing Item(s)");
            if( (rc = TarNode_MakeFileList(xml_node, &((TarNode*)*self)->files, errmsg, rel_path, (*self)->name)) != 0 ) {
                FSNode_Release(*self);
                *self = NULL;
            }
        }
    }
    return rc;
}
Exemplo n.º 2
0
static
rc_t SRAConfigParse(const KXMLNode* xml_node, SRAConfigFlags* flags, char* errmsg)
{
    rc_t rc = 0;
    uint32_t i;
    char at[4096];
    size_t sz;
    char* attr_name[]         = { "run-directory", "SRA-archive",   "SRA-archive-lite",  "fastq",           "SFF" };
    SRAConfigFlags attr_val[] = { eSRAFuseRunDir,  eSRAFuseFileArc, eSRAFuseFileArcLite, eSRAFuseFileFastq, eSRAFuseFileSFF };

    if( *flags & eSRAFuseInitial ) {
        *flags = 0;
    }
    for(i = 0; rc == 0 && i < sizeof(attr_name)/sizeof(attr_name[0]); i++) {
        if( (rc = KXMLNodeReadAttrCString(xml_node, attr_name[i], at, sizeof(at), &sz)) == 0 ) {
            if( strcasecmp(at, "true") == 0 ) {
                *flags = *flags | attr_val[i];
            } else if( strcasecmp(at, "false") == 0 ) {
                *flags = *flags & ~(attr_val[i]);
            } else {
                strcpy(errmsg, "SRAConfig attribute ");
                strcat(errmsg,  attr_name[i]);
                strcat(errmsg, " value '");
                strcat(errmsg, at);
                strcat(errmsg, "'");
                rc = RC(rcExe, rcDoc, rcReading, rcData, rcInvalid);
            }
        } else if( GetRCState(rc) == rcNotFound ) {
            rc = 0;
        }
    }
    return rc;
}
Exemplo n.º 3
0
rc_t XML_ParseBool(const KXMLNode* xml_node, const char* attr, bool* val, bool optional)
{
    rc_t rc;
    char b[16];
    size_t sz;

    if( (rc = KXMLNodeReadAttrCString(xml_node, attr, b, sizeof(b), &sz)) == 0 ) {
        if( strcasecmp(b, "true") == 0 || strcasecmp(b, "on") == 0 || strcasecmp(b, "yes") == 0 ) {
            *val = true;
        } else if( strcasecmp(b, "false") == 0 || strcasecmp(b, "off") == 0 || strcasecmp(b, "no") == 0 ) {
            *val = false;
        } else {
            rc = RC(rcExe, rcDoc, rcReading, rcAttr, rcInvalid);
        }
    } else if( optional && GetRCObject(rc) == rcAttr && GetRCState(rc) == rcNotFound ) {
        rc = 0;
    }
    return rc;
}
Exemplo n.º 4
0
rc_t XML_ParseTimestamp(const KXMLNode* xml_node, const char* attr, KTime_t* timestamp, bool optional)
{
    rc_t rc;
    char ts[128];
    size_t sz;

    if( (rc = KXMLNodeReadAttrCString(xml_node, attr, ts, sizeof(ts), &sz)) == 0 ) {
        struct tm tm;
        memset(&tm, 0, sizeof(tm));
        if( strptime(ts, "%Y-%m-%dT%H:%M:%S", &tm) != NULL ) {
            *timestamp = mktime(&tm);
        } else {
            rc = RC(rcExe, rcDoc, rcReading, rcAttr, rcInvalid);
        }
    } else if( optional && GetRCObject(rc) == rcAttr && GetRCState(rc) == rcNotFound ) {
        rc = 0;
    }
    return rc;
}
Exemplo n.º 5
0
static rc_t XmlMetaInitMembers(BSTree* tr, const KXMLNode* node) {
    rc_t rc = 0;
    const char path[] = "Member";
    uint32_t count = 0;
    uint32_t idx = 0;
    const KXMLNodeset *members = NULL;
    if (rc == 0) {
        rc = KXMLNodeOpenNodesetRead(node, &members, path);
        DISP_RC(rc, path);
    }
    if (rc == 0) {
        rc = KXMLNodesetCount(members, &count);
        DISP_RC(rc, path);
    }
    for (idx = 0; idx < count && rc == 0; ++idx) {
        const KXMLNode *node = NULL;
        char member_name[256] = "";
        if (rc == 0) {
            rc = KXMLNodesetGetNodeRead(members, &node, idx);
            DISP_RC(rc, path);
        }
        if (rc == 0) {
            size_t size = 0;
            rc = KXMLNodeReadAttrCString(node, "member_name",
                member_name, sizeof member_name, &size);
            if (rc) {
                if (GetRCState(rc) == rcInsufficient) {
                    member_name[sizeof member_name - 1] = '\0';
                    rc = 0;
                }
            }
        }
        if (rc == 0) {
            rc = XmlMetaInitMemser(tr, node, path, member_name);
        }
        RELEASE(KXMLNode, node);
    }
    RELEASE(KXMLNodeset, members);
    return rc;
}
Exemplo n.º 6
0
static
rc_t TarNode_MakeFileList(const KXMLNode* xml_node, const TarFileList** files, char* errmsg, const char* rel_path, const char* name)
{
    rc_t rc = 0;
    time_t now = time(NULL);
    uint32_t count = 0;

    *files = NULL;
    if( (rc = KXMLNodeCountChildNodes(xml_node, &count)) == 0 ) {
        if( count == 0 ) {
            rc = RC(rcExe, rcDoc, rcValidating, rcData, rcEmpty);
        } else if( (rc = TarFileList_Make(files, count, name)) == 0 ) {
            uint32_t i = 0;
            while(rc == 0 && i < count) {
                const KXMLNode* n = NULL;
                const char* n_name;
                if( (rc = KXMLNodeGetNodeRead(xml_node, &n, i++)) == 0 && (rc = KXMLNodeElementName(n, &n_name)) == 0 ) {
                    if( strcmp(n_name, "Item") != 0 ) {
                        rc = RC(rcExe, rcDoc, rcValidating, rcNode, rcUnexpected);
                        strcpy(errmsg, n_name);
                    } else {
                        size_t sz_read;
                        char path[4096], name[4096];
                        KTime_t ts = now;
                        uint64_t fsz = 0;
                        bool exec = false;

                        if( (rc = KXMLNodeReadAttrCString(n, "path", name, sizeof(name), &sz_read)) == 0 ) {
                            if( name[0] == '\0' ) {
                                rc = RC(rcExe, rcDoc, rcValidating, rcAttr, rcEmpty);
                            } else if( name[0] == '/' ) {
                                memmove(path, name, sz_read + 1);
                            } else {
                                KDirectory* dir = NULL;
                                if( (rc = KDirectoryNativeDir(&dir)) == 0 &&
                                    (rc = KDirectoryResolvePath(dir, true, path, sizeof(path), "%s/%s", rel_path, name)) == 0 ) {
                                    DEBUG_LINE(8, "%s/%s resolved to %s", rel_path, name, path);
                                }
                                KDirectoryRelease(dir);
                            }
                            if( rc != 0 ) {
                                strcpy(errmsg, "TAR/Item/@path");
                            }
                        }
                        if( rc == 0 && (rc = XML_ParseTimestamp(n, "timestamp", &ts, true)) != 0 ) {
                            strcpy(errmsg, "TAR/Item/@timestamp");
                        }
                        if( rc == 0 && (rc = XML_ParseBool(n, "executable", &exec, true)) != 0 ) {
                            strcpy(errmsg, "TAR/Item/@executable");
                        }
                        if( rc == 0 && (rc = KXMLNodeReadAttrAsU64(n, "size", &fsz)) != 0 ) {
                            strcpy(errmsg, "TAR/Item/@size");
                        }
                        if( rc == 0 ) {
                            name[0] = '\0';
                            rc = KXMLNodeReadAttrCString(n, "name", name, sizeof(name), &sz_read);
                            if( (GetRCObject(rc) == (enum RCObject)rcAttr && GetRCState(rc) == rcNotFound) || name[0] == '\0' ) {
                                char* x = strrchr(path, '/');
                                strcpy(name, x ? x + 1 : path);
                                rc = 0;
                            } else if( rc == 0 && name[0] == '/' ) {
                                strcat(errmsg, "Item/@name cannot be absolute");
                                rc = RC(rcExe, rcDoc, rcValidating, rcName, rcInvalid);
                            } else if( rc != 0 ) {
                                strcpy(errmsg, "Item/@name");
                            }
                        }
                        if( rc == 0 ) {
                            const KNamelist* attr = NULL;
                            if( (rc = KXMLNodeListAttr(n, &attr)) == 0 ) {
                                uint32_t j = 0, count = 0;
                                if( (rc = KNamelistCount(attr, &count)) == 0 && count > 0 ) {
                                    while( rc == 0 && j < count ) {
                                        const char *attr_nm = NULL;
                                        if( (rc = KNamelistGet(attr, j++, &attr_nm)) != 0 ) {
                                            break;
                                        }
                                        if( strcmp("path", attr_nm) == 0 || strcmp("name", attr_nm) == 0 ||
                                            strcmp("timestamp", attr_nm) == 0 || strcmp("size", attr_nm) == 0 ||
                                            strcmp("executable", attr_nm) == 0 ) {
                                            continue;
                                        }
                                        rc = RC(rcExe, rcDoc, rcValidating, rcDirEntry, rcInvalid);
                                        strcpy(errmsg, "unknown attribute TAR/Item/@");
                                        strcat(errmsg, attr_nm);
                                    }
                                }
                                ReleaseComplain(KNamelistRelease, attr);
                            }
                        }
                        if( rc == 0 && (rc = TarFileList_Add(*files, path, name, fsz, ts, exec)) != 0 ) {
                            strcpy(errmsg, "adding to TAR");
                        }
                    }
                    ReleaseComplain(KXMLNodeRelease, n);
                }
            }
            if( rc != 0 ) {
                TarFileList_Release(*files);
                *files = NULL;
            }
        }
    }
    return rc;
}