Example #1
0
static void https_send_read_read_content_rsp_cb(VMUINT16 request_id, VMUINT8 seq_num, 
                                                 VMUINT8 result, VMBOOL more, 
                                                 VMUINT8 *reply_segment, VMUINT32 reply_segment_len)
{
    VMINT ret = -1;
    vm_log_debug("reply_content:%s", reply_segment);
    if (more > 0) {
        ret = vm_https_read_content(
            request_id,                                    /* Request ID */
            ++g_read_seg_num,                 /* Sequence number (for debug purpose) */
            100);                                          /* The suggested segment data length of replied data in the peer buffer of 
                                                              response. 0 means use reply_segment_len in MSG_ID_WPS_HTTP_REQ or 
                                                              read_segment_length in previous request. */
        if (ret != 0) {
            vm_https_cancel(request_id);
            vm_https_unset_channel(g_channel_id);
        }
    }
    else {
        /* don't want to send more requests, so unset channel */
        vm_https_cancel(request_id);
        vm_https_unset_channel(g_channel_id);
        g_channel_id = 0;
        g_read_seg_num = 0;

    }
}
Example #2
0
//-------------------------------------------------------------------------
static void https_send_read_read_content_rsp_cb(VMUINT16 request_id,
                                                VMUINT8 seq_num,
                                                VMUINT8 result,
                                                VMBOOL more,
                                                VMUINT8* reply_segment,
                                                VMUINT32 reply_segment_len)
{
    int ret = -1;

	if (g_https_response_cb_ref != LUA_NOREF) {
		int i;
		luaL_Buffer b;

		lua_rawgeti(L, LUA_REGISTRYINDEX, g_https_response_cb_ref);
		if ((lua_type(L, -1) != LUA_TFUNCTION) && (lua_type(L, -1) != LUA_TLIGHTFUNCTION)) {
		  // * BAD CB function reference
		  lua_remove(L, -1);
		}
		else {
			luaL_buffinit(L, &b);
			for(i = 0; i < reply_segment_len; i++) {
				luaL_addchar(&b, reply_segment[i]);
			}

			luaL_pushresult(&b);
			lua_pushinteger(L, more);

			lua_call(L, 2, 0);
		}
	}
	else {
		for(int i = 0; i < reply_segment_len; i++) {
			fputc(reply_segment[i], stdout);
		}
		fflush(stdout);
	}

    if(more > 0) {
        ret = vm_https_read_content(request_id,       /* Request ID */
                                    ++g_read_seg_num, /* Sequence number (for debug purpose) */
                                    128); /* The suggested segment data length of replied data in the peer buffer of
                                             response. 0 means use reply_segment_len in MSG_ID_WPS_HTTP_REQ or
                                             read_segment_length in previous request. */
        if(ret != 0) {
            vm_https_cancel(request_id);
            vm_https_unset_channel(g_channel_id);
        }
    } else {
        /* don't want to send more requests, so unset channel */
        vm_https_cancel(request_id);
        vm_https_unset_channel(g_channel_id);
        g_channel_id = 0;
        g_read_seg_num = 0;
    }
}
Example #3
0
static void https_send_read_request_rsp_cb(VMUINT16 request_id, VMUINT8 result,
		VMUINT16 status, VMINT32 cause, VMUINT8 protocol,
		VMUINT32 content_length, VMBOOL more, VMUINT8 *content_type,
		VMUINT8 content_type_len, VMUINT8 *new_url, VMUINT32 new_url_len,
		VMUINT8 *reply_header, VMUINT32 reply_header_len,
		VMUINT8 *reply_segment, VMUINT32 reply_segment_len) {
	VMINT ret = -1;
	vm_log_debug("https_send_request_rsp_cb()");
	if (result != 0) {
		vm_https_cancel(request_id);
		vm_https_unset_channel(g_channel_id);
	} else {
		vm_log_debug("reply_content:%s", reply_segment);
		ret = vm_https_read_content(request_id, ++g_read_seg_num, 100);
		if (ret != 0) {
			vm_https_cancel(request_id);
			vm_https_unset_channel(g_channel_id);
		}
	}
}
Example #4
0
//--------------------------------------------------------------------
static void https_send_read_request_rsp_cb(VMUINT16 request_id,
                                           VMUINT8 result,
                                           VMUINT16 status,
                                           VMINT32 cause,
                                           VMUINT8 protocol,
                                           VMUINT32 content_length,
                                           VMBOOL more,
                                           VMUINT8* content_type,
                                           VMUINT8 content_type_len,
                                           VMUINT8* new_url,
                                           VMUINT32 new_url_len,
                                           VMUINT8* reply_header,
                                           VMUINT32 reply_header_len,
                                           VMUINT8* reply_segment,
                                           VMUINT32 reply_segment_len)
{
    int ret = -1;

    if(result != 0) {
        vm_https_cancel(request_id);
        vm_https_unset_channel(g_channel_id);
    } else {
        g_request_id = request_id;
    	if (g_https_header_cb_ref != LUA_NOREF) {
			int i;
			luaL_Buffer b;

			lua_rawgeti(L, LUA_REGISTRYINDEX, g_https_header_cb_ref);
			if ((lua_type(L, -1) != LUA_TFUNCTION) && (lua_type(L, -1) != LUA_TLIGHTFUNCTION)) {
			  // * BAD CB function reference
			  lua_remove(L, -1);
			}
			else {
				luaL_buffinit(L, &b);
				for(i = 0; i < reply_header_len; i++) {
					luaL_addchar(&b, reply_header[i]);
				}
				luaL_pushresult(&b);
				lua_call(L, 1, 0);
			}
    	}
    	else {
    		fputs("\n--- Header: ---\n", stdout);
			for(int i = 0; i < reply_header_len; i++) {
				fputc(reply_header[i], stdout);
			}
    		fputs("\n---------------\n", stdout);
			fflush(stdout);
    	}

    	if (g_https_response_cb_ref != LUA_NOREF) {
			int i;
			luaL_Buffer b;

			lua_rawgeti(L, LUA_REGISTRYINDEX, g_https_response_cb_ref);
			if ((lua_type(L, -1) != LUA_TFUNCTION) && (lua_type(L, -1) != LUA_TLIGHTFUNCTION)) {
			  // * BAD CB function reference
			  lua_remove(L, -1);
			}
			else {
				luaL_buffinit(L, &b);
				for(i = 0; i < reply_segment_len; i++) {
					luaL_addchar(&b, reply_segment[i]);
				}
				luaL_pushresult(&b);
				lua_pushinteger(L, more);
				lua_call(L, 2, 0);
			}
    	}
    	else {
			for(int i = 0; i < reply_segment_len; i++) {
				fputc(reply_segment[i], stdout);
			}
			fflush(stdout);
    	}

        if(more) {
            ret = vm_https_read_content(request_id, ++g_read_seg_num, 128);
            if(ret != 0) {
                vm_https_cancel(request_id);
                vm_https_unset_channel(g_channel_id);
            }
        }
    }
}