Exemplo n.º 1
0
void *start_validator_nofree(char *name, void *handle, webs_t wp, char *value, struct variable *v)
{
	// lcdmessaged("Starting Service",name);
	cprintf("start_service_nofree %s\n", name);
	char service[64];
	int nohandle = 0;

	if (!handle) {
		handle = load_service(name);
		nohandle = 1;
	}
	if (handle == NULL) {
		return NULL;
	}
	void (*fptr) (webs_t wp, char *value, struct variable * v);

	sprintf(service, "%s", name);
	if (nohandle) {
		if (initWeb(handle) != 0) {
			return handle;
		}
	}
	cprintf("resolving %s\n", service);
	fptr = (void (*)(webs_t wp, char *value, struct variable * v))
	    dlsym(handle, service);
	cprintf("found. pointer is %p\n", fptr);
	if (fptr)
		(*fptr) (wp, value, v);
	else if (nvram_match("console_debug", "1"))
		fprintf(stderr, "function %s not found \n", service);
	cprintf("start_sevice_nofree done()\n");
	return handle;
}
Exemplo n.º 2
0
void start_gozila(char *name, webs_t wp)
{
	// lcdmessaged("Starting Service",name);
	cprintf("start_gozila %s\n", name);
	char service[64];
	int init = 0;
	if (!s_service) {
		init = 1;
		s_service = load_service(name);
	}
	if (s_service == NULL) {
		return;
	}
	if (init) {
		if (initWeb(s_service) != 0) {
			return;
		}
	}

	int (*fptr) (webs_t wp);

	sprintf(service, "%s", name);
	cprintf("resolving %s\n", service);
	fptr = (int (*)(webs_t wp))dlsym(s_service, service);
	if (fptr)
		(*fptr) (wp);
	else if (nvram_match("console_debug", "1"))
		fprintf(stderr, "function %s not found \n", service);
#ifndef MEMLEAK_OVERRIDE
	dlclose(s_service);
	s_service = NULL;
#endif
	cprintf("start_sevice done()\n");
}
Exemplo n.º 3
0
int __stdcall start(int state)
{
     int p;
     int i;

     int scrnsize;
     int scrnbpp;
     int scrnpitch;

     if( !test_mmx())
        return FALSE;

     if( (scrnbpp = GetScreenBpp()) != 32)
        return FALSE;

     scrnsize  = GetScreenSize();
     scrnpitch = GetScreenPitch();

     scrn_clip.xmin = 0;
     scrn_clip.ymin = 0;
     scrn_clip.xmax = (scrnsize >> 16) - 1;
     scrn_clip.ymax = (scrnsize & 0xFFFF) - 1;

     scrn_pixmap.width   = scrnsize >> 16;
     scrn_pixmap.height  = scrnsize & 0xFFFF;
     scrn_pixmap.format  = PICT_a8r8g8b8;
     scrn_pixmap.flags   = PX_MEM_LOCAL;
     scrn_pixmap.pitch   = scrnpitch;
     scrn_pixmap.mapped  = (void*)LFB_BASE;

     br_slab.available = 256;
     br_slab.start = brushes;
     br_slab.nextavail = brushes;

     for (i = 0, p = (int)br_slab.start; i < 256; i++)
     {
       *(int *)p = p+sizeof(brush_t);
       p = p+sizeof(brush_t);
     };

     px_slab.available = 64;
     px_slab.start = pixmaps;
     px_slab.nextavail = pixmaps;

     for (i = 0, p = (int)px_slab.start; i < 64; i++)
     {
       *(int *)p = p+sizeof(pixmap_t);
       p = p+sizeof(pixmap_t);
     };

     srv_hw2d = get_service("HDRAW");
       if(srv_hw2d == 0)
         srv_hw2d = load_service("/rd/1/drivers/ati2d.drv");

     return TRUE;
};
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
    L = luaL_newstate();
    luaL_openlibs(L);

    const char *cfg_file_name = "config.cfg";
    if (argc > 1)
        cfg_file_name = argv[1];
    if (read_config(L, cfg_file_name) != 0) {
        fprintf(stderr, "config read failed %s", lua_tostring(L, -1));
        return -1;
    }

    EV_Base = event_base_new();
    init_network(L, EV_Base);
    preload(L);
    load_service(L);

    event_base_dispatch(EV_Base);
    lua_close(L);
    return 0;
}
Exemplo n.º 5
0
int start_validator(char *name, webs_t wp, char *value, struct variable *v)
{
	// lcdmessaged("Starting Service",name);
	cprintf("start_validator %s\n", name);
	char service[64];
	int init = 0;
	if (!s_service) {
		s_service = load_service(name);
		init = 1;
	}
	if (s_service == NULL) {
		return FALSE;
	}
	if (init) {
		if (initWeb(s_service) != 0) {
			return FALSE;
		}
	}
	int ret = FALSE;

	int (*fptr) (webs_t wp, char *value, struct variable * v);

	sprintf(service, "%s", name);
	cprintf("resolving %s\n", service);
	fptr = (int (*)(webs_t wp, char *value, struct variable * v))
	    dlsym(s_service, service);
	if (fptr)
		ret = (*fptr) (wp, value, v);
	else if (nvram_match("console_debug", "1"))
		fprintf(stderr, "function %s not found \n", service);
#ifndef MEMLEAK_OVERRIDE
	dlclose(s_service);
	s_service = NULL;
#endif

	cprintf("start_sevice done()\n");
	return ret;
}
Exemplo n.º 6
0
void plugin_server::load_service_config(const std::string& config_name)
{
    std::string config_file;
    if (! plugin::find_config_file(config_file, config_name))
        BOOST_THROW_EXCEPTION( error::file_not_found() << error::errinfo_file_name(config_name) );
    
    // open the file for reading
    std::ifstream config_stream;
    config_stream.open(config_file.c_str(), std::ios::in);
    if (! config_stream.is_open())
        BOOST_THROW_EXCEPTION( error::open_file() << error::errinfo_file_name(config_name) );
    
    // parse the contents of the file
    http::auth_ptr my_auth_ptr;
    enum ParseState {
        PARSE_NEWLINE, PARSE_COMMAND, PARSE_RESOURCE, PARSE_VALUE, PARSE_COMMENT, PARSE_USERNAME
    } parse_state = PARSE_NEWLINE;
    std::string command_string;
    std::string resource_string;
    std::string username_string;
    std::string value_string;
    std::string option_name_string;
    std::string option_value_string;
    int c = config_stream.get();    // read the first character
    
    while (config_stream) {
        switch(parse_state) {
        case PARSE_NEWLINE:
            // parsing command portion (or beginning of line)
            if (c == '#') {
                // line is a comment
                parse_state = PARSE_COMMENT;
            } else if (isalpha(c)) {
                // first char in command
                parse_state = PARSE_COMMAND;
                // ignore case for commands
                command_string += tolower(c);
            } else if (c != '\r' && c != '\n') {    // check for blank lines
                BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
            }
            break;
            
        case PARSE_COMMAND:
            // parsing command portion (or beginning of line)
            if (c == ' ' || c == '\t') {
                // command finished -> check if valid
                if (command_string=="path" || command_string=="auth" || command_string=="restrict") {
                    value_string.clear();
                    parse_state = PARSE_VALUE;
                } else if (command_string=="service" || command_string=="option") {
                    resource_string.clear();
                    parse_state = PARSE_RESOURCE;
                } else if (command_string=="user") {
                    username_string.clear();
                    parse_state = PARSE_USERNAME;
                } else {
                    BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                }
            } else if (! isalpha(c)) {
                // commands may only contain alpha chars
                BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
            } else {
                // ignore case for commands
                command_string += tolower(c);
            }
            break;

        case PARSE_RESOURCE:
            // parsing resource portion (/hello)
            if (c == ' ' || c == '\t') {
                // check for leading whitespace
                if (! resource_string.empty()) {
                    // resource finished
                    value_string.clear();
                    parse_state = PARSE_VALUE;
                }
            } else if (c == '\r' || c == '\n') {
                // line truncated before value
                BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
            } else {
                // add char to resource
                resource_string += c;
            }
            break;
        
        case PARSE_USERNAME:
            // parsing username for user command
            if (c == ' ' || c == '\t') {
                // check for leading whitespace
                if (! username_string.empty()) {
                    // username finished
                    value_string.clear();
                    parse_state = PARSE_VALUE;
                }
            } else if (c == '\r' || c == '\n') {
                // line truncated before value (missing username)
                BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
            } else {
                // add char to username
                username_string += c;
            }
            break;
        
        case PARSE_VALUE:
            // parsing value portion
            if (c == '\r' || c == '\n') {
                // value is finished
                if (value_string.empty()) {
                    // value must not be empty
                    BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                } else if (command_string == "path") {
                    // finished path command
                    try { plugin::add_plugin_directory(value_string); }
                    catch (std::exception& e) {
                        PION_LOG_WARN(m_logger, boost::diagnostic_information(e));
                    }
                } else if (command_string == "auth") {
                    // finished auth command
                    user_manager_ptr user_mgr(new user_manager);
                    if (value_string == "basic"){
                        my_auth_ptr.reset(new http::basic_auth(user_mgr));
                    }
                    else if (value_string == "cookie"){
                        my_auth_ptr.reset(new http::cookie_auth(user_mgr));
                    }
                    else {
                        // only basic and cookie authentications are supported
                        BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                    }
                } else if (command_string == "restrict") {
                    // finished restrict command
                    if (! my_auth_ptr)
                        // Authentication type must be defined before restrict
                        BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                    else if (value_string.empty())
                        // No service defined for restrict parameter
                        BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                    my_auth_ptr->add_restrict(value_string);
                } else if (command_string == "user") {
                    // finished user command
                    if (! my_auth_ptr)
                        // Authentication type must be defined before users
                        BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                    else if (value_string.empty())
                        // No password defined for user parameter
                        BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                    my_auth_ptr->add_user(username_string, value_string);
                } else if (command_string == "service") {
                    // finished service command
                    load_service(resource_string, value_string);
                } else if (command_string == "option") {
                    // finished option command
                    std::string::size_type pos = value_string.find('=');
                    if (pos == std::string::npos)
                        BOOST_THROW_EXCEPTION( error::bad_config() << error::errinfo_file_name(config_name) );
                    option_name_string = value_string.substr(0, pos);
                    option_value_string = value_string.substr(pos + 1);
                    set_service_option(resource_string, option_name_string,
                                     option_value_string);
                }
                command_string.clear();
                parse_state = PARSE_NEWLINE;
            } else if (c == ' ' || c == '\t') {
                // only skip leading whitespace (value may contain spaces, etc)
                if (! value_string.empty())
                    value_string += c;
            } else {
                // add char to value
                value_string += c;
            }
            break;
        
        case PARSE_COMMENT:
            // skipping comment line
            if (c == '\r' || c == '\n')
                parse_state = PARSE_NEWLINE;
            break;
        }

        // read the next character
        c = config_stream.get();
    }
    
    // update authentication configuration for the server
    set_authentication(my_auth_ptr);
}