int remove_mre(const char *file_path){ 
	/* 
	MSC:
	int remove(const char *file_path);

	MRE:
	VMINT vm_file_delete(const VMWSTR filename);	
	*/

	int remove_result;
	VMWCHAR wfile_path[MRE_STR_SIZE_MAX + 1];

	/* VMSTR to VMWSTR string format conversion */
	vm_ascii_to_ucs2 (wfile_path, MRE_STR_SIZE_MAX, file_path);
	remove_result = vm_file_delete(wfile_path);

	return remove_result;
}
void app_log_file(char *fmt, ...)
{
    va_list args;
    VMINT drv, hdl;
    VMUINT written;
    VMINT ret;
    vm_time_t time = {0};
    char buf[LOG_BUF_SIZE] = {0};
    VMWCHAR wpath[FILE_PATH_SIZE] = {0};
    VMCHAR path[FILE_PATH_SIZE] = {0};
  
    buf[LOG_BUF_SIZE - 2] = '\r';
    buf[LOG_BUF_SIZE - 1] = '\n';

    va_start( args, fmt );
    vm_get_time(&time);
    vm_sprintf(buf+strlen(buf), "[%02d:%02d:%02d]", time.hour, time.min, time.sec);
    vm_vsprintf(buf+strlen(buf), fmt, args);
        
    drv = vm_get_removable_driver() > 0 ? vm_get_removeable_driver() : vm_get_system_driver();
    vm_sprintf(path, "%c:\\%s", drv, BT_NAME".log");

    vm_gb2312_to_ucs2(wpath, sizeof(wpath), path); 
    hdl = vm_file_open(wpath, MODE_APPEND, 0);
    if (hdl < 0)
        hdl = vm_file_open(wpath, MODE_CREATE_ALWAYS_WRITE, 0);
    else
    {
        if (!flag_delete_log)
        {
            vm_file_close(hdl);
            vm_file_delete(wpath);
            flag_delete_log = 1;
            hdl = vm_file_open(wpath, MODE_CREATE_ALWAYS_WRITE, 0);
        }
    }
    
    vm_file_write(hdl, buf, LOG_BUF_SIZE, &written);
    vm_file_close(hdl);

    va_end( args );						
}
Esempio n. 3
0
static void _vm_preload_clean(vm_preload_ctx_t * ctx_p)
{
    VMINT found = 0;

    found = _vm_preload_check_valid(ctx_p);

    if (found)
    {
        if (E_PRELOAD_DOWNLOADED != ctx_p->status)
        {
            vm_file_delete(ctx_p->path);
        }
        if (0 < ctx_p->soc_id)
        {
            vm_tcp_close(ctx_p->soc_id);
        }
        memset(ctx_p, 0, sizeof(vm_preload_ctx_t));
        //ctx_p->p_hdl = 0;
        ctx_p->soc_id = -1;
        //ctx_p->res_id = -10;
    }
}
Esempio n. 4
0
static void _vm_preload_read_data(vm_preload_ctx_t * ctx_p)
{
    VMCHAR *body = (VMCHAR *)_vm_kernel_calloc(BUFFER_LEN);
    //VMCHAR http_buffer[BUFFER_LEN] = {0};
    VMINT len = 0, i = 0;
    VMINT http_header_received = 0;
    VMINT first_downloaded = 0;
    VMINT http_header_len = 0;
    VMINT file_handle = -1;
    VMINT ret = 0;
    VMBYTE * buf = NULL;
    VMFILE f_handle = -1;
    VMUINT written = 0;
    vm_preload_recv_data_t data = {{E_PRELOAD_QUERYING, NULL}, 0, 0}; 

    
    data.head.user_data = ctx_p->user_data;

    //memset(buf, 0, sizeof(2*BUFFER_LEN));

    MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3358 , ctx_p->g_http_content_length);       

    // read the header
    if (0 == ctx_p->g_http_content_length)
    {
        
        buf = (VMBYTE *)_vm_kernel_malloc(BUFFER_LEN);
        if (NULL == buf)
        {
            MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_PRELOAD_E1, 7, __LINE__);
            return;
        }
        memset(buf, 0, sizeof(BUFFER_LEN));
        while ((ret = vm_tcp_read (ctx_p->soc_id, buf + len, BUFFER_LEN - len)) > 0)
        {
            len += ret;
            MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3369 , ret, len);         
        }
        
        for(i = 1; i < len; i++)
        {
            if (buf[i] == LF && buf[i - 1] == CR)
            {
                if (app_strnicmp((kal_char *)&buf[http_header_len], (kal_char *)CONTENT_LENGTH, strlen(CONTENT_LENGTH)) == 0)
                {
                    buf[i - 1] = '\0';
                    first_downloaded = 0;
                    ctx_p->g_http_content_length = atoi((const char *)&buf[http_header_len] + strlen(CONTENT_LENGTH) + 1);
                    ctx_p->need_recv_len = ctx_p->g_http_content_length;
                    //data.total = http_content_length;I
                    
                    ctx_p->update = 1;
                }

                http_header_len = i + 1;

                if ((i + 2) < len && 
                (buf[i + 2] == LF && buf[i + 1] == CR))
                {
					http_header_len += 2;
                    first_downloaded = len - http_header_len;					
					break;
                }
            }
        }
        
        //strncpy(body, buf + 2, first_downloaded);
        memcpy(body, &buf[http_header_len], first_downloaded);
        _vm_kernel_free(buf);
        if (!vm_preload_is_url_valid(body, ctx_p, 0))
        {
            _vm_preload_try_download(ctx_p);
            ctx_p->g_http_content_length = ctx_p->need_recv_len = 0;
            //ctx_p->update = 0;
            _vm_kernel_free(body);
            return;
        }
        
        // preparing file
        f_handle = vm_file_open(ctx_p->path, MODE_READ, 1);
        if (0 <= f_handle)
        {
            vm_file_close(f_handle);
            MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3411 );
            vm_file_delete(ctx_p->path);
        }
        f_handle = vm_file_open(ctx_p->path, MODE_CREATE_ALWAYS_WRITE, 1);
    }

    // preparing file
    if (0 > f_handle)
    {
        f_handle = vm_file_open(ctx_p->path, MODE_APPEND, 1);
    }

    if (0 > f_handle)
    {
        VMCHAR buf[260];
        vm_ucs2_to_ascii(buf, 260, ctx_p->path);
        MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3429 , buf);
        data.head.state = E_PRELOAD_ERR_PATH;
        ctx_p->status = E_PRELOAD_ERR_PATH;
        _vm_preload_clean_and_free_ctx(ctx_p, &data);
        _vm_kernel_free(body);
        return;
    }

    // no disk space
    {
        VMWCHAR drv_wname[4] = {0};  
        VMUINT size = 0;
        vm_wstrncpy(drv_wname, ctx_p->path, 1);
        size = vm_get_disk_free_space(drv_wname);

        if (size < (VMUINT)ctx_p->g_http_content_length)
        {
            MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3429 , (VMCHAR*)drv_wname);
            data.head.state = E_PRELOAD_FAILURE;
            ctx_p->status = E_PRELOAD_FAILURE;
            if (0 <= f_handle)
            {
                vm_file_close(f_handle);
				vm_file_delete(ctx_p->path);
            }               
            _vm_preload_clean_and_free_ctx(ctx_p, &data);
            _vm_kernel_free(body);
            return;
        }
     
    }


    do
    {
        len = first_downloaded;

        while ((ret = vm_tcp_read (ctx_p->soc_id, body + len, 
            (ctx_p->g_http_content_length > BUFFER_LEN ? BUFFER_LEN : ctx_p->g_http_content_length) - len)) > 0)
        {
            // would block
            if (0 == ret)
            {
                MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3448 );
                break;
            }
            len += ret;
            if (BUFFER_LEN == len)
            {
                MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3454 );
                break;
            }
        }
        
        ctx_p->g_http_content_length -= len;
        first_downloaded = 0;
    
        MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3462 , len);            
        data.head.state = E_PRELOAD_DOWNLOADING;
        ctx_p->status = (VMINT)E_PRELOAD_DOWNLOADING;
        data.total = ctx_p->need_recv_len;
        data.received = ctx_p->need_recv_len - ctx_p->g_http_content_length;
        //data.buf = body;
        //data.size = len;
        
        MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3469 , data.received, data.total);
        MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3470 );

        vm_file_write(f_handle, body, len, &written);
    
        PRELOAD_PMNG_WRAP_CALLBACK(ctx_p->p_hdl, 
            ctx_p->cb, ctx_p->res_id, (void*)&data);
        
    } while (BUFFER_LEN == len && 0 != ret); // would block break

    vm_file_close(f_handle);

    if (0 == ctx_p->g_http_content_length)
    {
        data.head.state = E_PRELOAD_DOWNLOADED;
        ctx_p->status = (VMINT)E_PRELOAD_DOWNLOADED;
        data.total = ctx_p->g_http_content_length;
        MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3485 , data.total);
        MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3486 );
        _vm_preload_clean_and_free_ctx(ctx_p, &data);
    }
    #if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
    #endif
    
    _vm_kernel_free(body);
    MMI_TRACE(MMI_MRE_TRC_MOD_VMSOCK, TRC_MRE_VMSOCK_3582 );            
}