コード例 #1
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 活动
apr_status_t event_duplicate_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	event_duplicate_t * ed = (event_duplicate_t *)
		apr_palloc(res_pool, sizeof(event_duplicate_t));
	ed->id = (apr_int32_t)apr_atoi64(argv[0]);
	ed->cycle_mode = (apr_int32_t)apr_atoi64(argv[2]);
	ed->begin_time = 0;
	ed->duration = (apr_int32_t)apr_atoi64(argv[4]);
	ed->battle_node[0] = 0;
	ed->battle_node[1] = 0;
	ed->battle_node[2] = 0;

	apr_int32_t key = ed->id;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), ed);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}
	return APR_SUCCESS;
}
コード例 #2
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 符石抽奖
apr_status_t lottery_stone_parser(
    apr_size_t nargs,
    char ** argv,
    apr_hash_t * res_subhash,
    apr_pool_t * res_pool)
{
    lottery_stone_t * ls = (lottery_stone_t *)
        apr_palloc(res_pool, sizeof(lottery_stone_t));
    ls->group_id = (apr_int32_t)apr_atoi64(argv[0]);
    ls->ptt_id = (card_ptt_id_t)apr_atoi64(argv[1]);
    ls->ptt_prob = (apr_int32_t)apr_atoi64(argv[2]);

    apr_int32_t key = ls->group_id;
    apr_hash_t * group_hash = (apr_hash_t *)
        apr_hash_get(res_subhash, &key, sizeof(key));
    if (group_hash == NULL) {
        group_hash = apr_hash_make(res_pool);
        apr_hash_set(res_subhash,
            &key,
            sizeof(key),
            group_hash);
    }
    apr_hash_set(group_hash,
        &ls->ptt_id,
        sizeof(ls->ptt_id),
        ls);

    return APR_SUCCESS;
}
コード例 #3
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 卡牌
apr_status_t card_ptt_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	card_ptt_t * ptt = (card_ptt_t *)
		apr_palloc(res_pool, sizeof(card_ptt_t));
	ptt->id = (card_ptt_id_t)apr_atoi64(argv[0]);
	ptt->class_info = (apr_int32_t)apr_atoi64(argv[7]);
	ptt->leadership_cost = (apr_int32_t)apr_atoi64(argv[12]);
	ptt->levelup_exp_type = (apr_int32_t)apr_atoi64(argv[13]);
	ptt->level_max = (apr_int32_t)apr_atoi64(argv[14]);
	ptt->hp_base = (apr_int32_t)apr_atoi64(argv[15]);
	ptt->att_base = (apr_int32_t)apr_atoi64(argv[18]);
	ptt->compose_exp_base = (apr_int32_t)apr_atoi64(argv[24]);
	ptt->sell_gold_base = (apr_int16_t)apr_atoi64(argv[25]);

	card_ptt_id_t key = ptt->id;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), ptt);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}
	return APR_SUCCESS;
}
コード例 #4
0
ファイル: aos_transport.c プロジェクト: EricChen2013/EasyRMS
static void aos_curl_transport_headers_done(aos_curl_http_transport_t *t)
{
    long http_code;
    CURLcode code;
    const char *value;

    if (t->controller->error_code != AOSE_OK) {
        aos_debug_log("has error %d.", t->controller->error_code);
        return;
    }
    
    if (t->resp->status > 0) {
        aos_trace_log("http response status %d.", t->resp->status);
        return;
    }

    t->resp->status = 0;
    if ((code = curl_easy_getinfo(t->curl, CURLINFO_RESPONSE_CODE, &http_code)) != CURLE_OK) {
        t->controller->reason = apr_pstrdup(t->pool, curl_easy_strerror(code));
        t->controller->error_code = AOSE_INTERNAL_ERROR;
        return;
    } else {
        t->resp->status = http_code;
    }

    value = apr_table_get(t->resp->headers, "Content-Length");
    if (value != NULL) {
        t->resp->content_length = apr_atoi64(value);
    }
}
コード例 #5
0
ファイル: px_utils.c プロジェクト: PerimeterX/mod_perimeterx
// returns the payload version, 0 if error msg, -1 if header not found
int extract_payload_from_header(apr_pool_t *pool, apr_table_t *headers, const char **payload3, const char **payload1) {
    *payload3 = NULL;
    *payload1 = NULL;
    const char *header_value = apr_table_get(headers, MOBILE_SDK_HEADER);
    if (header_value) {
        char *rest;
        char *header_cpy = apr_pstrdup(pool, header_value);
        const char *prefix = apr_strtok(header_cpy, ":", &rest);
        if (prefix == NULL) {
            // Setting payload to "" so it will fail on decryption
            *payload3 = "";
            return 0;
        }
        const char *postfix = apr_strtok(NULL, "", &rest);
        // if postfix is empty, use prefix as payload number, in this case version will be 0
        if (postfix == NULL) {
            *payload3 = prefix;
            return 0;
        }
        int version = apr_atoi64(prefix);
        switch (version) {
            case 1:
                *payload1 = postfix;
                break;
            case 3:
                *payload3 = postfix;
                break;
            default:
                return -1;
        }
        return version;
    }
    return -1;
}
コード例 #6
0
ファイル: h2_alt_svc.c プロジェクト: NeedfulThings/mod_h2
/**
 * Parse an Alt-Svc specifier as described in "HTTP Alternative Services"
 * (https://tools.ietf.org/html/draft-ietf-httpbis-alt-svc-04)
 * with the following changes:
 * - do not percent encode token values
 * - do not use quotation marks
 */
