montage-tech/src/kware/network/http_file/http_download_mini.cpp
/*
*
*
*
*  RETURN VALUE:  1 means success
*                          0 means failure
*
*/
RETURN VALUE:  1 means success
0 means failure
RETURN VALUE : 1 means success 0 means failure
static int http_accept(struct thread_dld * dld)
{
    const ne_uri * reuri;
    const char * value;
    const ne_status * st;
    ne_request * req;
    int state;
    req = dld->req;
    st = ne_get_status(req);
    if (st->klass == 2) {
        value = ne_get_response_header(req, "Content-length");
        if (value != NULL) {
            dld->total = atoi(value);
        } else {
            dld->total = -1;
        }
        value = ne_get_response_header(req, "Content-Type");
        if (value) {
            http_fill_ctype(dld, value);
        }
        if(dld->http_rsp_header)
            http_parse_rsp_header(dld);
        if(dld->state == HTTP_ABORTED_BY_USER) {
            state = HTTP_ABORTED_BY_USER;
        } else {
            state = HTTP_DOWNLOADING;
        }
#if 0
        int nfd = ne_get_socket(dld->sess);
        if (strcmp(ne_get_scheme(dld->sess), "https") != 0) {
#if 0 
#endif
        }
        if (ne_get_buffered(dld->sess) != 0) {
            int tmp = http_begin_read(dld);
            if (tmp != -1) {
                state = tmp;
            }
        }
#endif
        return state;
    }
    if (st->klass == 3) {
        dld->code = ne_end_request(req);
        reuri = ne_redirect_location(dld->sess);
        if (reuri == NULL) {
            OS_PRINTF("Server Error, redirect with incorrect redirect URL\n");
            goto aborted;
        }
        ne_buffer_destroy(dld->url);
        dld->url = ne_buffer_create();
        char * p = ne_uri_unparse(reuri);
        ne_buffer_zappend(dld->url, p);
        ne_free(p);
        ne_request_destroy(dld->req);
        ne_session_destroy(dld->sess);
        dld->req = NULL;
        dld->sess = NULL;
        dld->redirect_flag = true;
        OS_PRINTF("redirect dld  on %p, url %s\n", dld, dld->url->data);
        state = http_begin_http(dld);
        return state;
    }
    OS_PRINTF("[%s]http dl aborted: %s\n", __func__, ne_get_error(dld->sess));
    http_fill_res(dld, dld->sess);
    dld->code = ne_end_request(req);
aborted:
    clean_arg(dld, CLEAN_ARG_CONN);
    if(dld->state == HTTP_ABORTED_BY_USER) {
        state = HTTP_ABORTED_BY_USER;
    } else {
        state = HTTP_ABORTED;
    }
    return state;
}
static int http_accept ( struct thread_dld * dld ) { const ne_uri * reuri ; const char * value ; const ne_status * st ; ne_request * req ; int state ; req = dld -> req ; st = ne_get_status ( req ) ; if ( st -> klass == 2 ) { value = ne_get_response_header ( req , " " ) ; if ( value != NULL ) { dld -> total = atoi ( value ) ; } else { dld -> total = -1 ; } value = ne_get_response_header ( req , " " ) ; if ( value ) { http_fill_ctype ( dld , value ) ; } if ( dld -> http_rsp_header ) http_parse_rsp_header ( dld ) ; if ( dld -> state == HTTP_ABORTED_BY_USER ) { state = HTTP_ABORTED_BY_USER ; } else { state = HTTP_DOWNLOADING ; } #if 0 int nfd = ne_get_socket ( dld -> sess ) ; if ( strcmp ( ne_get_scheme ( dld -> sess ) , " " ) != 0 ) { #if 0 #endif } if ( ne_get_buffered ( dld -> sess ) != 0 ) { int tmp = http_begin_read ( dld ) ; if ( tmp != -1 ) { state = tmp ; } } #endif return state ; } if ( st -> klass == 3 ) { dld -> code = ne_end_request ( req ) ; reuri = ne_redirect_location ( dld -> sess ) ; if ( reuri == NULL ) { OS_PRINTF ( " \n " ) ; goto aborted ; } ne_buffer_destroy ( dld -> url ) ; dld -> url = ne_buffer_create ( ) ; char * p = ne_uri_unparse ( reuri ) ; ne_buffer_zappend ( dld -> url , p ) ; ne_free ( p ) ; ne_request_destroy ( dld -> req ) ; ne_session_destroy ( dld -> sess ) ; dld -> req = NULL ; dld -> sess = NULL ; dld -> redirect_flag = true ; OS_PRINTF ( " \n " , dld , dld -> url -> data ) ; state = http_begin_http ( dld ) ; return state ; } OS_PRINTF ( " \n " , __func__ , ne_get_error ( dld -> sess ) ) ; http_fill_res ( dld , dld -> sess ) ; dld -> code = ne_end_request ( req ) ; aborted : clean_arg ( dld , CLEAN_ARG_CONN ) ; if ( dld -> state == HTTP_ABORTED_BY_USER ) { state = HTTP_ABORTED_BY_USER ; } else { state = HTTP_ABORTED ; } return state ; }
RETURN VALUE:  1 means success
0 means failure
RETURN VALUE : 1 means success 0 means failure
//OS_PRINTF("[%s] start start... \n", __func__); //int oflags; //OS_PRINTF("[%s] st->klass is 2.. \n", __func__); //OS_PRINTF("[%s] fill ctype... \n", __func__); //OS_PRINTF("[%s]  Downloading Starts , 0x%x !!!\n", __func__, dld); //del by libin ,move to downloader //def __LINUX__//to be confirmed //if ((oflags = fcntl(nfd, F_GETFL, 0)) != -1){ //fcntl(nfd, F_SETFL, oflags | O_NONBLOCK); //  } //OS_PRINTF("[%s] end end 1111... \n", __func__); //OS_PRINTF("[%s] st->klass is 3 [redirect encountered] \n", __func__); /* redirect encountered */ /* go for redirect */ //OS_PRINTF("[%s] end end 222222... \n", __func__); //OS_PRINTF("[%s] end end .. \n", __func__);