void pop() {
   size_type current = head[bucket_id];
   size_type next_node = next[current];
   head[bucket_id] = next_node;
   if ( next_node != invalid_value() )
     prev[next_node] = invalid_value();
 }
 bucket_sorter(size_type _length, bucket_type _max_bucket, 
               const Bucket& _bucket = Bucket(), 
               const ValueIndexMap& _id = ValueIndexMap()) 
   : head(_max_bucket, invalid_value()),
     next(_length, invalid_value()), 
     prev(_length, invalid_value()),
     id_to_value(_length),
     bucket(_bucket), id(_id) { }
 void push(const value_type& x) {
   const size_type new_head = id[x];
   const size_type current = head[bucket_id];
   if ( current != invalid_value() )
     prev[current] = new_head;
   prev[new_head] = invalid_value();
   next[new_head] = current;
   head[bucket_id] = new_head;
 }
 void remove(const value_type& x) {
   const size_type i = id[x];
   const size_type& next_node = next[i];
   const size_type& prev_node = prev[i];
 
   //check if i is the end of the bucket list 
   if ( next_node != invalid_value() )
     prev[next_node] = prev_node; 
   //check if i is the begin of the bucket list
   if ( prev_node != invalid_value() )
     next[prev_node] = next_node;
   else //need update head of current bucket list
     head[ bucket[x] ] = next_node;
 }
Esempio n. 5
0
void LocationsMgr::add_szbase( const std::string& name , const CfgPairs& cfg )
{
	auto draw_name = cfg.count("draw_name") ?  cfg.at("draw_name") : name;

	try {
		auto& vars = vars_cache.get_szarp( cfg.at("base") );

		loc_factory.register_location<SzbaseLocation>(
				name , draw_name , "szbase" , std::ref(vars) );
	} catch( file_not_found_error& e ) {
		throw invalid_value( e.what() );
	} catch( xml_parse_error& e ) {
		throw invalid_value( e.what() );
	}
}
Esempio n. 6
0
      /** @brief Trows exceptions that reflect OpenCL error codes */
      static void raise_exception(cl_int err)
      {
        switch (err)
        {
          case CL_DEVICE_NOT_FOUND:               throw device_not_found();
          case CL_DEVICE_NOT_AVAILABLE:           throw device_not_available();
          case CL_COMPILER_NOT_AVAILABLE:         throw compiler_not_available();
          case CL_MEM_OBJECT_ALLOCATION_FAILURE:  throw mem_object_allocation_failure();
          case CL_OUT_OF_RESOURCES:               throw out_of_resources();
          case CL_OUT_OF_HOST_MEMORY:             throw out_of_host_memory();
          case CL_PROFILING_INFO_NOT_AVAILABLE:   throw profiling_info_not_available();
          case CL_MEM_COPY_OVERLAP:               throw mem_copy_overlap();
          case CL_IMAGE_FORMAT_MISMATCH:          throw image_format_mismatch();
          case CL_IMAGE_FORMAT_NOT_SUPPORTED:     throw image_format_not_supported();
          case CL_BUILD_PROGRAM_FAILURE:          throw build_program_failure();
          case CL_MAP_FAILURE:                    throw map_failure();

          case CL_INVALID_VALUE:                  throw invalid_value();
          case CL_INVALID_DEVICE_TYPE:            throw invalid_device_type();
          case CL_INVALID_PLATFORM:               throw invalid_platform();
          case CL_INVALID_DEVICE:                 throw invalid_device();
          case CL_INVALID_CONTEXT:                throw invalid_context();
          case CL_INVALID_QUEUE_PROPERTIES:       throw invalid_queue_properties();
          case CL_INVALID_COMMAND_QUEUE:          throw invalid_command_queue();
          case CL_INVALID_HOST_PTR:               throw invalid_host_ptr();
          case CL_INVALID_MEM_OBJECT:             throw invalid_mem_object();
          case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR: throw invalid_image_format_descriptor();
          case CL_INVALID_IMAGE_SIZE:             throw invalid_image_size();
          case CL_INVALID_SAMPLER:                throw invalid_sampler();
          case CL_INVALID_BINARY:                 throw invalid_binary();
          case CL_INVALID_BUILD_OPTIONS:          throw invalid_build_options();
          case CL_INVALID_PROGRAM:                throw invalid_program();
          case CL_INVALID_PROGRAM_EXECUTABLE:     throw invalid_program_executable();
          case CL_INVALID_KERNEL_NAME:            throw invalid_kernel_name();
          case CL_INVALID_KERNEL_DEFINITION:      throw invalid_kernel_definition();
          case CL_INVALID_KERNEL:                 throw invalid_kernel();
          case CL_INVALID_ARG_INDEX:              throw invalid_arg_index();
          case CL_INVALID_ARG_VALUE:              throw invalid_arg_value();
          case CL_INVALID_ARG_SIZE:               throw invalid_arg_size();
          case CL_INVALID_KERNEL_ARGS:            throw invalid_kernel_args();
          case CL_INVALID_WORK_DIMENSION:         throw invalid_work_dimension();
          case CL_INVALID_WORK_GROUP_SIZE:        throw invalid_work_group_size();
          case CL_INVALID_WORK_ITEM_SIZE:         throw invalid_work_item_size();
          case CL_INVALID_GLOBAL_OFFSET:          throw invalid_global_offset();
          case CL_INVALID_EVENT_WAIT_LIST:        throw invalid_event_wait_list();
          case CL_INVALID_EVENT:                  throw invalid_event();
          case CL_INVALID_OPERATION:              throw invalid_operation();
          case CL_INVALID_GL_OBJECT:              throw invalid_gl_object();
          case CL_INVALID_BUFFER_SIZE:            throw invalid_buffer_size();
          case CL_INVALID_MIP_LEVEL:              throw invalid_mip_level();
          case CL_INVALID_GLOBAL_WORK_SIZE:       throw invalid_global_work_size();
      #ifdef CL_INVALID_PROPERTY
    case CL_INVALID_PROPERTY:               throw invalid_property();
      #endif
          //  return "CL_INVALID_GLOBAL_WORK_SIZE";

          default: throw unknown_error();
        }

      } //getErrorString
 void set_upper_bound_x(double y) {
     if(!(y > lo_y)) {
         throw invalid_value("new upper bound must satisfy upper > lower. "
                             "set lower bound first.");
     }
     hi_y = y;
 }
 void set_lower_bound_y(double y) {
     if(!(y < hi_y)) {
         throw invalid_value("new lower bound must satistfy lower < upper. "
                             "set upper bound first.");
     }
     hi_y = y;
 }
 void set_upper_bound_x(double x) {
     if(!(x > lo_x)) {
         throw invalid_value("new upper bound must satisfy upper > lower. "
                             "set lower bound first.");
     }
     hi_x = x;
 }
 void set_lower_bound_x(double x) {
     if(!(x < hi_x)) {
         throw invalid_value("new lower bound must satisfy lower < upper. "
                             "set upper bound first.");
     }
     lo_x = x;
 }
