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; } }
//------------------------------------------------------------------------- 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; } }
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); } } }
//===================================== static int https_cancel( lua_State* L ) { if (g_request_id >= 0) { vm_https_cancel(g_request_id); } vm_https_unset_channel(g_channel_id); g_channel_id = 0; g_read_seg_num = 0; return 0; }
static void https_send_request_set_channel_rsp_cb(VMUINT32 req_id, VMUINT8 channel_id, VMUINT8 result) { VMINT ret = -1; ret = vm_https_send_request(0, /* Request ID */ VM_HTTPS_METHOD_GET, /* HTTP Method Constant */ VM_HTTPS_OPTION_NO_CACHE, /* HTTP request options */ VM_HTTPS_DATA_TYPE_BUFFER, /* Reply type (wps_data_type_enum) */ 100, /* bytes of data to be sent in reply at a time. If data is more that this, multiple response would be there */ (VMUINT8 *) VMHTTPS_TEST_URL, /* The request URL */ strlen(VMHTTPS_TEST_URL), /* The request URL length */ NULL, /* The request header */ 0, /* The request header length */ NULL, 0); if (ret != 0) { vm_https_unset_channel(channel_id); } }
//---------------------------------------------------------------------------------------------------- static void https_post_request_set_channel_rsp_cb(VMUINT32 req_id, VMUINT8 channel_id, VMUINT8 result) { VMINT ret = -1; if (g_post_type == 0) { ret = vm_https_send_request(0, // Request ID VM_HTTPS_METHOD_POST, // HTTP Method Constant VM_HTTPS_OPTION_NO_CACHE, // HTTP request options VM_HTTPS_DATA_TYPE_BUFFER, // Reply type (wps_data_type_enum) REPLY_SEGMENT_LENGTH, // bytes of data to be sent in reply at a time. // If data is more that this, multiple response would be there g_https_url, // The request URL strlen(g_https_url), // The request URL length CONTENT_TYPE_WWWFORM, // The request header strlen(CONTENT_TYPE_WWWFORM), // The request header length g_postdata, // Post segment g_postdata_len); // Post segment length vm_log_debug("[POST] to %s, result=%d", g_https_url, ret); } else { g_post_context->content = (vm_https_content_t *)g_post_content; g_postdata_ptr = g_postdata; ret = vm_https_request_ext(0, // Request ID VM_HTTPS_METHOD_POST, // HTTP Method Constant VM_HTTPS_OPTION_NO_CACHE, // HTTP request options VM_HTTPS_DATA_TYPE_BUFFER, // Reply type (wps_data_type_enum) REPLY_SEGMENT_LENGTH, // bytes of data to be sent in reply at a time. // If data is more that this, multiple response would be there VM_TRUE, // more posts VM_HTTPS_DATA_TYPE_MULTIPART, // post type g_post_context, // The request data _post_cb); // The callback of post status vm_log_debug("[POST] to '%s', nseg=%d, result=%d", g_post_context->url, g_post_context->number_entries, ret); } if(ret != 0) { vm_https_unset_channel(channel_id); } }
//---------------------------------------------------------------------------------------------------- static void https_send_request_set_channel_rsp_cb(VMUINT32 req_id, VMUINT8 channel_id, VMUINT8 result) { VMINT ret = -1; g_channel_id = channel_id; ret = vm_https_send_request(0, // Request ID VM_HTTPS_METHOD_GET, // HTTP Method Constant VM_HTTPS_OPTION_NO_CACHE, // HTTP request options VM_HTTPS_DATA_TYPE_BUFFER, // Reply type (wps_data_type_enum) REPLY_SEGMENT_LENGTH, // bytes of data to be sent in reply at a time. // If data is more that this, multiple response would be there g_https_url, // The request URL strlen(g_https_url), // The request URL length NULL, // The request header 0, // The request header length NULL, // post segment 0 // post segment length ); if(ret != 0) { vm_https_unset_channel(channel_id); } vm_log_debug("[HTTPS] GET req to %s, result %d", g_https_url, ret); }
//-------------------------------------------------------------------- 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); } } } }