h2_alt_svc *h2_alt_svc_parse(const char *s, apr_pool_t *pool) {
    const char *sep = ap_strchr_c(s, '=');
    if (sep) {
        const char *alpn = apr_pstrndup(pool, s, sep - s);
        const char *host = NULL;
        int port = 0;
        s = sep + 1;
        sep = ap_strchr_c(s, ':');  /* mandatory : */
        if (sep) {
            if (sep != s) {    /* optional host */
                host = apr_pstrndup(pool, s, sep - s);
            }
            s = sep + 1;
            if (*s) {          /* must be a port number */
                port = (int)apr_atoi64(s);
                if (port > 0 && port < (0x1 << 16)) {
                    h2_alt_svc *as = apr_pcalloc(pool, sizeof(*as));
                    as->alpn = alpn;
                    as->host = host;
                    as->port = port;
                    return as;
                }
            }
        }
    }
    return NULL;
}
コード例 #7
0
ファイル: h2_config.c プロジェクト: reschke/mod_h2
static const char *h2_conf_set_max_worker_idle_secs(cmd_parms *parms,
                                                    void *arg, const char *value)
{
    h2_config *cfg = h2_config_sget(parms->server);
    cfg->max_worker_idle_secs = (int)apr_atoi64(value);
    (void)arg;
    return NULL;
}
コード例 #8
0
ファイル: h2_config.c プロジェクト: reschke/mod_h2
static const char *h2_conf_set_max_hl_size(cmd_parms *parms,
                                           void *arg, const char *value)
{
    h2_config *cfg = h2_config_sget(parms->server);
    cfg->h2_max_hl_size = (int)apr_atoi64(value);
    (void)arg;
    return NULL;
}
コード例 #9
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 玩家升级
apr_status_t actor_levelup_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	actor_levelup_t * lu = (actor_levelup_t *)
		apr_palloc(res_pool, sizeof(actor_levelup_t));
	lu->level = (level_t)apr_atoi64(argv[0]);
	lu->to_next_level = (apr_int32_t)apr_atoi64(argv[1]);
	lu->stamina_max = (apr_int32_t)apr_atoi64(argv[2]);
	lu->cards_max = (apr_int32_t)apr_atoi64(argv[3]);
	lu->leadership_max = (apr_int32_t)apr_atoi64(argv[4]);
	lu->friends_max = (apr_int32_t)apr_atoi64(argv[5]);
	lu->stamina_reward = (apr_int32_t)apr_atoi64(argv[6]);

	level_t key = lu->level;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), lu);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}
	return APR_SUCCESS;
}
コード例 #10
0
const char *
but_config_session_inactivity_timeout(cmd_parms *cmd, void *dummy, const char *arg)
{
	mod_but_server_t *conf = ap_get_module_config(cmd->server->module_config, &but_module);
	if (arg) {
		conf->session_inactivity_timeout = apr_atoi64(arg);
	}
	return OK;
}
コード例 #11
0
static int find_cookie(request_rec *r,char **user,uint8_t *secret,int secretLen) {
	char *cookie=0l;
	char *cookie_expire=0l;
	char *cookie_valid=0l;
	ap_regmatch_t regmatch[AP_MAX_REG_MATCH];
	authn_google_config_rec *conf = ap_get_module_config(r->per_dir_config, &authn_google_module);
	cookie = (char *) apr_table_get(r->headers_in, "Cookie");
	if (cookie) {
	if (conf->debugLevel) 
					ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
												"Found cookie \"%s\"",cookie);
		if (!ap_regexec(cookie_regexp, cookie, AP_MAX_REG_MATCH, regmatch, 0)) {
			if (user) *user  = ap_pregsub(r->pool, "$2", cookie,AP_MAX_REG_MATCH,regmatch);
			cookie_expire = ap_pregsub(r->pool, "$3", cookie,AP_MAX_REG_MATCH,regmatch);
			cookie_valid = ap_pregsub(r->pool, "$4", cookie,AP_MAX_REG_MATCH,regmatch);
				
if (conf->debugLevel) 
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "Found cookie Expires \"%s\" Valid \"%s\"",cookie_expire,cookie_valid);

				if (cookie_expire && cookie_valid && *user) {
					long unsigned int exp = apr_atoi64(cookie_expire);
					long unsigned int now = apr_time_now()/1000000;
					if (exp < now) {

if (conf->debugLevel) 
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
           "Expired. Now=%lu Expire=%lu\n",now,exp);

						return 0;	/* Expired */
					}
					if (!secret) {
						secret = getUserSecret(r,*user,&secretLen,0L);
					}
					char *h = hash_cookie(r->pool,secret,secretLen,exp);

if (conf->debugLevel) 
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "Match cookie \"%s\" vs  \"%s\"",h,cookie_valid);

					if (apr_strnatcmp(h,cookie_valid)==0)
						return 1; /* Valid Cookie */
					else {

if (conf->debugLevel) 
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "MISMATCHED  cookie \"%s\" vs  \"%s\"",h,cookie_valid);

						return 0; /* Mismatched */
					}
				}
		}
	}
	return 0;	/* Not found */
}
コード例 #12
0
ファイル: h2_config.c プロジェクト: practicalswift/osx
static const char *h2_conf_set_window_size(cmd_parms *parms,
                                           void *arg, const char *value)
{
    h2_config *cfg = (h2_config *)h2_config_sget(parms->server);
    cfg->h2_window_size = (int)apr_atoi64(value);
    (void)arg;
    if (cfg->h2_window_size < 1024) {
        return "value must be >= 1024";
    }
    return NULL;
}
コード例 #13
0
ファイル: mrcp_start_line.c プロジェクト: AaronZhangL/unimrcp
/** Parse MRCP request-id */
MRCP_DECLARE(mrcp_request_id) mrcp_request_id_parse(const apt_str_t *field)
{
	if(field->buf) {
#ifdef TOO_LONG_MRCP_REQUEST_ID
		return apr_atoi64(field->buf);
#else
		return atol(field->buf);
#endif
	}
	return 0;
}
コード例 #14
0
ファイル: h2_config.c プロジェクト: practicalswift/osx
static const char *h2_conf_set_max_worker_idle_secs(cmd_parms *parms,
                                                    void *arg, const char *value)
{
    h2_config *cfg = (h2_config *)h2_config_sget(parms->server);
    cfg->max_worker_idle_secs = (int)apr_atoi64(value);
    (void)arg;
    if (cfg->max_worker_idle_secs < 1) {
        return "value must be > 0";
    }
    return NULL;
}
コード例 #15
0
ファイル: h2_config.c プロジェクト: NeedfulThings/mod_h2
static const char *h2_conf_set_min_workers(cmd_parms *parms,
                                           void *arg, const char *value)
{
    h2_config *cfg = h2_config_sget(parms->server);
    cfg->min_workers = (int)apr_atoi64(value);
    (void)arg;
    if (cfg->min_workers < 1) {
        return "value must be > 1";
    }
    return NULL;
}
コード例 #16
0
static unsigned int parse_number(const char *string, const char *name, apr_int64_t min, apr_int64_t max,
    apr_int64_t default_value, server_rec *s) {
    if (string == NULL) {
        return default_value;
    }
    apr_int64_t value = apr_atoi64(string);
    if (errno != 0 || value > max || value < min) {
        ap_log_error(APLOG_MARK, APLOG_EMERG, errno, s, "Could not parse %s: '%s'", name, string);
        exit(1);
    }
    return value;
}
コード例 #17
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 队长技能
apr_status_t captskill_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	captskill_t * s =
		(captskill_t *)apr_palloc(res_pool, sizeof(captskill_t));
	s->id = (captskill_id_t)apr_atoi64(argv[0]);
	s->plus0 = (apr_int32_t)apr_atoi64(argv[5]);
	s->plus1 = (apr_int32_t)apr_atoi64(argv[6]);
	s->plus2 = (apr_int32_t)apr_atoi64(argv[7]);
	s->plus3 = (apr_int32_t)apr_atoi64(argv[8]);
	s->plus4 = (apr_int32_t)apr_atoi64(argv[9]);

	captskill_id_t key = s->id;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), s);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}
	return APR_SUCCESS;
}
コード例 #18
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 任务
apr_status_t quest_ptt_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	quest_ptt_t * ptt = (quest_ptt_t *)
		apr_palloc(res_pool, sizeof(quest_ptt_t));
	ptt->id = (quest_ptt_id_t)apr_atoi64(argv[0]);
	ptt->pre_quest_id = (apr_int32_t)apr_atoi64(argv[5]);
	ptt->reward_type = (apr_int32_t)apr_atoi64(argv[6]);
	ptt->reward_param = (apr_int32_t)apr_atoi64(argv[7]);
	ptt->cond1_type = (apr_int32_t)apr_atoi64(argv[8]);
	ptt->cond1_param = (apr_int32_t)apr_atoi64(argv[9]);

	quest_ptt_id_t key = ptt->id;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), ptt);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}
	return APR_SUCCESS;
}
コード例 #19
0
ファイル: h2_config.c プロジェクト: NeedfulThings/mod_h2
static const char *h2_conf_set_stream_max_mem_size(cmd_parms *parms,
                                                   void *arg, const char *value)
{
    h2_config *cfg = h2_config_sget(parms->server);
    
    
    cfg->stream_max_mem_size = (int)apr_atoi64(value);
    (void)arg;
    if (cfg->stream_max_mem_size < 1024) {
        return "value must be > 1k";
    }
    return NULL;
}
コード例 #20
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 卡牌合成
apr_status_t card_compose_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	card_compose_t * clu = (card_compose_t *)
		apr_palloc(res_pool, sizeof(card_compose_t));
	clu->level = (level_t)apr_atoi64(argv[0]);
	clu->compose_exp[0] = (apr_int32_t)apr_atoi64(argv[1]);
	clu->compose_exp[1] = (apr_int32_t)apr_atoi64(argv[2]);
	clu->compose_exp[2] = (apr_int32_t)apr_atoi64(argv[3]);
	clu->compose_exp[3] = (apr_int32_t)apr_atoi64(argv[4]);

	level_t key = clu->level;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), clu);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}
	return APR_SUCCESS;
}
コード例 #21
0
ファイル: session.c プロジェクト: azenk/mod_auth_openidc
// copied from mod_session.c
static apr_status_t oidc_session_identity_decode(request_rec * r,
		session_rec * z) {
	char *last = NULL;
	char *encoded, *pair;
	const char *sep = "&";

	//oidc_debug(r, "decoding %s", z->encoded);

	/* sanity check - anything to decode? */
	if (!z->encoded) {
		return APR_SUCCESS;
	}

	/* decode what we have */
	encoded = apr_pstrdup(r->pool, z->encoded);
	pair = apr_strtok(encoded, sep, &last);
	while (pair && pair[0]) {
		char *plast = NULL;
		const char *psep = "=";
		char *key = apr_strtok(pair, psep, &plast);
		char *val = apr_strtok(NULL, psep, &plast);

		//oidc_debug(r, "decoding %s=%s", key, val);

		if (key && *key) {
			if (!val || !*val) {
				apr_table_unset(z->entries, key);
			} else if (!ap_unescape_urlencoded(key)
					&& !ap_unescape_urlencoded(val)) {
				if (!strcmp(OIDC_SESSION_EXPIRY_KEY, key)) {
					z->expiry = (apr_time_t) apr_atoi64(val);
				} else {
					apr_table_set(z->entries, key, val);
				}
			}
		}
		pair = apr_strtok(NULL, sep, &last);
	}
	z->encoded = NULL;
	return APR_SUCCESS;
}
コード例 #22
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 卡牌进化
apr_status_t card_evolution_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	card_evolution_t * ce = (card_evolution_t *)
		apr_palloc(res_pool, sizeof(card_evolution_t));
	ce->id = (card_id_t)apr_atoi64(argv[0]);
	ce->equip_set_required = (int)apr_atoi64(argv[1]);
	ce->id_evo = (card_id_t)apr_atoi64(argv[2]);
	ce->level_required = (level_t)apr_atoi64(argv[3]);
	ce->type_required = (int)apr_atoi64(argv[4]);
	ce->card1_required[0] = CARD_INVALID_ID;
	ce->card1_required[1] = CARD_INVALID_ID;
	ce->card2_required[0] = CARD_INVALID_ID;
	ce->card2_required[1] = CARD_INVALID_ID;
	ce->card3_required[0] = CARD_INVALID_ID;
	ce->card3_required[1] = CARD_INVALID_ID;
	ce->card4_required[0] = CARD_INVALID_ID;
	ce->card4_required[1] = CARD_INVALID_ID;
	ce->card5_required[0] = CARD_INVALID_ID;
	ce->card5_required[1] = CARD_INVALID_ID;
	ce->level_evo = (level_t)apr_atoi64(argv[10]);
	ce->initsk_level_evo = (initskill_level_t)apr_atoi64(argv[11]);
	ce->gold_required = (int)apr_atoi64(argv[13]);
	
	card_id_t key = ce->id;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), ce);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}

	return APR_SUCCESS;
}
コード例 #23
0
ファイル: mod_trell_ops.c プロジェクト: KjeFre/tinia
/** Read the master job pid from file on disc. */
static int
trell_get_master_pid( trell_sconf_t* svr_conf,  request_rec* r, pid_t* pid )
{
    apr_status_t rv;

    apr_file_t* pidfile = NULL;
    rv = apr_file_open( &pidfile, master_job_pidfile_path,
                        APR_READ, APR_OS_DEFAULT, r->pool );
    if( rv != APR_SUCCESS ) {
        ap_log_rerror( APLOG_MARK, APLOG_NOTICE, rv, r, "mod_trell: Failed to open master job pid file for reading." );
        return rv;
    }

    char* line = (char*)apr_palloc( r->pool, sizeof(unsigned char)*256 );
    rv = apr_file_gets( line, 256, pidfile );
    if( rv != APR_SUCCESS ) {
        ap_log_rerror( APLOG_MARK, APLOG_NOTICE, rv, r, "mod_trell: %s@%d", __FILE__, __LINE__ );
        return rv;
    }
    *pid = apr_atoi64( line );
    return APR_SUCCESS;
}
コード例 #24
0
/* return -1 means error */
static int parse_url (request_rec *r, const char *remote_url,
                      char **hostname, apr_int64_t *p_port_num,
                      char **filepath)
{
    apr_pool_t *rp = r->pool;
    char *p_port_str;
    char *p_tmp;

    *hostname = apr_pstrdup (rp, remote_url);
    if (!strncasecmp (*hostname, "http://", 7)) {
        *hostname += 7;
    }

    p_tmp = ap_strchr (*hostname, '/');
    
    if (p_tmp) {
        *filepath = apr_pstrdup (rp, p_tmp);
        *p_tmp = '\0';
    }
    else {
        *filepath = apr_pstrdup (rp, "/");
    }

    *p_port_num = DEF_PORT_NUM;
    if (p_port_str = ap_strchr (*hostname, ':')) {
        *p_port_str = '\0';
        p_port_str++;
        *p_port_num = apr_atoi64 (p_port_str);
    }

    if (errno == ERANGE) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "port number overflow");
        return -1;
    }
    return 0;
}
コード例 #25
0
ファイル: res_parser.cpp プロジェクト: marinemelody/MyUtility
// 主动技能
apr_status_t initskill_parser(
	apr_size_t nargs,
	char ** argv,
	apr_hash_t * res_subhash,
	apr_pool_t * res_pool)
{
	initskill_ptt_t * ptt = (initskill_ptt_t *)
		apr_palloc(res_pool, sizeof(initskill_ptt_t));
	ptt->id = (initskill_id_t)apr_atoi64(argv[0]);
	ptt->type = (apr_int32_t)apr_atoi64(argv[1]);
	ptt->level_max = (apr_int32_t)apr_atoi64(argv[5]);
	ptt->cast_cycle = (apr_int32_t)apr_atoi64(argv[6]);
	ptt->cast_round = (apr_int32_t)apr_atoi64(argv[7]);
	ptt->cast_target = (apr_int32_t)apr_atoi64(argv[8]);
	ptt->target_scope = (apr_int32_t)apr_atoi64(argv[9]);
	ptt->att_type = (apr_int32_t)apr_atoi64(argv[10]);
	ptt->base_fix_base = (apr_int32_t)apr_atoi64(argv[11]);
	ptt->levelup_fix_base = (apr_int32_t)apr_atoi64(argv[12]);
	ptt->levelup_prob = (apr_int32_t)apr_atoi64(argv[13]);
	ptt->effect_type = (apr_int32_t)apr_atoi64(argv[14]);
	ptt->effect_param = (apr_int32_t)apr_atoi64(argv[15]);

	initskill_id_t key = ptt->id;
	if (apr_hash_get(res_subhash, &key, sizeof(key)) == NULL) {
		apr_hash_set(res_subhash, &key, sizeof(key), ptt);
	} else {
		fprintf(stderr,
			"[RES] FAULT: duplicate key = %d\n",
			key);
	}
	return APR_SUCCESS;
}
コード例 #26
0
ファイル: gpsmon.c プロジェクト: phan-pivotal/gpdb
static void parse_command_line(int argc, const char* const argv[])
{
	apr_getopt_t* os;
	int ch;
	const char* arg;
	const char* bin_start = NULL;
	int e;
	static apr_getopt_option_t option[] =
	{
	{ NULL, '?', 0, "print help screen" },
	{ NULL, 'v', 1, "verbose" },
	{ NULL, 'D', 0, "debug mode" },
	{ NULL, 'l', 1, "log directory" },
	{ NULL, 'm', 1, "max log size" },
	{ NULL, 't', 1, "terminate timeout" },
	{ NULL, 'a', 0, "iterator aggregate" },
	{ NULL, 'i', 0, "ignore qexec packet" },
	{ NULL, 0, 0, NULL } };
	apr_pool_t* pool;

	if (0 != (e = apr_pool_create_alloc(&pool, 0)))
	{
		gpsmon_fatalx(FLINE, e, "apr_pool_create_alloc failed");
	}

	bin_start = argv[0] + strlen(argv[0]) - 1;
	while (bin_start != argv[0] && *bin_start != '/')
		bin_start--;
	if (bin_start[0] == '/')
		bin_start++;

	opt.pname = bin_start;
	opt.v = opt.D = 0;
	opt.max_log_size = 0;
	opt.terminate_timeout = 0;

	if (0 != (e = apr_getopt_init(&os, pool, argc, argv)))
	{
		gpsmon_fatalx(FLINE, e, "apr_getopt_init failed");
	}

	while (0 == (e = apr_getopt_long(os, option, &ch, &arg)))
	{
		switch (ch)
		{
		case '?':
			usage(0);
			break;
		case 'v':
			opt.v = atoi(arg);
			break;
		case 'D':
			opt.D = 1;
			break;
		case 'l':
			opt.log_dir = strdup(arg);
			break;
		case 'm':
			opt.max_log_size = apr_atoi64(arg);
			break;
		case 't':
			opt.terminate_timeout = apr_atoi64(arg);
			break;
		}
	}

	if (e != APR_EOF)
		usage("Error: illegal arguments");

	if (os->ind >= argc)
		usage("Error: missing port argument");
	opt.arg_port = argv[os->ind++];

	apr_pool_destroy(pool);

	verbose = opt.v;
	very_verbose = opt.V;
}
コード例 #27
0
ファイル: apr_dbd_mysql.c プロジェクト: cmjonze/apr
static apr_status_t dbd_mysql_datum_get(const apr_dbd_row_t *row, int n,
                                        apr_dbd_type_e type, void *data)
{
    if (row->res->statement) {
        MYSQL_BIND *bind = &row->res->bind[n];
        unsigned long len = *bind->length;

        if (mysql_stmt_fetch_column(row->res->statement, bind, n, 0) != 0) {
            return APR_EGENERAL;
        }

        if (*bind->is_null) {
            return APR_ENOENT;
        }

        switch (type) {
        case APR_DBD_TYPE_TINY:
            *(char*)data = atoi(bind->buffer);
            break;
        case APR_DBD_TYPE_UTINY:
            *(unsigned char*)data = atoi(bind->buffer);
            break;
        case APR_DBD_TYPE_SHORT:
            *(short*)data = atoi(bind->buffer);
            break;
        case APR_DBD_TYPE_USHORT:
            *(unsigned short*)data = atoi(bind->buffer);
            break;
        case APR_DBD_TYPE_INT:
            *(int*)data = atoi(bind->buffer);
            break;
        case APR_DBD_TYPE_UINT:
            *(unsigned int*)data = atoi(bind->buffer);
            break;
        case APR_DBD_TYPE_LONG:
            *(long*)data = atol(bind->buffer);
            break;
        case APR_DBD_TYPE_ULONG:
            *(unsigned long*)data = atol(bind->buffer);
            break;
        case APR_DBD_TYPE_LONGLONG:
            *(apr_int64_t*)data = apr_atoi64(bind->buffer);
            break;
        case APR_DBD_TYPE_ULONGLONG:
            *(apr_uint64_t*)data = apr_atoi64(bind->buffer);
            break;
        case APR_DBD_TYPE_FLOAT:
            *(float*)data = (float) atof(bind->buffer);
            break;
        case APR_DBD_TYPE_DOUBLE:
            *(double*)data = atof(bind->buffer);
            break;
        case APR_DBD_TYPE_STRING:
        case APR_DBD_TYPE_TEXT:
        case APR_DBD_TYPE_TIME:
        case APR_DBD_TYPE_DATE:
        case APR_DBD_TYPE_DATETIME:
        case APR_DBD_TYPE_TIMESTAMP:
        case APR_DBD_TYPE_ZTIMESTAMP:
            *((char*)bind->buffer+bind->buffer_length-1) = '\0';
            *(char**)data = bind->buffer;
            break;
        case APR_DBD_TYPE_BLOB:
        case APR_DBD_TYPE_CLOB:
            {
            apr_bucket *e;
            apr_bucket_brigade *b = (apr_bucket_brigade*)data;

            e = apr_bucket_lob_create(row, n, 0, len,
                                      row->res->pool, b->bucket_alloc);
            APR_BRIGADE_INSERT_TAIL(b, e);
            }
            break;
        case APR_DBD_TYPE_NULL:
            *(void**)data = NULL;
            break;
        default:
            return APR_EGENERAL;
        }
    }
    else {
        if (row->row[n] == NULL) {
            return APR_ENOENT;
        }

        switch (type) {
        case APR_DBD_TYPE_TINY:
            *(char*)data = atoi(row->row[n]);
            break;
        case APR_DBD_TYPE_UTINY:
            *(unsigned char*)data = atoi(row->row[n]);
            break;
        case APR_DBD_TYPE_SHORT:
            *(short*)data = atoi(row->row[n]);
            break;
        case APR_DBD_TYPE_USHORT:
            *(unsigned short*)data = atoi(row->row[n]);
            break;
        case APR_DBD_TYPE_INT:
            *(int*)data = atoi(row->row[n]);
            break;
        case APR_DBD_TYPE_UINT:
            *(unsigned int*)data = atoi(row->row[n]);
            break;
        case APR_DBD_TYPE_LONG:
            *(long*)data = atol(row->row[n]);
            break;
        case APR_DBD_TYPE_ULONG:
            *(unsigned long*)data = atol(row->row[n]);
            break;
        case APR_DBD_TYPE_LONGLONG:
            *(apr_int64_t*)data = apr_atoi64(row->row[n]);
            break;
        case APR_DBD_TYPE_ULONGLONG:
            *(apr_uint64_t*)data = apr_atoi64(row->row[n]);
            break;
        case APR_DBD_TYPE_FLOAT:
            *(float*)data = (float) atof(row->row[n]);
            break;
        case APR_DBD_TYPE_DOUBLE:
            *(double*)data = atof(row->row[n]);
            break;
        case APR_DBD_TYPE_STRING:
        case APR_DBD_TYPE_TEXT:
        case APR_DBD_TYPE_TIME:
        case APR_DBD_TYPE_DATE:
        case APR_DBD_TYPE_DATETIME:
        case APR_DBD_TYPE_TIMESTAMP:
        case APR_DBD_TYPE_ZTIMESTAMP:
            *(char**)data = row->row[n];
            break;
        case APR_DBD_TYPE_BLOB:
        case APR_DBD_TYPE_CLOB:
            {
            apr_bucket *e;
            apr_bucket_brigade *b = (apr_bucket_brigade*)data;

            e = apr_bucket_pool_create(row->row[n], row->len[n],
                                       row->res->pool, b->bucket_alloc);
            APR_BRIGADE_INSERT_TAIL(b, e);
            }
            break;
        case APR_DBD_TYPE_NULL:
            *(void**)data = NULL;
            break;
        default:
            return APR_EGENERAL;
        }
    }
    return 0;
}
コード例 #28
0
ファイル: htcacheclean.c プロジェクト: aptana/Jaxer
/*
 * main
 */