Esempio n. 11
0
void invalid_value::throw_(const char* file, std::size_t line, std::string const& descr)
{
    boost::throw_exception(boost::enable_error_info(invalid_value(descr))
        << boost::throw_file(file)
        << boost::throw_line(line)
    );
}
Esempio n. 12
0
    /** 
     * Reclaims ownership of the native file handle. 
     * 
     * Explicitly reclaims ownership of the native file handle contained 
     * in the \a file_handle object, returning the native file handle. 
     * The caller is responsible of closing it later on. 
     * 
     * \pre The file handle is valid. 
     * \post The file handle is invalid. 
     * \return The native file handle. 
     */ 
    handle_type release() 
    { 
        BOOST_ASSERT(valid()); 

        handle_type h = handle_; 
        handle_ = invalid_value(); 
        return h; 
    } 
Esempio n. 13
0
impl::file_handle&
impl::file_handle::operator=(const file_handle& fh)
{
    m_handle = fh.m_handle;
    fh.m_handle = invalid_value();

    return *this;
}
Esempio n. 14
0
impl::file_handle::handle_type
impl::file_handle::disown(void)
{
    PRE(is_valid());

    handle_type h = m_handle;
    m_handle = invalid_value();
    return h;
}
Esempio n. 15
0
void
impl::file_handle::close(void)
{
    PRE(is_valid());

    ::close(m_handle);

    m_handle = invalid_value();
}
Esempio n. 16
0
bool yes_no(const std::string &v)
{
	if (v == "yes")
		return true;
	else if (v == "no")
		return false;
	else
		invalid_value(v);
}
Esempio n. 17
0
    /** 
     * Closes the file handle. 
     * 
     * Explicitly closes the file handle, which must be valid. Upon 
     * exit, the handle is not valid any more. 
     * 
     * \pre The file handle is valid. 
     * \post The file handle is invalid. 
     * \post The native file handle is closed. 
     */ 
    void close() 
    { 
        BOOST_ASSERT(valid()); 

#if defined(BOOST_POSIX_API) 
        ::close(handle_); 
#elif defined(BOOST_WINDOWS_API) 
        ::CloseHandle(handle_); 
#endif 

        handle_ = invalid_value(); 
    } 
