Exemple #1
0
static rc_t CC KNSManagerNewReleaseVersionImpl(const struct KNSManager *self,
    SraReleaseVersion *newVersion)
{
    rc_t rc = 0;
    KDataBuffer result;
    KHttpRequest *req = NULL;
    KHttpResult *rslt = NULL;
    if (newVersion == NULL) {
        return RC(rcNS, rcArgv, rcAccessing, rcParam, rcNull);
    }
    memset(newVersion, 0, sizeof *newVersion);
    if (self == NULL) {
        return RC(rcNS, rcArgv, rcAccessing, rcSelf, rcNull);
    }
    memset(&result, 0, sizeof result);
    if (rc == 0) {
        rc = KNSManagerMakeRequest(self, &req, 0x01010000, NULL,
  "https://ftp-trace.ncbi.nlm.nih.gov/sra/sdk/current/sratoolkit.current.version"
        );
    }
    if (rc == 0) {
        rc = KHttpRequestGET(req, &rslt);
    }
    if (rc == 0) {
        uint32_t code = 0;
        rc = KHttpResultStatus(rslt, &code, NULL, 0, NULL);
        if (rc == 0) {
            if (code != 200) {
                rc = RC(rcNS, rcFile, rcReading, rcFile, rcInvalid);
            }
        }
    }
    if (rc == 0) {
        size_t total = 0;
        KStream *response = NULL;
        rc = KHttpResultGetInputStream(rslt, &response);
        if (rc == 0) {
            rc = KDataBufferMakeBytes(&result, 1024);
        }
        while (rc == 0) {
            size_t num_read = 0;
            uint8_t *base = NULL;
            uint64_t avail = result.elem_count - total;
            if (avail < 256) {
                rc = KDataBufferResize(&result, result.elem_count + 1024);
                if (rc != 0) {
                    break;
                }
            }
            base = result.base;
            rc = KStreamRead(response, &base[total], result.elem_count - total,
                &num_read);
            if (num_read > 0 || rc != 0) {
                DBGMSG(DBG_VFS, DBG_FLAG(DBG_VFS), ("KStreamRead"
                    "(sratoolkit.current.version, %zu) = %R\n", num_read, rc));
            }
            if (rc != 0) {
                /* TBD - look more closely at rc */
                if (num_read > 0) {
                    rc = 0;
                }
                else {
                    break;
                }
            }
            if (num_read == 0) {
                break;
            }
            total += num_read;
        }
        RELEASE(KStream, response);
        if (rc == 0) {
            DBGMSG(DBG_VFS, DBG_FLAG(DBG_VFS),
                ("sratoolkit.current.version (%zu)\n", total));
            result.elem_count = total;
        }
    }

    if (rc == 0) {
        const char *start = (const void*)(result.base);
        size_t size = KDataBufferBytes(&result);
        DBGMSG(DBG_VFS, DBG_FLAG(DBG_VFS),
            ("sratoolkit.current.version = '%.*s'\n", (uint32_t)size, start));
        rc = SraReleaseVersionInit(newVersion, start, size);
    }

    KDataBufferWhack(&result);
    RELEASE(KHttpResult, rslt);
    RELEASE(KHttpRequest, req);

    return rc;
}
Exemple #2
0
LIB_EXPORT
rc_t CC
XFS_HttpStreamMake_ZHR (
                    const char * Url,
                    const struct XFSHttpStream ** Stream
)
{
    rc_t RCt;
    struct VPath * Path;
    struct String Host;
    uint32_t Port;
    struct XFSHttpStream * TheStream;

    RCt = 0;
    Path = NULL;

    if ( Stream != NULL ) {
        * Stream = NULL;
    }

    if ( Url == NULL || Stream == NULL ) {
        return XFS_RC ( rcNull );
    }

    RCt = VFSManagerMakePath ( XFS_VfsManager (), & Path, Url );
    if ( RCt == 0 ) {
        RCt = VPathGetHost ( Path, & Host );
        if ( RCt == 0 ) {
            Port = VPathGetPortNum ( Path );

            TheStream = calloc ( 1, sizeof ( struct XFSHttpStream ) );
            if ( TheStream == NULL ) {
                RCt = XFS_RC ( rcExhausted );
            }
            else {
                RCt = KNSManagerMakeHttp (
                                    XFS_KnsManager(),
                                    & ( TheStream -> http ),
                                    NULL,
                                    0x01010000,
                                    & Host,
                                    Port
                                    );
                if ( RCt == 0 ) {
                    RCt = KHttpMakeRequest (
                                        TheStream -> http,
                                        & ( TheStream -> req ),
                                        Url
                                        );
                    if ( RCt == 0 ) {
                        RCt = KHttpRequestGET (
                                        TheStream -> req,
                                        & ( TheStream -> res )
                                        );
                        if ( RCt == 0 ) {
                            RCt = KHttpResultGetInputStream (
                                                TheStream -> res,
                                                & ( TheStream -> str )
                                                );
                            if ( RCt == 0 ) {
                                TheStream -> completed = false;
                                TheStream -> last_error = 0;

                                * Stream = TheStream;
                            }
                        }
                    }
                }
            }
        }

        VPathRelease ( Path );
    }

    if ( RCt != 0 ) {
        * Stream = NULL;

        if ( TheStream != NULL ) {
            XFS_HttpStreamDispose_ZHR ( TheStream );
        }
    }

    return RCt;
}   /* XFS_HttpStreamMake_ZHR () */