int main(int argc, const char * const argv[])
{
    apr_off_t max;
    apr_time_t current, repeat, delay, previous;
    apr_status_t status;
    apr_pool_t *pool, *instance;
    apr_getopt_t *o;
    apr_finfo_t info;
    int retries, isdaemon, limit_found, intelligent, dowork;
    char opt;
    const char *arg;
    char *proxypath, *path;

    interrupted = 0;
    repeat = 0;
    isdaemon = 0;
    dryrun = 0;
    limit_found = 0;
    max = 0;
    verbose = 0;
    realclean = 0;
    benice = 0;
    deldirs = 0;
    intelligent = 0;
    previous = 0; /* avoid compiler warning */
    proxypath = NULL;

    if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
        return 1;
    }
    atexit(apr_terminate);

    if (argc) {
        shortname = apr_filepath_name_get(argv[0]);
    }

    if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
        return 1;
    }
    apr_pool_abort_set(oom, pool);
    apr_file_open_stderr(&errfile, pool);
    apr_signal(SIGINT, setterm);
    apr_signal(SIGTERM, setterm);

    apr_getopt_init(&o, pool, argc, argv);

    while (1) {
        status = apr_getopt(o, "iDnvrtd:l:L:p:", &opt, &arg);
        if (status == APR_EOF) {
            break;
        }
        else if (status != APR_SUCCESS) {
            usage();
        }
        else {
            switch (opt) {
            case 'i':
                if (intelligent) {
                    usage();
                }
                intelligent = 1;
                break;

            case 'D':
                if (dryrun) {
                    usage();
                }
                dryrun = 1;
                break;

            case 'n':
                if (benice) {
                    usage();
                }
                benice = 1;
                break;

            case 't':
                if (deldirs) {
                    usage();
                }
                deldirs = 1;
                break;

            case 'v':
                if (verbose) {
                    usage();
                }
                verbose = 1;
                break;

            case 'r':
                if (realclean) {
                    usage();
                }
                realclean = 1;
                deldirs = 1;
                break;

            case 'd':
                if (isdaemon) {
                    usage();
                }
                isdaemon = 1;
                repeat = apr_atoi64(arg);
                repeat *= SECS_PER_MIN;
                repeat *= APR_USEC_PER_SEC;
                break;

            case 'l':
                if (limit_found) {
                    usage();
                }
                limit_found = 1;

                do {
                    apr_status_t rv;
                    char *end;

                    rv = apr_strtoff(&max, arg, &end, 10);
                    if (rv == APR_SUCCESS) {
                        if ((*end == 'K' || *end == 'k') && !end[1]) {
                            max *= KBYTE;
                        }
                        else if ((*end == 'M' || *end == 'm') && !end[1]) {
                            max *= MBYTE;
                        }
                        else if ((*end == 'G' || *end == 'g') && !end[1]) {
                            max *= GBYTE;
                        }
                        else if (*end &&        /* neither empty nor [Bb] */
                                 ((*end != 'B' && *end != 'b') || end[1])) {
                            rv = APR_EGENERAL;
                        }
                    }
                    if (rv != APR_SUCCESS) {
                        apr_file_printf(errfile, "Invalid limit: %s"
                                                 APR_EOL_STR APR_EOL_STR, arg);
                        usage();
                    }
                } while(0);
                break;

            case 'p':
                if (proxypath) {
                    usage();
                }
                proxypath = apr_pstrdup(pool, arg);
                if (apr_filepath_set(proxypath, pool) != APR_SUCCESS) {
                    usage();
                }
                break;
            } /* switch */
        } /* else */
    } /* while */

    if (o->ind != argc) {
         usage();
    }

    if (isdaemon && (repeat <= 0 || verbose || realclean || dryrun)) {
         usage();
    }

    if (!isdaemon && intelligent) {
         usage();
    }

    if (!proxypath || max <= 0) {
         usage();
    }

    if (apr_filepath_get(&path, 0, pool) != APR_SUCCESS) {
        usage();
    }
    baselen = strlen(path);