Esempio n. 18
0
void LocationsMgr::add_location( const std::string& name , const CfgPairs& cfg )
{
	try {
		if( cfg.at("type") == "szbase" )
			add_szbase( name , cfg );
		else if( cfg.at("type") == "proxy" )
			add_proxy( name , cfg );
		else
			throw invalid_value("Invalid 'type' in section " + name );
	} catch( std::out_of_range& e ) {
		throw missing_option("Missing option in section " + name );
	}
}
Esempio n. 19
0
void LocationsMgr::add_szbase( const std::string& name , const CfgPairs& cfg )
{
	auto pa = cfg.count("prober_address") ? cfg.at("prober_address") : "127.0.0.1";
	auto pp = cfg.count("prober_port")    ? cfg.at("prober_port")    : "8090";
	auto draw_name = cfg.count("draw_name") ?  cfg.at("draw_name") : name;

	unsigned p;
	try {
		p = boost::lexical_cast<unsigned>(pp);
	} catch( boost::bad_lexical_cast& e ) {
		throw invalid_value("Invalid port number in section " + name );
	}

	try {
		auto& vars = vars_cache.get_szarp( cfg.at("base") );

		loc_factory.register_location<SzbaseLocation>(
				name , draw_name , "szbase" , std::ref(vars) );
	} catch( file_not_found_error& e ) {
		throw invalid_value( e.what() );
	} catch( xml_parse_error& e ) {
		throw invalid_value( e.what() );
	}
}
Esempio n. 20
0
void LocationsMgr::add_proxy( const std::string& name , const CfgPairs& cfg )
{
	unsigned port;
	try {
		port = boost::lexical_cast<unsigned>(cfg.at("port"));
	} catch( boost::bad_lexical_cast& e ) {
		throw invalid_value("Invalid port number in section " + name );
	} catch( std::out_of_range& e ) {
		port = 9002;
	}

	auto draw_name = cfg.count("draw_name") ?  cfg.at("draw_name") : "";

	auto updater = std::make_shared
		<RemotesUpdater>( name , draw_name , cfg.at("address") , port , loc_factory );

	updater->connect();

	updaters[ name ] = updater;
}
Esempio n. 21
0
impl::file_handle::file_handle(void) :
    m_handle(invalid_value())
{
}
Esempio n. 22
0
/*
 *----------------------------------------------------------------------
 *
 * fcgi_config_set_config --
 *
 *      Implements the FastCGI FCGIConfig configuration directive.
 *      This command adds routines to control the execution of the
 *      dynamic FastCGI processes.
 *
 *
 *----------------------------------------------------------------------
 */
