예제 #1
0
/*static*/ void  _CRhoAppAdapter::resetDBOnSyncUserChanged()
{
#ifndef RHO_NO_RUBY_API
    if (rho_ruby_is_started())
        rho_ruby_reset_db_on_sync_user_changed();
#endif
}
예제 #2
0
파일: rhoruby.c 프로젝트: KlearXos/rhodes
VALUE rho_ruby_main_thread()
{
    if (!rho_ruby_is_started())
        return Qnil;

    return rb_thread_main();
}
예제 #3
0
/*static*/ void  _CRhoAppAdapter::loadAllSyncSources()
{
#ifndef RHO_NO_RUBY_API
    if (rho_ruby_is_started())
        rho_ruby_loadallsyncsources();
#endif
}
예제 #4
0
/*static*/ void  _CRhoAppAdapter::loadServerSources(const String& strSources)
{
#ifndef RHO_NO_RUBY_API
    if (rho_ruby_is_started())
        rho_ruby_loadserversources(strSources.c_str());
#endif
}
예제 #5
0
/*static*/ const char* _CRhoAppAdapter::getRhoDBVersion()
{
#ifndef RHO_NO_RUBY_API
    if (rho_ruby_is_started())
	    return rho_ruby_getRhoDBVersion();
    else
#endif
        return "2.2.0";
}
예제 #6
0
파일: rhoruby.c 프로젝트: KlearXos/rhodes
VALUE rho_ruby_current_thread()
{
    if (!rho_ruby_is_started())
        return 0;

    if ( ruby_native_thread_p() != 1 )
        return 0;

    return rb_thread_current();
}
예제 #7
0
extern "C" void Init_ShareExtension_API()
{
#ifndef RHO_NO_RUBY_API
    if (rho_ruby_is_started())
    {
    	Init_RubyAPI_ShareExtension();
    }
#endif

#ifndef RHO_NO_JS_API
    Init_JSAPI_ShareExtension();
#endif
}
예제 #8
0
extern "C" void Init_GenPropBag_API()
{
#ifndef RHO_NO_RUBY_API
    if (rho_ruby_is_started())
    {
    	Init_RubyAPI_GenPropBag();
    }
#endif

#ifndef RHO_NO_JS_API
    Init_JSAPI_GenPropBag();
#endif
}
예제 #9
0
파일: ExtManager.cpp 프로젝트: 4nkh/rhodes
void CExtManager::requireRubyFile( const char* szFilePath )
{
    if( rho_ruby_is_started() )
        rb_require(szFilePath);
}
예제 #10
0
bool CHttpServer::run()
{
    if (verbose) LOG(INFO) + "Start HTTP server";

    if (!init())
    {
        return false;
    }

    m_active = true;

    if (!m_started_as_separated_simple_server)
        RHODESAPP().notifyLocalServerStarted();

    for(;;) 
    {
        if (verbose) RAWTRACE("Waiting for connections...");
#ifndef RHO_NO_RUBY_API
        if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
            rho_ruby_start_threadidle();
#endif
        fd_set readfds;
        FD_ZERO(&readfds);
        FD_SET(m_listener, &readfds);

        timeval tv = {0,0};
        unsigned long nTimeout = RHODESAPP().getTimer().getNextTimeout();
        tv.tv_sec = nTimeout/1000;
        tv.tv_usec = (nTimeout - tv.tv_sec*1000)*1000;
        
        
        int ret = select(m_listener+1, &readfds, NULL, NULL, (tv.tv_sec == 0 && tv.tv_usec == 0 ? 0 : &tv) );
        
        //int errsv = errno;
        
#ifndef RHO_NO_RUBY_API
        if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
            rho_ruby_stop_threadidle();
#endif
        bool bProcessed = false;
        if (ret > 0) 
        {
            if (FD_ISSET(m_listener, &readfds))
            {
                //RAWTRACE("Before accept...");
                SOCKET conn = accept(m_listener, NULL, NULL);
                //RAWTRACE("After accept...");
                if (!m_active) {
                    if (verbose) RAWTRACE("Stop HTTP server");
                    return true;
                }
                if (conn == INVALID_SOCKET) {
        #if !defined(WINDOWS_PLATFORM)
                    if (RHO_NET_ERROR_CODE == EINTR)
                        continue;
        #endif
                    if (verbose) RAWLOG_ERROR1("Can not accept connection: %d", RHO_NET_ERROR_CODE);
                    return false;
                }

                if (verbose) RAWTRACE("Connection accepted, process it...");
                VALUE val;
#ifndef RHO_NO_RUBY_API                
                if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
                {
                    if ( !RHOCONF().getBool("enable_gc_while_request") )                
                        val = rho_ruby_disable_gc();
                }
#endif
                m_sock = conn;
                bProcessed = process(m_sock);
#ifndef RHO_NO_RUBY_API
                if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
                {
                    if ( !RHOCONF().getBool("enable_gc_while_request") )
                        rho_ruby_enable_gc(val);
                }
#endif
                if (verbose) RAWTRACE("Close connected socket");
                closesocket(m_sock);
                m_sock = INVALID_SOCKET;
            }
        }
        else if ( ret == 0 ) //timeout
        {
            bProcessed = RHODESAPP().getTimer().checkTimers();
        }
        else
        {
            if (verbose) RAWLOG_ERROR1("HTTP Server select error: %d", ret);
            continue;
            //return false;
        }
#ifndef RHO_NO_RUBY_API
        if (rho_ruby_is_started() && (!m_started_as_separated_simple_server))
        {
            if ( bProcessed )
            {
                if (verbose) {
                    LOG(INFO) + "GC Start.";
                }
                rb_gc();
                if (verbose) {
                    LOG(INFO) + "GC End.";
                }
            }
        }
#endif
    }
}
예제 #11
0
bool CDirectHttpRequestQueue::run( )
{
  m_server.m_pQueue = this;
  m_server.m_active = true;
  RHODESAPP().notifyLocalServerStarted();
  
  do
  {
      
      if (rho_ruby_is_started() ) {
          rho_ruby_start_threadidle();
      }
      
     m_thread.wait(-1);

      
      if (rho_ruby_is_started() ) {
          rho_ruby_stop_threadidle();
      }
      
    m_response = "";
    
    if ( m_request != 0 )
    {
      CHttpServer::ResponseWriter respWriter;
      m_server.m_localResponseWriter = &respWriter;
      
#ifndef RHO_NO_RUBY_API
      VALUE val;
      if (rho_ruby_is_started())
      {
        if ( !RHOCONF().getBool("enable_gc_while_request") )
        {
          val = rho_ruby_disable_gc();
        }
      }
#endif
      
      bool bProcessed = m_server.decide(
                                        m_request->method,
                                        m_request->uri,
                                        m_request->query,
                                        m_request->headers,
                                        m_request->body
                                        );
      
#ifndef RHO_NO_RUBY_API
      if (rho_ruby_is_started())
      {
        if ( !RHOCONF().getBool("enable_gc_while_request") )
        {
          rho_ruby_enable_gc(val);
        }
        
        if ( bProcessed )
        {
          LOG(INFO) + "GC Start.";
          rb_gc();
          LOG(INFO) + "GC End.";
        }
      }
#endif
      
      m_server.m_localResponseWriter = 0;
      
      m_response = respWriter.getResponse();
      
      pthread_cond_t* signal = m_request->signal;
      pthread_mutex_t* mutex = m_request->mutex;
      
      m_request->clear();
      m_request = 0;

      if ( (signal != 0) && (mutex!=0) )
      {
        pthread_mutex_lock(mutex);
        pthread_cond_signal(signal);
        pthread_mutex_unlock(mutex);
      }
    }
  }while (m_server.m_active);
  
  return true;
}
예제 #12
0
bool CHttpServer::decide(String const &method, String const &arg_uri, String const &query,
                         HeaderList const &headers, String const &body/*, IResponseSender& respSender*/ )
{
    if (verbose) RAWTRACE1("Decide what to do with uri %s", arg_uri.c_str());
    callback_t callback = registered(arg_uri);
    if (callback) {
        if (verbose) RAWTRACE1("Uri %s is registered callback, so handle it appropriately", arg_uri.c_str());

        if ( callback == rho_http_ruby_proc_callback )
            call_ruby_proc( query, body );
        else
            callback(this, query.length() ? query : body);

        return false;
    }

    String uri = arg_uri;

    String fullPath = CFilePath::join(m_root, uri);
#ifndef RHO_NO_RUBY_API    
    if (rho_ruby_is_started())
    {
        Route route;
        if (dispatch(uri, route)) {
            if (verbose) RAWTRACE1("Uri %s is correct route, so enable MVC logic", uri.c_str());
            
            VALUE req = create_request_hash(route.application, route.model, route.action, route.id,
                                            method, uri, query, headers, body);
            VALUE data = callFramework(req);
            String reply(getStringFromValue(data), getStringLenFromValue(data));
            rho_ruby_releaseValue(data);

            bool isRedirect = String_startsWith(reply, "HTTP/1.1 301") ||
                              String_startsWith(reply, "HTTP/1.1 302");

            if (!send_response(reply, isRedirect))
                return false;

            if (method == "GET")
                rho_rhodesapp_keeplastvisitedurl(uri.c_str());

		    if ( sync::RhoconnectClientManager::haveRhoconnectClientImpl() ) {

			    if (!route.id.empty()) {
				    sync::RhoconnectClientManager::rho_sync_addobjectnotify_bysrcname(route.model.c_str(), route.id.c_str());
			    }			
		    }
            
            return true;
        }
        
        if (isdir(fullPath)) {
            if (verbose) RAWTRACE1("Uri %s is directory, redirecting to index", uri.c_str());
            String q = query.empty() ? "" : "?" + query;
            
            HeaderList headers;
            headers.push_back(Header("Location", CFilePath::join( uri, "index" RHO_ERB_EXT) + q));
            
            send_response(create_response("301 Moved Permanently", headers), true);
            return false;
        }

        if (isindex(uri)) {
            if (!isfile(fullPath)) {
                if (verbose) RAWLOG_ERROR1("The file %s was not found", fullPath.c_str());
                String error = "<!DOCTYPE html><html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                send_response(create_response("404 Not Found",error));
                return false;
            }
            
            if (verbose) RAWTRACE1("Uri %s is index file, call serveIndex", uri.c_str());

            VALUE req = create_request_hash(route.application, route.model, route.action, route.id,
                                            method, uri, query, headers, body);

            VALUE data = callServeIndex((char *)fullPath.c_str(), req);
            String reply(getStringFromValue(data), getStringLenFromValue(data));
            rho_ruby_releaseValue(data);

            if (!send_response(reply))
                return false;

            if (method == "GET")
                rho_rhodesapp_keeplastvisitedurl(uri.c_str());

            return true;
        }
    }
#endif
    // Try to send requested file
    if (verbose) RAWTRACE1("Uri %s should be regular file, trying to send it", uri.c_str());

    PROF_START("READ_FILE");
    bool bRes = send_file(uri, headers);
    PROF_STOP("READ_FILE");

    return bRes;
}