#ifndef DEBUG
    if (isdaemon) {
        apr_file_close(errfile);
        apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
    }
#endif

    do {
        apr_pool_create(&instance, pool);

        now = apr_time_now();
        APR_RING_INIT(&root, _entry, link);
        delcount = 0;
        unsolicited = 0;
        dowork = 0;

        switch (intelligent) {
        case 0:
            dowork = 1;
            break;

        case 1:
            retries = STAT_ATTEMPTS;
            status = APR_SUCCESS;

            do {
                if (status != APR_SUCCESS) {
                    apr_sleep(STAT_DELAY);
                }
                status = apr_stat(&info, path, APR_FINFO_MTIME, instance);
            } while (status != APR_SUCCESS && !interrupted && --retries);

            if (status == APR_SUCCESS) {
                previous = info.mtime;
                intelligent = 2;
            }
            dowork = 1;
            break;

        case 2:
            retries = STAT_ATTEMPTS;
            status = APR_SUCCESS;

            do {
                if (status != APR_SUCCESS) {
                    apr_sleep(STAT_DELAY);
                }
                status = apr_stat(&info, path, APR_FINFO_MTIME, instance);
            } while (status != APR_SUCCESS && !interrupted && --retries);

            if (status == APR_SUCCESS) {
                if (previous != info.mtime) {
                    dowork = 1;
                }
                previous = info.mtime;
                break;
            }
            intelligent = 1;
            dowork = 1;
            break;
        }

        if (dowork && !interrupted) {
            if (!process_dir(path, instance) && !interrupted) {
                purge(path, instance, max);
            }
            else if (!isdaemon && !interrupted) {
                apr_file_printf(errfile, "An error occurred, cache cleaning "
                                         "aborted." APR_EOL_STR);
                return 1;
            }

            if (intelligent && !interrupted) {
                retries = STAT_ATTEMPTS;
                status = APR_SUCCESS;
                do {
                    if (status != APR_SUCCESS) {
                        apr_sleep(STAT_DELAY);
                    }
                    status = apr_stat(&info, path, APR_FINFO_MTIME, instance);
                } while (status != APR_SUCCESS && !interrupted && --retries);

                if (status == APR_SUCCESS) {
                    previous = info.mtime;
                    intelligent = 2;
                }
                else {
                    intelligent = 1;
                }
            }
        }

        apr_pool_destroy(instance);

        current = apr_time_now();
        if (current < now) {
            delay = repeat;
        }
        else if (current - now >= repeat) {
            delay = repeat;
        }
        else {
            delay = now + repeat - current;
        }

        /* we can't sleep the whole delay time here apiece as this is racy
         * with respect to interrupt delivery - think about what happens
         * if we have tested for an interrupt, then get scheduled
         * before the apr_sleep() call and while waiting for the cpu
         * we do get an interrupt
         */
        if (isdaemon) {
            while (delay && !interrupted) {
                if (delay > APR_USEC_PER_SEC) {
                    apr_sleep(APR_USEC_PER_SEC);
                    delay -= APR_USEC_PER_SEC;
                }
                else {
                    apr_sleep(delay);
                    delay = 0;
                }
            }
        }
    } while (isdaemon && !interrupted);

    if (!isdaemon && interrupted) {
        apr_file_printf(errfile, "Cache cleaning aborted due to user "
                                 "request." APR_EOL_STR);
        return 1;
    }

    return 0;
}
コード例 #29
0
ファイル: apr_dbd_pgsql.c プロジェクト: QsBBQ/masspinger
static apr_status_t dbd_pgsql_datum_get(const apr_dbd_row_t *row, int n,
                                        apr_dbd_type_e type, void *data)
{
    if (PQgetisnull(row->res->res, row->n, n)) {
        return APR_ENOENT;
    }

    switch (type) {
    case APR_DBD_TYPE_TINY:
        *(char*)data = atoi(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_UTINY:
        *(unsigned char*)data = atoi(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_SHORT:
        *(short*)data = atoi(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_USHORT:
        *(unsigned short*)data = atoi(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_INT:
        *(int*)data = atoi(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_UINT:
        *(unsigned int*)data = atoi(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_LONG:
        *(long*)data = atol(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_ULONG:
        *(unsigned long*)data = atol(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_LONGLONG:
        *(apr_int64_t*)data = apr_atoi64(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_ULONGLONG:
        *(apr_uint64_t*)data = apr_atoi64(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_FLOAT:
        *(float*)data = (float)atof(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_DOUBLE:
        *(double*)data = atof(PQgetvalue(row->res->res, row->n, n));
        break;
    case APR_DBD_TYPE_STRING:
    case APR_DBD_TYPE_TEXT:
    case APR_DBD_TYPE_TIME:
    case APR_DBD_TYPE_DATE:
    case APR_DBD_TYPE_DATETIME:
    case APR_DBD_TYPE_TIMESTAMP:
    case APR_DBD_TYPE_ZTIMESTAMP:
        *(char**)data = PQgetvalue(row->res->res, row->n, n);
        break;
    case APR_DBD_TYPE_BLOB:
    case APR_DBD_TYPE_CLOB:
        {
        apr_bucket *e;
        apr_bucket_brigade *b = (apr_bucket_brigade*)data;

        e = apr_bucket_pool_create(PQgetvalue(row->res->res, row->n, n),
                                   PQgetlength(row->res->res, row->n, n),
                                   row->res->pool, b->bucket_alloc);
        APR_BRIGADE_INSERT_TAIL(b, e);
        }
        break;
    case APR_DBD_TYPE_NULL:
        *(void**)data = NULL;
        break;
    default:
        return APR_EGENERAL;
    }

    return APR_SUCCESS;
}
コード例 #30
0
ファイル: sessions.c プロジェクト: abbra/mod_auth_gssapi
void mag_check_session(request_rec *req,
                       struct mag_config *cfg, struct mag_conn **conn)
{
    struct mag_conn *mc;
    apr_status_t rc;
    session_rec *sess = NULL;
    const char *sessval = NULL;
    int declen;
    struct databuf ctxbuf = { 0 };
    struct databuf cipherbuf = { 0 };
    char *next, *last;
    time_t expiration;

    rc = mag_session_load(req, &sess);
    if (rc != OK || sess == NULL) {
        ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, 0, req,
                      "Sessions not available, no cookies!");
        return;
    }

    mc = *conn;
    if (!mc) {
        mc = apr_pcalloc(req->pool, sizeof(struct mag_conn));
        if (!mc) return;

        mc->parent = req->pool;
        *conn = mc;
    }

    rc = mag_session_get(req, sess, MAG_BEARER_KEY, &sessval);
    if (rc != OK) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
                      "Failed to get session data!");
        return;
    }
    if (!sessval) {
        /* no session established, just return */
        return;
    }

    if (!cfg->mag_skey) {
        ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, req,
                      "Session key not available, no cookies!");
        /* we do not have a key, just return */
        return;
    }

    /* decode it */
    declen = apr_base64_decode_len(sessval);
    cipherbuf.value = apr_palloc(req->pool, declen);
    if (!cipherbuf.value) return;
    cipherbuf.length = (int)apr_base64_decode((char *)cipherbuf.value, sessval);

    rc = UNSEAL_BUFFER(req->pool, cfg->mag_skey, &cipherbuf, &ctxbuf);
    if (rc != OK) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, req,
                      "Failed to unseal session data!");
        return;
    }

    /* get time */
    next = apr_strtok((char *)ctxbuf.value, ":", &last);
    expiration = (time_t)apr_atoi64(next);
    if (expiration < time(NULL)) {
        /* credentials fully expired, return nothing */
        return;
    }

    /* user name is next */
    next = apr_strtok(NULL, ":", &last);
    mc->user_name = apr_pstrdup(mc->parent, next);
    if (!mc->user_name) return;

    /* gssapi name (often a principal) is last.
     * (because it may contain the separator as a valid char we
     * just read last as is, without further tokenizing */
    mc->gss_name = apr_pstrdup(mc->parent, last);
    if (!mc->gss_name) return;

    /* OK we have a valid token */
    mc->established = true;
}