const char *fcgi_config_set_config(cmd_parms *cmd, void *dummy, const char *arg)
{
    pool * const p = cmd->pool;
    pool * const tp = cmd->temp_pool;
    const char *err, *option;
    const char * const name = cmd->cmd->name;

    /* Allocate temp storage for an initial environment */
    unsigned int envc = 0;
    char **envp = (char **)ap_pcalloc(tp, sizeof(char *) * (MAX_INIT_ENV_VARS + 3));

    err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
    if (err)
    {
        return err;
    }

    /* Parse the directive arguments */
    while (*arg) {
        option = ap_getword_conf(tp, &arg);

        if (strcasecmp(option, "-maxProcesses") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicMaxProcs, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-minProcesses") == 0) {
            if ((err = get_int(tp, &arg, &dynamicMinProcs, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-maxClassProcesses") == 0) {
            if ((err = get_int(tp, &arg, &dynamicMaxClassProcs, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-killInterval") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicKillInterval, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-updateInterval") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicUpdateInterval, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-gainValue") == 0) {
            if ((err = get_float(tp, &arg, &dynamicGain, 0.0, 1.0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if ((strcasecmp(option, "-singleThreshold") == 0)
		    || (strcasecmp(option, "-singleThreshhold") == 0)) 
        {
            if ((err = get_int(tp, &arg, &dynamicThreshold1, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if ((strcasecmp(option, "-multiThreshold") == 0)
		    || (strcasecmp(option, "-multiThreshhold") == 0)) 
        {
            if ((err = get_int(tp, &arg, &dynamicThresholdN, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-startDelay") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicPleaseStartDelay, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-initial-env") == 0) {
            if ((err = get_env_var(p, &arg, envp, &envc)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-pass-header") == 0) {
            if ((err = get_pass_header(p, &arg, &dynamic_pass_headers)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-appConnTimeout") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicAppConnectTimeout, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-idle-timeout") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamic_idle_timeout, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-listen-queue-depth") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicListenQueueDepth, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-min-server-life") == 0) {
            if ((err = get_int(tp, &arg, &dynamicMinServerLife, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-restart-delay") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicRestartDelay, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-init-start-delay") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicInitStartDelay, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-processSlack") == 0) {
            if ((err = get_u_int(tp, &arg, &dynamicProcessSlack, 1)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-restart") == 0) {
            dynamicAutoRestart = 1;
        }
        else if (strcasecmp(option, "-autoUpdate") == 0) {
            dynamicAutoUpdate = 1;
		}
        else if (strcasecmp(option, "-flush") == 0) {
            dynamicFlush = TRUE;
        }
        else {
            return ap_psprintf(tp, "%s: invalid option: %s", name, option);
        }
    } /* while */

    if (dynamicProcessSlack >= dynamicMaxProcs + 1) {
	    /* the kill policy would work unexpectedly */
    	return ap_psprintf(tp, 
            "%s: processSlack (%u) must be less than maxProcesses (%u) + 1", 
        	name, dynamicProcessSlack, dynamicMaxProcs);
    }

    /* Move env array to a surviving pool, leave 2 extra slots for 
     * WIN32 _FCGI_MUTEX_ and _FCGI_SHUTDOWN_EVENT_ */
    dynamicEnvp = (char **)ap_pcalloc(p, sizeof(char *) * (envc + 4));
    memcpy(dynamicEnvp, envp, sizeof(char *) * envc);

    return NULL;
}
Esempio n. 23
0
/*******************************************************************************
 * Configure a static FastCGI server.
 */
const char *fcgi_config_new_static_server(cmd_parms *cmd, void *dummy, const char *arg)
{
    fcgi_server *s;
    pool *p = cmd->pool, *tp = cmd->temp_pool;
    const char *name = cmd->cmd->name;
    char *fs_path = ap_getword_conf(p, &arg);
    const char *option, *err;

    /* Allocate temp storage for the array of initial environment variables */
    char **envp = ap_pcalloc(tp, sizeof(char *) * (MAX_INIT_ENV_VARS + 3));
    unsigned int envc = 0;

#ifdef WIN32
    HANDLE mutex;
#endif

    err = ap_check_cmd_context(cmd, NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE);
    if (err)
    {
        return err;
    }

    if (*fs_path == '\0')
        return "AppClass requires a pathname!?";

    if ((err = fcgi_config_set_fcgi_uid_n_gid(1)) != NULL)
        return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);

#ifdef APACHE2
    if (apr_filepath_merge(&fs_path, "", fs_path, 0, p))
        return ap_psprintf(tp, "%s %s: invalid filepath", name, fs_path);
#else
    fs_path = ap_os_canonical_filename(p, fs_path);
#endif
    fs_path = ap_server_root_relative(p, fs_path);

    ap_getparents(fs_path);
    ap_no2slash(fs_path);

    /* See if we've already got one of these configured */
    s = fcgi_util_fs_get_by_id(fs_path, fcgi_util_get_server_uid(cmd->server),
                               fcgi_util_get_server_gid(cmd->server));
    if (s != NULL) {
        if (fcgi_wrapper) {
            return ap_psprintf(tp,
                "%s: redefinition of a previously defined FastCGI "
                "server \"%s\" with uid=%ld and gid=%ld",
                name, fs_path, (long) fcgi_util_get_server_uid(cmd->server),
                (long) fcgi_util_get_server_gid(cmd->server));
        }
        else {
            return ap_psprintf(tp,
                "%s: redefinition of a previously defined FastCGI server \"%s\"",
                name, fs_path);
        }
    }

    err = fcgi_util_fs_is_path_ok(tp, fs_path, NULL);
    if (err != NULL) {
        return ap_psprintf(tp, "%s: \"%s\" %s", name, fs_path, err);
    }

    s = fcgi_util_fs_new(p);
    s->fs_path = fs_path;
    s->directive = APP_CLASS_STANDARD;
    s->restartOnExit = TRUE;
    s->numProcesses = 1;

#ifdef WIN32

    /* TCP FastCGI applications require SystemRoot be present in the environment
     * Put it in both for consistency to the application */
    fcgi_config_set_env_var(p, envp, &envc, "SystemRoot");

    mutex = CreateMutex(NULL, FALSE, fs_path);
    
    if (mutex == NULL)
    {
        ap_log_error(FCGI_LOG_ALERT, fcgi_apache_main_server,
            "FastCGI: CreateMutex() failed");
        return "failed to create FastCGI application accept mutex";
    }
    
    SetHandleInformation(mutex, HANDLE_FLAG_INHERIT, TRUE);

    s->mutex_env_string = ap_psprintf(p, "_FCGI_MUTEX_=%ld", mutex);

#endif

    /*  Parse directive arguments */
    while (*arg) {
        option = ap_getword_conf(tp, &arg);

        if (strcasecmp(option, "-processes") == 0) {
            if ((err = get_u_int(tp, &arg, &s->numProcesses, 1)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-restart-delay") == 0) {
            if ((err = get_u_int(tp, &arg, &s->restartDelay, 0)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-init-start-delay") == 0) {
            if ((err = get_int(tp, &arg, &s->initStartDelay, 0)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-min-server-life") == 0) {
            if ((err = get_u_int(tp, &arg, &s->minServerLife, 0)))
                return invalid_value(tp, name, NULL, option, err);
        }
        else if (strcasecmp(option, "-priority") == 0) {
            if ((err = get_u_int(tp, &arg, &s->processPriority, 0)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-listen-queue-depth") == 0) {
            if ((err = get_u_int(tp, &arg, &s->listenQueueDepth, 1)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-appConnTimeout") == 0) {
            if ((err = get_u_int(tp, &arg, &s->appConnectTimeout, 0)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-idle-timeout") == 0) {
            if ((err = get_u_int(tp, &arg, &s->idle_timeout, 1)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-port") == 0) {
            if ((err = get_u_short(tp, &arg, &s->port, 1)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-socket") == 0) {
            s->socket_path = ap_getword_conf(tp, &arg);
            if (*s->socket_path == '\0')
                return invalid_value(tp, name, fs_path, option, "\"\"");
        }
        else if (strcasecmp(option, "-initial-env") == 0) {
            if ((err = get_env_var(p, &arg, envp, &envc)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-pass-header") == 0) {
            if ((err = get_pass_header(p, &arg, &s->pass_headers)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-flush") == 0) {
            s->flush = 1;
        }
        else if (strcasecmp(option, "-nph") == 0) {
            s->nph = 1;
        }
        else if (strcasecmp(option, "-user") == 0) {
#ifdef WIN32
            return ap_psprintf(tp, 
                "%s %s: the -user option isn't supported on WIN", name, fs_path);
#else
            s->user = ap_getword_conf(tp, &arg);
            if (*s->user == '\0')
                return invalid_value(tp, name, fs_path, option, "\"\"");
#endif
        }
        else if (strcasecmp(option, "-group") == 0) {
#ifdef WIN32
            return ap_psprintf(tp, 
                "%s %s: the -group option isn't supported on WIN", name, fs_path);
#else
            s->group = ap_getword_conf(tp, &arg);
            if (*s->group == '\0')
                return invalid_value(tp, name, fs_path, option, "\"\"");
#endif
        }
        else {
            return ap_psprintf(tp, "%s %s: invalid option: %s", name, fs_path, option);
        }
    } /* while */

#ifndef WIN32
    if (fcgi_wrapper)
    {
        if (s->group == NULL)
        {
            s->group = ap_psprintf(tp, "#%ld", (long)fcgi_util_get_server_gid(cmd->server));
        }

        if (s->user == NULL)
        {
            s->user = ap_psprintf(p, "#%ld", (long)fcgi_util_get_server_uid(cmd->server)); 
        }

        s->uid = ap_uname2id(s->user);
        s->gid = ap_gname2id(s->group);
    }
    else if (s->user || s->group)
    {
        ap_log_error(FCGI_LOG_WARN, cmd->server, "FastCGI: there is no "
                     "fastcgi wrapper set, user/group options are ignored");
    }

    if ((err = fcgi_util_fs_set_uid_n_gid(p, s, s->uid, s->gid)))
    {
        return ap_psprintf(tp, 
            "%s %s: invalid user or group: %s", name, fs_path, err);
    }
#endif /* !WIN32 */

    if (s->socket_path != NULL && s->port != 0) {
        return ap_psprintf(tp,
                "%s %s: -port and -socket are mutually exclusive options",
                name, fs_path);
    }

    /* Move env array to a surviving pool */
    s->envp = (char **)ap_pcalloc(p, sizeof(char *) * (envc + 4));
    memcpy(s->envp, envp, sizeof(char *) * envc);

    /* Initialize process structs */
    s->procs = fcgi_util_fs_create_procs(p, s->numProcesses);

    /* Build the appropriate sockaddr structure */
    if (s->port != 0) {
        err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->socket_addr,
                                &s->socket_addr_len, NULL, s->port);
        if (err != NULL)
            return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#ifdef WIN32
        err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->dest_addr,
                                          &s->socket_addr_len, "localhost", s->port);
        if (err != NULL)
            return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#endif
    } else {
        if (s->socket_path == NULL)
             s->socket_path = fcgi_util_socket_hash_filename(tp, fs_path, s->user, s->group);

        if (fcgi_socket_dir == NULL)
        {
#ifdef WIN32
            fcgi_socket_dir = DEFAULT_SOCK_DIR;
#else
            fcgi_socket_dir = ap_server_root_relative(p, DEFAULT_SOCK_DIR);
#endif
        }

        s->socket_path = fcgi_util_socket_make_path_absolute(p, s->socket_path, 0);
#ifndef WIN32
        err = fcgi_util_socket_make_domain_addr(p, (struct sockaddr_un **)&s->socket_addr,
                                  &s->socket_addr_len, s->socket_path);
        if (err != NULL)
            return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#endif
    }

    /* Add it to the list of FastCGI servers */
    fcgi_util_fs_add(s);

    return NULL;
}
Esempio n. 24
0
/*******************************************************************************
 * Configure a static FastCGI server that is started/managed elsewhere.
 */
const char *fcgi_config_new_external_server(cmd_parms *cmd, void *dummy, const char *arg)
{
    fcgi_server *s;
    pool * const p = cmd->pool, *tp = cmd->temp_pool;
    const char * const name = cmd->cmd->name;
    char *fs_path = ap_getword_conf(p, &arg);
    const char *option, *err;

    err = ap_check_cmd_context(cmd, NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE);
    if (err) {
        return err;
    }

    if (!*fs_path) {
        return ap_pstrcat(tp, name, " requires a path and either a -socket or -host option", NULL);
    }

#ifdef APACHE2
    if (apr_filepath_merge(&fs_path, "", fs_path, 0, p))
        return ap_psprintf(tp, "%s %s: invalid filepath", name, fs_path);
#else
    fs_path = ap_os_canonical_filename(p, fs_path);
#endif

    fs_path = ap_server_root_relative(p, fs_path);

    ap_getparents(fs_path);
    ap_no2slash(fs_path);

    /* See if we've already got one of these bettys configured */
    s = fcgi_util_fs_get_by_id(fs_path, fcgi_util_get_server_uid(cmd->server),
                               fcgi_util_get_server_gid(cmd->server));
    if (s != NULL) {
        if (fcgi_wrapper) {
            return ap_psprintf(tp,
                "%s: redefinition of a previously defined class \"%s\" "
                "with uid=%ld and gid=%ld",
                name, fs_path, (long) fcgi_util_get_server_uid(cmd->server),
                (long) fcgi_util_get_server_gid(cmd->server));
        }
        else 
        {
            return ap_psprintf(tp,
                "%s: redefinition of previously defined class \"%s\"", name, fs_path);
        }
    }

    s = fcgi_util_fs_new(p);
    s->fs_path = fs_path;
    s->directive = APP_CLASS_EXTERNAL;

    /*  Parse directive arguments */
    while (*arg != '\0') {
        option = ap_getword_conf(tp, &arg);

        if (strcasecmp(option, "-host") == 0) {
            if ((err = get_host_n_port(p, &arg, &s->host, &s->port)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-socket") == 0) {
            s->socket_path = ap_getword_conf(tp, &arg);
            if (*s->socket_path == '\0')
                return invalid_value(tp, name, fs_path, option, "\"\"");
        }
        else if (strcasecmp(option, "-appConnTimeout") == 0) {
            if ((err = get_u_int(tp, &arg, &s->appConnectTimeout, 0)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-idle-timeout") == 0) {
            if ((err = get_u_int(tp, &arg, &s->idle_timeout, 1)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-nph") == 0) {
            s->nph = 1;
        }
        else if (strcasecmp(option, "-pass-header") == 0) {
            if ((err = get_pass_header(p, &arg, &s->pass_headers)))
                return invalid_value(tp, name, fs_path, option, err);
        }
        else if (strcasecmp(option, "-flush") == 0) {
            s->flush = 1;
        }
        else if (strcasecmp(option, "-user") == 0) {
#ifdef WIN32
            return ap_psprintf(tp, 
                "%s %s: the -user option isn't supported on WIN", name, fs_path);
#else
            s->user = ap_getword_conf(tp, &arg);
            if (*s->user == '\0')
                return invalid_value(tp, name, fs_path, option, "\"\"");
#endif
        }
        else if (strcasecmp(option, "-group") == 0) {
#ifdef WIN32
            return ap_psprintf(tp, 
                "%s %s: the -group option isn't supported on WIN", name, fs_path);
#else
            s->group = ap_getword_conf(tp, &arg);
            if (*s->group == '\0')
                return invalid_value(tp, name, fs_path, option, "\"\"");
#endif
        }
        else if (strcasecmp(option, "-fixPaths") == 0) {
            s->fixPaths = 1;
        }
        else {
            return ap_psprintf(tp, "%s %s: invalid option: %s", name, fs_path, option);
        }
    } /* while */


#ifndef WIN32
    if (fcgi_wrapper)
    {
        if (s->group == NULL)
        {
            s->group = ap_psprintf(tp, "#%ld", (long)fcgi_util_get_server_gid(cmd->server));
        }

        if (s->user == NULL)
        {
            s->user = ap_psprintf(p, "#%ld", (long)fcgi_util_get_server_uid(cmd->server));
        }

        s->uid = ap_uname2id(s->user);
        s->gid = ap_gname2id(s->group);
    }
    else if (s->user || s->group)
    {
        ap_log_error(FCGI_LOG_WARN, cmd->server, "FastCGI: there is no "
                     "fastcgi wrapper set, user/group options are ignored");
    }

    if ((err = fcgi_util_fs_set_uid_n_gid(p, s, s->uid, s->gid)))
    {
        return ap_psprintf(tp,
            "%s %s: invalid user or group: %s", name, fs_path, err);
    }
#endif /* !WIN32 */

    /* Require one of -socket or -host, but not both */
    if (s->socket_path != NULL && s->port != 0) {
        return ap_psprintf(tp,
            "%s %s: -host and -socket are mutually exclusive options",
            name, fs_path);
    }
    if (s->socket_path == NULL && s->port == 0) {
        return ap_psprintf(tp,
            "%s %s: -socket or -host option missing", name, fs_path);
    }

    /* Build the appropriate sockaddr structure */
    if (s->port != 0) {
        err = fcgi_util_socket_make_inet_addr(p, (struct sockaddr_in **)&s->socket_addr,
            &s->socket_addr_len, s->host, s->port);
        if (err != NULL)
            return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
    } else {

        if (fcgi_socket_dir == NULL)
        {
#ifdef WIN32
            fcgi_socket_dir = DEFAULT_SOCK_DIR;
#else
            fcgi_socket_dir = ap_server_root_relative(p, DEFAULT_SOCK_DIR);
#endif
        }

        s->socket_path = fcgi_util_socket_make_path_absolute(p, s->socket_path, 0);
#ifndef WIN32
        err = fcgi_util_socket_make_domain_addr(p, (struct sockaddr_un **)&s->socket_addr,
                                  &s->socket_addr_len, s->socket_path);
        if (err != NULL)
            return ap_psprintf(tp, "%s %s: %s", name, fs_path, err);
#endif
    }

    /* Add it to the list of FastCGI servers */
    fcgi_util_fs_add(s);

    return NULL;
}
 bool empty() const { return head[bucket_id] == invalid_value(); }
Esempio n. 26
0
int
cb_load_conf (const char *fname, const int check_nodef, const int prefix_dir)
{
	char			*s;
	char			*e;
	const char		*name;
	const char		*val;
	void			*var;
	FILE			*fp;
	char			*nores;
	struct noreserve	*noresptr;
	int			i;
	int			j;
	int			ret;
	int			saveret;
	int			line;
	char			buff[COB_SMALL_BUFF];

	/* initialize the config table */
	if (check_nodef) {
		for (i = 0; config_table[i].name; i++) {
			config_table[i].val = NULL;
		}
	}

	if (prefix_dir) {
		snprintf (buff, COB_SMALL_MAX, "%s/%s", cob_config_dir, fname);
		name = buff;
	} else {
		name = fname;
	}
	/* open the config file */
	fp = fopen (name, "r");
	if (fp == NULL) {
		perror (name);
		return -1;
	}

	/* read the config file */
	ret = 0;
	line = 0;
	while (fgets (buff, COB_SMALL_BUFF, fp)) {
		line++;

		/* skip comments */
		if (buff[0] == '#') {
			continue;
		}

		/* skip blank lines */
		for (s = buff; *s; s++) {
			if (isgraph (*s)) {
				break;
			}
		}
		if (!*s) {
			continue;
		}

		/* get the tag */
		s = strpbrk (buff, " \t:=");
		if (!s) {
			fprintf (stderr, "%s:%d: invalid line\n", fname, line);
			ret = -1;
			continue;
		}
		*s = 0;

		/* find the entry */
		for (i = 0; config_table[i].name; i++) {
			if (strcmp (buff, config_table[i].name) == 0) {
				break;
			}
		}
		if (!config_table[i].name) {
			fprintf (stderr, "%s:%d: unknown tag '%s'\n", fname, line, buff);
			ret = -1;
			continue;
		}

		/* get the value */
		for (s++; *s && strchr (" \t:=", *s); s++) {
			;
		}
		e = s + strlen (s) - 1;
		for (; e >= s && strchr (" \t\r\n", *e); e--) {
			;
		}
		e[1] = 0;
		config_table[i].val = s;

		/* set the value */
		name = config_table[i].name;
		var = config_table[i].var;
		val = config_table[i].val;
		switch (config_table[i].type) {
		case ANY:
			if (strcmp (name, "assign-clause") == 0) {
				if (strcmp (val, "cobol2002") == 0) {
					unsupported_value (fname, line, val);
					ret = -1;
				} else if (strcmp (val, "mf") == 0) {
					cb_assign_clause = CB_ASSIGN_MF;
				} else if (strcmp (val, "ibm") == 0) {
					cb_assign_clause = CB_ASSIGN_IBM;
				} else if (strcmp (val, "jph1") == 0) {
					cb_assign_clause = CB_ASSIGN_JPH1;
				} else {
					invalid_value (fname, line, name);
					ret = -1;
				}
			} else if (strcmp (name, "binary-size") == 0) {
				if (strcmp (val, "2-4-8") == 0) {
					cb_binary_size = CB_BINARY_SIZE_2_4_8;
				} else if (strcmp (val, "1-2-4-8") == 0) {
					cb_binary_size = CB_BINARY_SIZE_1_2_4_8;
				} else if (strcmp (val, "1--8") == 0) {
					cb_binary_size = CB_BINARY_SIZE_1__8;
				} else {
					invalid_value (fname, line, name);
					ret = -1;
				}
			} else if (strcmp (name, "binary-byteorder") == 0) {
				if (strcmp (val, "native") == 0) {
					cb_binary_byteorder = CB_BYTEORDER_NATIVE;
				} else if (strcmp (val, "big-endian") == 0) {
					cb_binary_byteorder = CB_BYTEORDER_BIG_ENDIAN;
				} else {
					invalid_value (fname, line, name);
					ret = -1;
				}
			} else if (strcmp (name, "abort-on-io-exception") == 0) {
				if (strcmp (val, "any") == 0) {
					cb_abort_on_io_exception = CB_ABORT_ON_IO_ANY;
				} else if (strcmp (val, "fatal") == 0) {
					cb_abort_on_io_exception = CB_ABORT_ON_IO_FATAL;
				} else if (strcmp (val, "never") == 0) {
					cb_abort_on_io_exception = CB_ABORT_ON_IO_NEVER;
				} else {
					invalid_value (fname, line, name);
					ret = -1;
				}
			} else if (strcmp (name, "default-organization") == 0) {
				if (strcmp (val, "record-sequential") == 0) {
					cb_default_organization = CB_ORG_RECORD_SEQUENTIAL;
				} else if (strcmp (val, "line-sequential") == 0) {
					cb_default_organization = CB_ORG_LINE_SEQUENTIAL;
				} else {
					invalid_value (fname, line, name);
					ret = -1;
				}
			}
			break;
		case INT:
			for (j = 0; val[j]; j++) {
				if (!isdigit (val[j])) {
					invalid_value (fname, line, name);
					ret = -1;
					break;
				}
			}
			*((int *)var) = atoi (val);
			break;
		case STRING:
			val = read_string (val);

			if (strcmp (name, "include") == 0) {
				/* include another conf file */
				saveret = ret;
				if (cb_load_conf (val, 0, 1) != 0) {
					return -1;
				}
				ret = saveret;
			} else if (strcmp (name, "not-reserved") == 0) {
				nores = read_string (val);
				noresptr = cobc_malloc (sizeof (struct noreserve));
				noresptr->noresword = cobc_malloc (strlen (nores) + 1);
				strcpy (noresptr->noresword, nores);
				noresptr->next = norestab;
				norestab = noresptr;
			} else {
				*((const char **)var) = val;
			}
			break;
		case CHAR:
			if (1 != strnlen (val, 2)) {
				invalid_value (fname, line, name);
				ret = -1;
			} else {
				*((char *)var) = *val;
			}
			break;
		case BOOLEAN:
			if (strcmp (val, "yes") == 0) {
				*((int *)var) = 1;
			} else if (strcmp (val, "no") == 0) {
				*((int *)var) = 0;
			} else {
				invalid_value (fname, line, name);
				ret = -1;
			}
			break;
		case SUPPORT:
			if (strcmp (val, "ok") == 0) {
				*((enum cb_support *)var) = CB_OK;
			} else if (strcmp (val, "warning") == 0) {
				*((enum cb_support *)var) = CB_WARNING;
			} else if (strcmp (val, "archaic") == 0) {
				*((enum cb_support *)var) = CB_ARCHAIC;
			} else if (strcmp (val, "obsolete") == 0) {
				*((enum cb_support *)var) = CB_OBSOLETE;
			} else if (strcmp (val, "skip") == 0) {
				*((enum cb_support *)var) = CB_SKIP;
			} else if (strcmp (val, "ignore") == 0) {
				*((enum cb_support *)var) = CB_IGNORE;
			} else if (strcmp (val, "error") == 0) {
				*((enum cb_support *)var) = CB_ERROR;
			} else if (strcmp (val, "unconformable") == 0) {
				*((enum cb_support *)var) = CB_UNCONFORMABLE;
			} else {
				invalid_value (fname, line, name);
				ret = -1;
			}
			break;
		default:
			fprintf (stderr, _("%s:%d: invalid type for '%s'\n"),
				 fname, line, name);
			ret = -1;
			break;
		}
	}
	fclose (fp);

	/* if assign_external is not setted in config file */
	for (i = 0; config_table[i].name; i++) {
		if (config_table[i].val == NULL && strcmp (config_table[i].name, "assign_external") == 0) {
			config_table[i].val = (char *)"no";
			*((int *)config_table[i].var) = 0;
		}
	}

	/* checks for no definition */
	if (check_nodef) {
		for (i = 2; config_table[i].name; i++) {
			if (config_table[i].val == NULL) {
				fprintf (stderr, "%s: no definition of '%s'\n",
					 fname, config_table[i].name);
				ret = -1;
			}
		}
	}

	return ret;
}
Esempio n. 27
0
 R operator()(T& t, J, V& v, R r)
 {
   if ( !J()(v) )
     return throw_<_except_>(t, invalid_value( distance(r) ), r);
   return r;
 }
Esempio n. 28
0
bool
impl::file_handle::is_valid(void)
    const
{
    return m_handle != invalid_value();
}
Esempio n. 29
0
impl::file_handle::file_handle(handle_type h) :
    m_handle(h)
{
    PRE(m_handle != invalid_value());
}
Esempio n. 30
0
impl::file_handle::file_handle(const file_handle& fh) :
    m_handle(fh.m_handle)
{
    fh.m_handle = invalid_value();
}