CURLNetRequest::CURLHolder::CURLHolder() :m_active(0) { m_bTraceCalls = rho_conf_getBool("net_trace"); timeout = rho_conf_getInt("net_timeout"); if (timeout == 0) timeout = 30; // 30 seconds by default m_sslVerifyPeer = true; m_curlm = curl_multi_init(); m_curl = curl_easy_init(); curl_easy_setopt(m_curl, CURLOPT_ERRORBUFFER, &errbuf); }
VALUE callFramework(VALUE hashReq) { VALUE callres = rb_funcall(framework, framework_mid, 1, hashReq); if (TYPE(callres)!=T_STRING) { RAWLOG_INFO1("Method call result type = %s", rb_type_to_s(callres)); return rb_str_new2("Error");//TBD: Supply html description of the error } if ( !rho_conf_getBool("log_skip_post") ) RAWTRACE(RSTRING_PTR(callres)); rb_gc_register_mark_object(callres); //TBD: need to cleanup memory //rb_gc(); return callres; }
VALUE callServeIndex(char* index_name, VALUE hashReq) { VALUE callres; //RhoSetCurAppPath(index_name); callres = rb_funcall(framework, framework_mid2, 2, RhoPreparePath(rb_str_new2(index_name)), hashReq); if (TYPE(callres)!=T_STRING) { RAWLOG_INFO1("Method call result type = %s", rb_type_to_s(callres)); return rb_str_new2("Error");//TBD: Supply html description of the error } if ( !rho_conf_getBool("log_skip_post") ) RAWTRACE(RSTRING_PTR(callres)); rb_gc_register_mark_object(callres); //TBD: need to cleanup memory //rb_gc(); return callres; }
int rho_is_eval_disabled() { return !rho_conf_getBool("enable_eval"); }
bool CHttpServer::receive_request(ByteVector &request) { if (verbose) RAWTRACE("Receiving request..."); ByteVector r; char buf[BUF_SIZE]; int attempts = 0; for(;;) { if (verbose) RAWTRACE("Read portion of data from socket..."); int n = recv(m_sock, &buf[0], sizeof(buf), 0); //RAWTRACE1("RECV: %d", n); if (n == -1) { int e = RHO_NET_ERROR_CODE; if (verbose) RAWTRACE1("RECV ERROR: %d", e); #if !defined(WINDOWS_PLATFORM) if (e == EINTR) continue; #else if (e == WSAEINTR) continue; #endif #if defined(OS_WP8) || (defined(RHODES_QT_PLATFORM) && defined(OS_WINDOWS_DESKTOP)) || defined(OS_WINCE) if (e == EAGAIN || e == WSAEWOULDBLOCK) { #else if (e == EAGAIN) { #endif if (!r.empty()) break; if(++attempts > (HTTP_EAGAIN_TIMEOUT*10)) { if (verbose) RAWLOG_ERROR("Error when receiving data from socket. Client does not send data for " HTTP_EAGAIN_TIMEOUT_STR " sec. Cancel recieve."); return false; } fd_set fds; FD_ZERO(&fds); FD_SET(m_sock, &fds); timeval tv = {0}; tv.tv_usec = 100000;//100 MS select(m_sock + 1, &fds, 0, 0, &tv); continue; } if (verbose) RAWLOG_ERROR1("Error when receiving data from socket: %d", e); return false; } if (n == 0) { if(!r.empty()) { if (verbose) RAWTRACE("Client closed connection gracefully"); break; } else { if (verbose) RAWLOG_ERROR("Connection gracefully closed before we receive any data"); return false; } } else { if (verbose) RAWTRACE1("Actually read %d bytes", n); r.insert(r.end(), &buf[0], &buf[0] + n); } } if (!r.empty()) { request.insert(request.end(), r.begin(), r.end()); if ( !rho_conf_getBool("log_skip_post") ) { String strRequest(request.begin(),request.end()); if (verbose) RAWTRACE1("Received request:\n%s", strRequest.c_str()); } } return true; } bool CHttpServer::send_response_impl(String const &data, bool continuation) { #ifdef OS_MACOSX if ( m_localResponseWriter != 0 ) { m_localResponseWriter->writeResponse( data ); return true; } #endif if (verbose) { if (continuation) if (verbose) RAWTRACE("Send continuation data..."); else if (verbose) RAWTRACE("Sending response..."); } // First of all, make socket blocking #if defined(WINDOWS_PLATFORM) unsigned long optval = 0; if(::ioctlsocket(m_sock, FIONBIO, &optval) == SOCKET_ERROR) { RAWLOG_ERROR1("Can not set blocking socket mode: %d", RHO_NET_ERROR_CODE); return false; } #else int flags = fcntl(m_sock, F_GETFL); if (flags == -1) { if (verbose) RAWLOG_ERROR1("Can not get current socket mode: %d", errno); return false; } if (fcntl(m_sock, F_SETFL, flags & ~O_NONBLOCK) == -1) { if (verbose) RAWLOG_ERROR1("Can not set blocking socket mode: %d", errno); return false; } #endif size_t pos = 0; for(; pos < data.size();) { int n = send(m_sock, data.c_str() + pos, data.size() - pos, 0); if (n == -1) { int e = RHO_NET_ERROR_CODE; #if !defined(WINDOWS_PLATFORM) if (e == EINTR) continue; #endif if (verbose) RAWLOG_ERROR1("Can not send response data: %d", e); return false; } if (n == 0) break; pos += n; } //String dbg_response = response.size() > 100 ? response.substr(0, 100) : response; //RAWTRACE2("Sent response:\n%s%s", dbg_response.c_str(), response.size() > 100 ? "..." : " "); if (continuation) { if (verbose) RAWTRACE1("Sent response body: %d bytes", data.size()); } else if ( !rho_conf_getBool("log_skip_post") ) { if (verbose) RAWTRACE1("Sent response (only headers displayed):\n%s", data.c_str()); } return true; } bool CHttpServer::send_response(String const &response, bool redirect) { #ifdef OS_ANDROID if (redirect) { CAutoPtr<IRhoThreadImpl> ptrThread = rho_get_RhoClassFactory()->createThreadImpl(); ptrThread->sleep(20); } #endif return send_response_impl(response, false); } String CHttpServer::create_response(String const &reason) { return create_response(reason, ""); } String CHttpServer::create_response(String const &reason, HeaderList const &headers) { return create_response(reason, headers, ""); } String CHttpServer::create_response(String const &reason, String const &body) { return create_response(reason, HeaderList(), body); } String CHttpServer::create_response(String const &reason, HeaderList const &hdrs, String const &body) { String response = "HTTP/1.1 "; response += reason; response += "\r\n"; char buf[50]; snprintf(buf, sizeof(buf), "%d", m_port); HeaderList headers; headers.push_back(Header("Host", String("127.0.0.1:") + buf)); headers.push_back(Header("Connection", "close")); headers.push_back(HttpHeader("Access-Control-Allow-Origin", "*")); std::copy(hdrs.begin(), hdrs.end(), std::back_inserter(headers)); for(HeaderList::const_iterator it = headers.begin(), lim = headers.end(); it != lim; ++it) { response += it->name; response += ": "; response += it->value; response += "\r\n"; } response += "\r\n"; response += body; return response; }
void CNativeToolbar::createToolbar(rho_param *p) { if (!rho_rhodesapp_check_mode() || !rho_wmsys_has_touchscreen() ) return; int bar_type = TOOLBAR_TYPE; m_rgbBackColor = RGB(220,220,220); m_rgbMaskColor = RGB(255,255,255); m_nHeight = MIN_TOOLBAR_HEIGHT; rho_param *params = NULL; switch (p->type) { case RHO_PARAM_ARRAY: params = p; break; case RHO_PARAM_HASH: { for (int i = 0, lim = p->v.hash->size; i < lim; ++i) { const char *name = p->v.hash->name[i]; rho_param *value = p->v.hash->value[i]; if (strcasecmp(name, "background_color") == 0) m_rgbBackColor = getColorFromString(value->v.string); else if (strcasecmp(name, "mask_color") == 0) m_rgbMaskColor = getColorFromString(value->v.string); else if (strcasecmp(name, "view_height") == 0) m_nHeight = atoi(value->v.string); else if (strcasecmp(name, "buttons") == 0 || strcasecmp(name, "tabs") == 0) params = value; } } break; default: { LOG(ERROR) + "Unexpected parameter type for create_nativebar, should be Array or Hash"; return; } } if (!params) { LOG(ERROR) + "Wrong parameters for create_nativebar"; return; } int size = params->v.array->size; if ( size == 0 ) { removeToolbar(); return; } if ( m_hWnd ) { removeAllButtons(); }else { RECT rcToolbar; rcToolbar.left = 0; rcToolbar.right = 0; rcToolbar.top = 0; rcToolbar.bottom = m_nHeight; Create(getAppWindow().m_hWnd, rcToolbar, NULL, WS_CHILD|CCS_NOPARENTALIGN|CCS_NORESIZE|CCS_NOMOVEY|CCS_BOTTOM|CCS_NODIVIDER | TBSTYLE_FLAT |TBSTYLE_LIST|TBSTYLE_TRANSPARENT ); //TBSTYLE_AUTOSIZE SetButtonStructSize(); } for (int i = 0; i < size; ++i) { rho_param *hash = params->v.array->value[i]; if (hash->type != RHO_PARAM_HASH) { LOG(ERROR) + "Unexpected type of array item for create_nativebar, should be Hash"; return; } const char *label = NULL; const char *action = NULL; const char *icon = NULL; const char *colored_icon = NULL; int nItemWidth = 0; for (int j = 0, lim = hash->v.hash->size; j < lim; ++j) { const char *name = hash->v.hash->name[j]; rho_param *value = hash->v.hash->value[j]; if (value->type != RHO_PARAM_STRING) { LOG(ERROR) + "Unexpected '" + name + "' type, should be String"; return; } if (strcasecmp(name, "label") == 0) label = value->v.string; else if (strcasecmp(name, "action") == 0) action = value->v.string; else if (strcasecmp(name, "icon") == 0) icon = value->v.string; else if (strcasecmp(name, "colored_icon") == 0) colored_icon = value->v.string; else if (strcasecmp(name, "width") == 0) nItemWidth = atoi(value->v.string); } if (label == NULL && bar_type == TOOLBAR_TYPE) label = ""; if ( label == NULL || action == NULL) { LOG(ERROR) + "Illegal argument for create_nativebar"; return; } if ( strcasecmp(action, "forward") == 0 && rho_conf_getBool("jqtouch_mode") ) continue; m_arButtons.addElement( new CToolbarBtn(label, action, icon, nItemWidth) ); } CSize sizeMax = getMaxImageSize(); m_nHeight = max(m_nHeight, sizeMax.cy+MIN_TOOLBAR_IDENT); int nBtnSize = m_nHeight-MIN_TOOLBAR_IDENT; SetButtonSize(max(nBtnSize,sizeMax.cx), max(nBtnSize,sizeMax.cy)); SetBitmapSize(sizeMax.cx, sizeMax.cy); m_listImages.Create(sizeMax.cx, sizeMax.cy, ILC_MASK|ILC_COLOR32, m_arButtons.size(), 0); SetImageList(m_listImages); for ( int i = 0; i < (int)m_arButtons.size(); i++ ) addToolbarButton( *m_arButtons.elementAt(i), i ); AutoSize(); alignSeparatorWidth(); ShowWindow(SW_SHOW); #if defined (OS_WINDOWS) RECT rcWnd; getAppWindow().GetWindowRect(&rcWnd); getAppWindow().SetWindowPos( 0, 0,0,rcWnd.right-rcWnd.left-1,rcWnd.bottom-rcWnd.top, SWP_NOMOVE|SWP_NOZORDER|SWP_FRAMECHANGED); getAppWindow().SetWindowPos( 0, 0,0,rcWnd.right-rcWnd.left,rcWnd.bottom-rcWnd.top, SWP_NOMOVE|SWP_NOZORDER|SWP_FRAMECHANGED); #else getAppWindow().SetWindowPos( 0, 0,0,0,0, SWP_NOMOVE|SWP_NOZORDER|SWP_NOSIZE|SWP_FRAMECHANGED); #endif }