コード例 #1
0
ファイル: apr_strings.c プロジェクト: Ga-vin/apache
APR_DECLARE(char *) apr_strfsize(apr_off_t size, char *buf)
{
    const char ord[] = "KMGTPE";
    const char *o = ord;
    int remain;

    if (size < 0) {
        return strcpy(buf, "  - ");
    }
    if (size < 973) {
        if (apr_snprintf(buf, 5, "%3d ", (int) size) < 0)
            return strcpy(buf, "****");
        return buf;
    }
    do {
        remain = (int)(size & 1023);
        size >>= 10;
        if (size >= 973) {
            ++o;
            continue;
        }
        if (size < 9 || (size == 9 && remain < 973)) {
            if ((remain = ((remain * 5) + 256) / 512) >= 10)
                ++size, remain = 0;
            if (apr_snprintf(buf, 5, "%d.%d%c", (int) size, remain, *o) < 0)
                return strcpy(buf, "****");
            return buf;
        }
        if (remain >= 512)
            ++size;
        if (apr_snprintf(buf, 5, "%3d%c", (int) size, *o) < 0)
            return strcpy(buf, "****");
        return buf;
    } while (1);
}
コード例 #2
0
ファイル: mpf_stream.c プロジェクト: odmanV2/freecenter
/** Trace media path */
MPF_DECLARE(void) mpf_audio_stream_trace(mpf_audio_stream_t *stream, mpf_stream_direction_e direction, apt_text_stream_t *output)
{
	if(stream->vtable->trace) {
		stream->vtable->trace(stream,direction,output);
		return;
	}

	if(direction & STREAM_DIRECTION_SEND) {
		mpf_codec_descriptor_t *descriptor = stream->tx_descriptor;
		if(descriptor) {
			apr_size_t offset = output->pos - output->text.buf;
			output->pos += apr_snprintf(output->pos, output->text.length - offset,
				"[%s/%d/%d]->Sink",
				descriptor->name.buf,
				descriptor->sampling_rate,
				descriptor->channel_count);
		}
	}
	if(direction & STREAM_DIRECTION_RECEIVE) {
		mpf_codec_descriptor_t *descriptor = stream->rx_descriptor;
		if(descriptor) {
			apr_size_t offset = output->pos - output->text.buf;
			output->pos += apr_snprintf(output->pos, output->text.length - offset,
				"Source->[%s/%d/%d]",
				descriptor->name.buf,
				descriptor->sampling_rate,
				descriptor->channel_count);
		}
	}
}
コード例 #3
0
ファイル: h2_bucket_beam.c プロジェクト: yewang15215/mod_h2
apr_size_t h2_util_bl_print(char *buffer, apr_size_t bmax, 
                            const char *tag, const char *sep, 
                            h2_blist *bl)
{
    apr_size_t off = 0;
    const char *sp = "";
    apr_bucket *b;
    
    if (bl) {
        memset(buffer, 0, bmax--);
        off += apr_snprintf(buffer+off, bmax-off, "%s(", tag);
        for (b = H2_BLIST_FIRST(bl); 
             bmax && (b != H2_BLIST_SENTINEL(bl));
             b = APR_BUCKET_NEXT(b)) {
            
            off += h2_util_bucket_print(buffer+off, bmax-off, b, sp);
            sp = " ";
        }
        off += apr_snprintf(buffer+off, bmax-off, ")%s", sep);
    }
    else {
        off += apr_snprintf(buffer+off, bmax-off, "%s(null)%s", tag, sep);
    }
    return off;
}
コード例 #4
0
ファイル: userinfo.c プロジェクト: QsBBQ/masspinger
/* Internal sid binary to string translation, see MSKB Q131320.
 * Several user related operations require our SID to access
 * the registry, but in a string format.  All error handling
 * depends on IsValidSid(), which internally we better test long
 * before we get here!
 */
void get_sid_string(char *buf, apr_size_t blen, apr_uid_t id)
{
    PSID_IDENTIFIER_AUTHORITY psia;
    DWORD nsa;
    DWORD sa;
    int slen;

    /* Determine authority values (these is a big-endian value, 
     * and NT records the value as hex if the value is > 2^32.)
     */
    psia = GetSidIdentifierAuthority(id);
    nsa =  (DWORD)(psia->Value[5])        + ((DWORD)(psia->Value[4]) <<  8)
        + ((DWORD)(psia->Value[3]) << 16) + ((DWORD)(psia->Value[2]) << 24);
    sa  =  (DWORD)(psia->Value[1])        + ((DWORD)(psia->Value[0]) <<  8);
    if (sa) {
        slen = apr_snprintf(buf, blen, "S-%lu-0x%04x%08x",
                            SID_REVISION, sa, nsa);
    } else {
        slen = apr_snprintf(buf, blen, "S-%lu-%lu",
                            SID_REVISION, nsa);
    }

    /* Now append all the subauthority strings.
     */
    nsa = *GetSidSubAuthorityCount(id);
    for (sa = 0; sa < nsa; ++sa) {
        slen += apr_snprintf(buf + slen, blen - slen, "-%lu",
                             *GetSidSubAuthority(id, sa));
    }
} 
コード例 #5
0
ファイル: testhash.c プロジェクト: ohmann/checkapi
static void dump_hash(apr_pool_t *p, apr_hash_t *h, char str[][MAX_LTH])
{
    apr_hash_index_t *hi;
    int i = 0;

    for (hi = apr_hash_first(p, h); hi; hi = apr_hash_next(hi)) {
        const char *key = apr_hash_this_key(hi);
        apr_ssize_t len = apr_hash_this_key_len(hi);
        char *val = apr_hash_this_val(hi);

        str[i][0]='\0';
        apr_snprintf(str[i], MAX_LTH, "%sKey %s (%" APR_SSIZE_T_FMT ") Value %s\n",
                 str[i], key, len, val);
        i++;
    }
    str[i][0]='\0';
    apr_snprintf(str[i], MAX_LTH, "%s#entries %d\n", str[i], i);

    /* Sort the result strings so that they can be checked for expected results easily,
     * without having to worry about platform quirks
     */
    qsort(
        str, /* Pointer to elements */
        i,   /* number of elements */
        MAX_LTH, /* size of one element */
        comp_string /* Pointer to comparison routine */
    );
}
コード例 #6
0
ファイル: testargs.c プロジェクト: ohmann/checkapi
static void format_arg(char *str, char option, const char *arg)
{
    if (arg) {
        apr_snprintf(str, 8196, "%soption: %c with %s\n", str, option, arg);
    }
    else {
        apr_snprintf(str, 8196, "%soption: %c\n", str, option);
    }
}
コード例 #7
0
ファイル: apr_dbd.c プロジェクト: dtrebbien/apr
APR_DECLARE(apr_status_t) apr_dbd_get_driver(apr_pool_t *pool, const char *name,
                                             const apr_dbd_driver_t **driver)
{
#if APR_HAVE_MODULAR_DSO
    char modname[32];
    char symname[34];
    apr_dso_handle_sym_t symbol;
#endif
    apr_status_t rv;

#if APR_HAVE_MODULAR_DSO
    rv = apu_dso_mutex_lock();
    if (rv) {
        return rv;
    }
#endif
    *driver = apr_hash_get(drivers, name, APR_HASH_KEY_STRING);
    if (*driver) {
#if APR_HAVE_MODULAR_DSO
        apu_dso_mutex_unlock();
#endif
        return APR_SUCCESS;
    }

#if APR_HAVE_MODULAR_DSO
    /* The driver DSO must have exactly the same lifetime as the
     * drivers hash table; ignore the passed-in pool */
    pool = apr_hash_pool_get(drivers);

#if defined(NETWARE)
    apr_snprintf(modname, sizeof(modname), "dbd%s.nlm", name);
#elif defined(WIN32)
    apr_snprintf(modname, sizeof(modname),
                 "apr_dbd_%s-" APR_STRINGIFY(APR_MAJOR_VERSION) ".dll", name);
#else
    apr_snprintf(modname, sizeof(modname),
                 "apr_dbd_%s-" APR_STRINGIFY(APR_MAJOR_VERSION) ".so", name);
#endif
    apr_snprintf(symname, sizeof(symname), "apr_dbd_%s_driver", name);
    rv = apu_dso_load(NULL, &symbol, modname, symname, pool);
    if (rv == APR_SUCCESS || rv == APR_EINIT) { /* previously loaded?!? */
        *driver = symbol;
        name = apr_pstrdup(pool, name);
        apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver);
        rv = APR_SUCCESS;
        if ((*driver)->init) {
            (*driver)->init(pool);
        }
    }
    apu_dso_mutex_unlock();

#else /* not builtin and !APR_HAS_DSO => not implemented */
    rv = APR_ENOTIMPL;
#endif

    return rv;
}
コード例 #8
0
ファイル: apt_log.c プロジェクト: Jared-Prime/UniMRCP
static apt_bool_t apt_do_log(apt_log_priority_e priority, const char *format, va_list arg_ptr)
{
    char log_entry[MAX_LOG_ENTRY_SIZE];
    apr_size_t offset = 0;
    apr_time_exp_t result;
    apr_time_t now = apr_time_now();
    apr_time_exp_lt(&result,now);

    if(apt_logger.header & APT_LOG_HEADER_DATE) {
        offset += apr_snprintf(log_entry+offset,MAX_LOG_ENTRY_SIZE-offset,"%4d-%02d-%02d ",
                               result.tm_year+1900,
                               result.tm_mon+1,
                               result.tm_mday);
    }
    if(apt_logger.header & APT_LOG_HEADER_TIME) {
        offset += apr_snprintf(log_entry+offset,MAX_LOG_ENTRY_SIZE-offset,"%02d:%02d:%02d:%06d ",
                               result.tm_hour,
                               result.tm_min,
                               result.tm_sec,
                               result.tm_usec);
    }
    if(apt_logger.header & APT_LOG_HEADER_PRIORITY) {
        memcpy(log_entry+offset,priority_snames[priority],MAX_PRIORITY_NAME_LENGTH);
        offset += MAX_PRIORITY_NAME_LENGTH;
    }

    offset += apr_vsnprintf(log_entry+offset,MAX_LOG_ENTRY_SIZE-offset,format,arg_ptr);
    log_entry[offset++] = '\n';
    log_entry[offset] = '\0';
    if((apt_logger.mode & APT_LOG_OUTPUT_CONSOLE) == APT_LOG_OUTPUT_CONSOLE) {
        printf(log_entry);
    }

    if((apt_logger.mode & APT_LOG_OUTPUT_FILE) == APT_LOG_OUTPUT_FILE && apt_logger.file) {
        apr_thread_mutex_lock(apt_logger.mutex);

        apt_logger.cur_size += offset;
        if(apt_logger.cur_size > apt_logger.max_size) {
            /* roll over */
            fseek(apt_logger.file,0,SEEK_SET);
            apt_logger.cur_size = offset;
        }
        /* write to log file */
        fwrite(log_entry,1,offset,apt_logger.file);
        fflush(apt_logger.file);

        apr_thread_mutex_unlock(apt_logger.mutex);
    }
    return TRUE;
}
コード例 #9
0
ファイル: config_cache.c プロジェクト: cephurs/pkg-nxlog-ce
boolean nx_config_cache_get_string(const char *module, const char *key, const char **result)
{
    nx_ctx_t *ctx;
    nx_cc_item_t *item;
    char ckey[NX_CONFIG_CACHE_MAX_KEYLEN];

    ASSERT(module != NULL);
    ASSERT(key != NULL);

    ctx = nx_ctx_get();

    if ( apr_snprintf(ckey, sizeof(ckey), "%s/%s", module, key) == sizeof(ckey) )
    {
	nx_panic("config cache key too long, limit is %d bytes", NX_CONFIG_CACHE_MAX_KEYLEN);
    }

    CHECKERR(apr_thread_mutex_lock(ctx->config_cache_mutex));
    item = (nx_cc_item_t *) apr_hash_get(ctx->config_cache, ckey, APR_HASH_KEY_STRING);
    CHECKERR(apr_thread_mutex_unlock(ctx->config_cache_mutex));

    if ( item == NULL )
    {
	return ( FALSE );
    }

    if ( (strcmp(item->key, ckey) == 0) && (item->value->type == NX_VALUE_TYPE_STRING) )
    {
	ASSERT(item->value->string != NULL);
	*result = item->value->string->buf;
	item->used = TRUE;
	return ( TRUE );
    }

    return ( FALSE );
}
コード例 #10
0
static void mpf_mixer_trace(mpf_object_t *object)
{
	mpf_mixer_t *mixer = (mpf_mixer_t*) object;
	apr_size_t i;
	mpf_audio_stream_t *source;
	char buf[2048];
	apr_size_t offset;

	apt_text_stream_t output;
	apt_text_stream_init(&output,buf,sizeof(buf)-1);

	for(i=0; i<mixer->source_count; i++)	{
		source = mixer->source_arr[i];
		if(source) {
			mpf_audio_stream_trace(source,STREAM_DIRECTION_RECEIVE,&output);
			apt_text_char_insert(&output,';');
		}
	}

	offset = output.pos - output.text.buf;
	output.pos += apr_snprintf(output.pos, output.text.length - offset,
		"->Mixer->");

	mpf_audio_stream_trace(mixer->sink,STREAM_DIRECTION_SEND,&output);

	*output.pos = '\0';
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Media Path %s %s",
		object->name,
		output.text.buf);
}
コード例 #11
0
ファイル: tstnull.c プロジェクト: cookrn/openamq
static void
report_unrecognised_event_error (smt_thread_t *thread)
{
    int
        thread_type;
    smt_state_t
        state_id;
    smt_event_t
        event_id;
    smt_state_t
        nextstate_id;
    char
        num_buffer[8],
        *event_name_or_number;
        
    find_thread_state_next_state (&thread_type,
                                  &state_id,
                                  &event_id,
                                  &nextstate_id,
                                  thread);
    if (thread->_next_event >= 0
    &&  thread->_next_event <  tblsize (event_name))
        event_name_or_number = (char *) event_name[thread->_next_event];
    else {
        apr_snprintf (num_buffer, sizeof (num_buffer), "%u", (unsigned) thread->_next_event);
        event_name_or_number = num_buffer;
    }
    icl_console_print ("tstnull: Unrecognised event '%s' in '%s' thread number: %u, state: %s",
                       event_name_or_number,
                       thread_name [thread_type],
                       thread->id,
                       state_name  [state_id]);
    abort ();
}
コード例 #12
0
/*
 * Canonicalize scgi-like URLs.
 */
static int scgi_canon(request_rec *r, char *url)
{
    char *host, sport[sizeof(":65535")];
    const char *err, *path;
    apr_port_t port = SCGI_DEFAULT_PORT;

    if (strncasecmp(url, SCHEME "://", sizeof(SCHEME) + 2)) {
        return DECLINED;
    }
    url += sizeof(SCHEME); /* Keep slashes */

    err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
    if (err) {
        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                      "error parsing URL %s: %s", url, err);
        return HTTP_BAD_REQUEST;
    }
        
    apr_snprintf(sport, sizeof(sport), ":%u", port);
        
    if (ap_strchr(host, ':')) { /* if literal IPv6 address */
        host = apr_pstrcat(r->pool, "[", host, "]", NULL);
    }

    path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
                             r->proxyreq);
    if (!path) {
        return HTTP_BAD_REQUEST;
    }

    r->filename = apr_pstrcat(r->pool, "proxy:" SCHEME "://", host, sport, "/",
                              path, NULL);
    r->path_info = apr_pstrcat(r->pool, "/", path, NULL);
    return OK;
}
コード例 #13
0
ファイル: teststr.c プロジェクト: ohmann/checkapi
static void snprintf_0NULL(abts_case *tc, void *data)
{
    int rv;

    rv = apr_snprintf(NULL, 0, "%sBAR", "FOO");
    ABTS_INT_EQUAL(tc, 6, rv);
}
コード例 #14
0
ファイル: debug.c プロジェクト: Alkzndr/freebsd
/* Print a formatted string using format FMT and argument-list AP,
 * prefixing each line of output with a debug header. */
static void
debug_vprintf(const char *fmt, va_list ap)
{
  FILE *output = debug_output;
  char prefix[80], buffer[1000];
  char *s = buffer;
  int n;

  if (output == NULL || quiet_mode())
    return;

  n = apr_snprintf(prefix, sizeof(prefix), DBG_FLAG "%s:%4ld: ",
                   debug_file, debug_line);
  assert(n < sizeof(prefix) - 1);
  n = apr_vsnprintf(buffer, sizeof(buffer), fmt, ap);
  assert(n < sizeof(buffer) - 1);
  do
    {
      char *newline = strchr(s, '\n');
      if (newline)
        *newline = '\0';

      fputs(prefix, output);
      fputs(s, output);
      fputc('\n', output);

      if (! newline)
        break;
      s = newline + 1;
    }
  while (*s);  /* print another line, except after a final newline */
}
コード例 #15
0
ファイル: prefork.c プロジェクト: kheradmand/Break
/* 
 * change directory for gprof to plop the gmon.out file
 * configure in httpd.conf:
 * GprofDir $RuntimeDir/   -> $ServerRoot/$RuntimeDir/gmon.out
 * GprofDir $RuntimeDir/%  -> $ServerRoot/$RuntimeDir/gprof.$pid/gmon.out
 */
static void chdir_for_gprof(void)
{
    core_server_config *sconf = 
	ap_get_module_config(ap_server_conf->module_config, &core_module);    
    char *dir = sconf->gprof_dir;
    const char *use_dir;

    if(dir) {
        apr_status_t res;
	char buf[512];
	int len = strlen(sconf->gprof_dir) - 1;
	if(*(dir + len) == '%') {
	    dir[len] = '\0';
	    apr_snprintf(buf, sizeof(buf), "%sgprof.%d", dir, (int)getpid());
	} 
	use_dir = ap_server_root_relative(pconf, buf[0] ? buf : dir);
	res = apr_dir_make(use_dir, 0755, pconf);
	if(res != APR_SUCCESS && !APR_STATUS_IS_EEXIST(res)) {
	    ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
			 "gprof: error creating directory %s", dir);
	}
    }
    else {
	use_dir = ap_server_root_relative(pconf, DEFAULT_REL_RUNTIMEDIR);
    }

    chdir(use_dir);
}
コード例 #16
0
ファイル: json.c プロジェクト: cephurs/pkg-nxlog-ce
static int yajl_parse_integer_cb(void *data, long long integerval)
{
    nx_json_parser_ctx_t *ctx;
    char intstr[32];

    ctx = (nx_json_parser_ctx_t *) data;

    //log_info("integer_cb");

    if ( (ctx->in_array > 0) || (ctx->in_map > 0) )
    {
	apr_snprintf(intstr, sizeof(intstr), "%lld", integerval);
	nx_string_append(ctx->tmpstr, intstr, -1);
	nx_string_append(ctx->tmpstr, ",", 1);

	return ( 1 );
    }  

    if ( ctx->key == NULL )
    {
	throw_msg("map key name not found");
    }

    nx_logdata_set_integer(ctx->logdata, ctx->key, (int64_t) integerval);
    free(ctx->key);
    ctx->key = NULL;

    return ( 1 );
}
コード例 #17
0
ファイル: writer.c プロジェクト: despegar/mod_tee
/*
 * Sets into the saved_request the designated filename, according to configured base
 * directory and request data (URI, headers, etc). Also creates the base directory if it
 * doesn't exist
 */
static int set_filename(tee_saved_request *sr)
{
	apr_time_exp_t t;
	apr_time_exp_gmt(&t, sr->time_enqueued);

	// Obtaining directory name
	const char *dir;
	dir = apr_psprintf(sr->pool, "%s/%04d%02d%02d/%02d",
			sr->base_dir, 1900 + t.tm_year, t.tm_mon + 1, t.tm_mday, t.tm_hour);

	// Creating directory if needed
	apr_status_t rc = apr_dir_make_recursive(dir, APR_FPROT_OS_DEFAULT, sr->pool);
	if (rc != APR_SUCCESS) {
		ap_log_error(APLOG_MARK, APLOG_ERR, 0, sr->server, "tee: Cannot create directory %s: %s",
				dir, tee_get_error_string(rc, sr->pool));
		return 1;
	}

	// Setting file name
	unsigned long file_id = ((unsigned long) t.tm_min * 60 + t.tm_sec) * 1000000 + t.tm_usec; // usec in hour
	char b[MAX_FILENAME_LEN]; // Filename is cut in case the URI is too long
	const char *rec_id = get_header_value(sr, sr->id_header, "");
	const char *host = get_header_value(sr, "Host", "");
	apr_snprintf(b, MAX_FILENAME_LEN, "%010lu_%s_%s_%s%s", file_id, rec_id, sr->method, host, sr->uri);
	tee_replace(b, "/", '_'); // Replace the slash (invalid character in file names)
	sr->filename = apr_psprintf(sr->pool, "%s/%s_%d", dir, b, sr->status);
	return 0;
}
コード例 #18
0
/** Generate mrcp request-id list */
static apt_bool_t mrcp_request_id_list_generate(const mrcp_request_id_list_t *request_id_list, apt_str_t *str, apr_pool_t *pool)
{
	apr_size_t i;
	int length;
	char *pos;

	/* compute estimated length, assuming request-ids consist of upto 10 digits */
	str->length = 10 * request_id_list->count;
	if(request_id_list->count > 1) {
		/* , */
		str->length += request_id_list->count - 1;
	}

	str->buf = apr_palloc(pool,str->length + 1);

	pos = str->buf;
	for(i=0; i<request_id_list->count; i++) {
		if(i != 0) {
			*pos++ = ',';
		}

		length = apr_snprintf(pos, str->length - (pos - str->buf), "%"MRCP_REQUEST_ID_FMT, request_id_list->ids[i]);
		if(length < 0)
			return FALSE;
		pos += length;
	}
	*pos = '\0';
	return TRUE;
}
コード例 #19
0
ファイル: ssl_util_ssl.c プロジェクト: pexip/os-apache2
/*
 * convert an X509_NAME to an RFC 2253 formatted string, optionally truncated
 * to maxlen characters (specify a maxlen of 0 for no length limit)
 */
char *modssl_X509_NAME_to_string(apr_pool_t *p, X509_NAME *dn, int maxlen)
{
    char *result = NULL;
    BIO *bio;
    int len;

    if ((bio = BIO_new(BIO_s_mem())) == NULL)
        return NULL;
    X509_NAME_print_ex(bio, dn, 0, XN_FLAG_RFC2253);
    len = BIO_pending(bio);
    if (len > 0) {
        result = apr_palloc(p, (maxlen > 0) ? maxlen+1 : len+1);
        if (maxlen > 0 && maxlen < len) {
            len = BIO_read(bio, result, maxlen);
            if (maxlen > 2) {
                /* insert trailing ellipsis if there's enough space */
                apr_snprintf(result + maxlen - 3, 4, "...");
            }
        } else {
            len = BIO_read(bio, result, len);
        }
        result[len] = NUL;
    }
    BIO_free(bio);

    return result;
}
コード例 #20
0
ファイル: modsecurity.c プロジェクト: mrG7/modsec-api
static int is_response_status_relevant(modsec_rec *msr, int status) {
    char *my_error_msg = NULL;
    apr_status_t rc;
    char buf[32];

    /* ENH: Setting is_relevant here will cause an audit even if noauditlog
     * was set for the last rule that matched.  Is this what we want?
     */

    if ((msr->txcfg->auditlog_relevant_regex == NULL)
        ||(msr->txcfg->auditlog_relevant_regex == NOT_SET_P))
    {
        return 0;
    }

    apr_snprintf(buf, sizeof(buf), "%d", status);

    rc = msc_regexec(msr->txcfg->auditlog_relevant_regex, buf, strlen(buf), &my_error_msg);
    if (rc >= 0) return 1;
    if (rc == PCRE_ERROR_NOMATCH) return 0;

    msr_log(msr, 1, "Regex processing failed (rc %d): %s", rc, my_error_msg);
    
    return 0;
}
コード例 #21
0
ファイル: teststr.c プロジェクト: kheradmand/Break
static void snprintf_0NULL(CuTest *tc)
{
    int rv;

    rv = apr_snprintf(NULL, 0, "%sBAR", "FOO");
    CuAssertIntEquals(tc, 6, rv);
}
コード例 #22
0
ファイル: util_pcre.c プロジェクト: Alivx/apache2nginx
AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg,
                                   char *errbuf, apr_size_t errbuf_size)
{
const char *message, *addmessage;
apr_size_t length, addlength;

message = (errcode >= (int)(sizeof(pstring)/sizeof(char *)))?
  "unknown error code" : pstring[errcode];
length = strlen(message) + 1;

addmessage = " at offset ";
addlength = (preg != NULL && (int)preg->re_erroffset != -1)?
  strlen(addmessage) + 6 : 0;

if (errbuf_size > 0)
  {
  if (addlength > 0 && errbuf_size >= length + addlength)
      apr_snprintf(errbuf, sizeof errbuf,
                   "%s%s%-6d", message, addmessage, (int)preg->re_erroffset);
  else
    {
    strncpy(errbuf, message, errbuf_size - 1);
    errbuf[errbuf_size-1] = 0;
    }
  }

return length + addlength;
}
コード例 #23
0
ファイル: teststr.c プロジェクト: kheradmand/Break
static void snprintf_int64(CuTest *tc)
{
    char buf[100];
    apr_int64_t i = APR_INT64_C(-42);
    apr_uint64_t ui = APR_INT64_C(42); /* no APR_UINT64_C */
    apr_uint64_t big = APR_INT64_C(3141592653589793238);

    apr_snprintf(buf, sizeof buf, "%" APR_INT64_T_FMT, i);
    CuAssertStrEquals(tc, buf, "-42");

    apr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, ui);
    CuAssertStrEquals(tc, buf, "42");

    apr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, big);
    CuAssertStrEquals(tc, buf, "3141592653589793238");
}
コード例 #24
0
ファイル: proc_mutex.c プロジェクト: AAthresh/quantlib
static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex,
                                            const char *fname)
{
    sem_t *psem;
    char semname[31];
    apr_time_t now;
    unsigned long sec;
    unsigned long usec;
    
    new_mutex->interproc = apr_palloc(new_mutex->pool,
                                      sizeof(*new_mutex->interproc));
    /*
     * This bogusness is to follow what appears to be the
     * lowest common denominator in Posix semaphore naming:
     *   - start with '/'
     *   - be at most 14 chars
     *   - be unique and not match anything on the filesystem
     *
     * Because of this, we ignore fname, and try our
     * own naming system. We tuck the name away, since it might
     * be useful for debugging. to  make this as robust as possible,
     * we initially try something larger (and hopefully more unique)
     * and gracefully fail down to the LCD above.
     *
     * NOTE: Darwin (Mac OS X) seems to be the most restrictive
     * implementation. Versions previous to Darwin 6.2 had the 14
     * char limit, but later rev's allow up to 31 characters.
     *
     * FIXME: There is a small window of opportunity where
     * instead of getting a new semaphore descriptor, we get
     * a previously obtained one. This can happen if the requests
     * are made at the "same time" and in the small span of time between
     * the sem_open and the sem_unlink. Use of O_EXCL does not
     * help here however...
     *
     */
    now = apr_time_now();
    sec = apr_time_sec(now);
    usec = apr_time_usec(now);
    apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec);
    psem = sem_open(semname, O_CREAT, 0644, 1);
    if ((psem == (sem_t *)SEM_FAILED) && (errno == ENAMETOOLONG)) {
        /* Oh well, good try */
        semname[13] = '\0';
        psem = sem_open(semname, O_CREAT, 0644, 1);
    }

    if (psem == (sem_t *)SEM_FAILED) {
        return errno;
    }
    /* Ahhh. The joys of Posix sems. Predelete it... */
    sem_unlink(semname);
    new_mutex->psem_interproc = psem;
    new_mutex->fname = apr_pstrdup(new_mutex->pool, semname);
    apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex,
                              apr_proc_mutex_cleanup, 
                              apr_pool_cleanup_null);
    return APR_SUCCESS;
}
コード例 #25
0
ファイル: testhash.c プロジェクト: TaoheGit/hmi_sdl_android
static void dump_hash(apr_pool_t *p, apr_hash_t *h, char *str) 
{
    apr_hash_index_t *hi;
    char *val, *key;
    apr_ssize_t len;
    int i = 0;

    str[0] = '\0';

    for (hi = apr_hash_first(p, h); hi; hi = apr_hash_next(hi)) {
        apr_hash_this(hi,(void*) &key, &len, (void*) &val);
        apr_snprintf(str, 8196, "%sKey %s (%" APR_SSIZE_T_FMT ") Value %s\n", 
                     str, key, len, val);
        i++;
    }
    apr_snprintf(str, 8196, "%s#entries %d\n", str, i);
}
コード例 #26
0
ファイル: teststr.c プロジェクト: kheradmand/Break
static void snprintf_underflow(CuTest *tc)
{
    char buf[20];
    int rv;

    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001);
    CuAssertIntEquals(tc, 4, rv);
    CuAssertStrEquals(tc, "0.00", buf);
    
    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001);
    CuAssertIntEquals(tc, 4, rv);
    CuAssertStrEquals(tc, "0.00", buf);
    
    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01);
    CuAssertIntEquals(tc, 4, rv);
    CuAssertStrEquals(tc, "0.01", buf);
}
コード例 #27
0
ファイル: teststr.c プロジェクト: ohmann/checkapi
static void snprintf_underflow(abts_case *tc, void *data)
{
    char buf[20];
    int rv;

    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.0001);
    ABTS_INT_EQUAL(tc, 4, rv);
    ABTS_STR_EQUAL(tc, "0.00", buf);

    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.001);
    ABTS_INT_EQUAL(tc, 4, rv);
    ABTS_STR_EQUAL(tc, "0.00", buf);

    rv = apr_snprintf(buf, sizeof buf, "%.2f", (double)0.01);
    ABTS_INT_EQUAL(tc, 4, rv);
    ABTS_STR_EQUAL(tc, "0.01", buf);
}
コード例 #28
0
ファイル: apt_log.c プロジェクト: odmanV2/freecenter
static apt_bool_t apt_do_log(const char *file, int line, apt_log_priority_e priority, const char *format, va_list arg_ptr)
{
	char log_entry[MAX_LOG_ENTRY_SIZE];
	apr_size_t max_size = MAX_LOG_ENTRY_SIZE - 2;
	apr_size_t offset = 0;
	apr_time_exp_t result;
	apr_time_t now = apr_time_now();
	apr_time_exp_lt(&result,now);

	if(apt_logger->header & APT_LOG_HEADER_DATE) {
		offset += apr_snprintf(log_entry+offset,max_size-offset,"%4d-%02d-%02d ",
							result.tm_year+1900,
							result.tm_mon+1,
							result.tm_mday);
	}
	if(apt_logger->header & APT_LOG_HEADER_TIME) {
		offset += apr_snprintf(log_entry+offset,max_size-offset,"%02d:%02d:%02d:%06d ",
							result.tm_hour,
							result.tm_min,
							result.tm_sec,
							result.tm_usec);
	}
	if(apt_logger->header & APT_LOG_HEADER_MARK) {
		offset += apr_snprintf(log_entry+offset,max_size-offset,"%s:%03d ",file,line);
	}
	if(apt_logger->header & APT_LOG_HEADER_THREAD) {
		offset += apr_snprintf(log_entry+offset,max_size-offset,"%05lu ",apt_thread_id_get());
	}
	if(apt_logger->header & APT_LOG_HEADER_PRIORITY) {
		memcpy(log_entry+offset,priority_snames[priority],MAX_PRIORITY_NAME_LENGTH);
		offset += MAX_PRIORITY_NAME_LENGTH;
	}

	offset += apr_vsnprintf(log_entry+offset,max_size-offset,format,arg_ptr);
	log_entry[offset++] = '\n';
	log_entry[offset] = '\0';
	if((apt_logger->mode & APT_LOG_OUTPUT_CONSOLE) == APT_LOG_OUTPUT_CONSOLE) {
		fwrite(log_entry,offset,1,stdout);
	}
	
	if((apt_logger->mode & APT_LOG_OUTPUT_FILE) == APT_LOG_OUTPUT_FILE && apt_logger->file_data) {
		apt_log_file_dump(apt_logger->file_data,log_entry,offset);
	}
	return TRUE;
}
コード例 #29
0
ファイル: teststr.c プロジェクト: kheradmand/Break
static void snprintf_0nonNULL(CuTest *tc)
{
    int rv;
    char *buff = "testing";

    rv = apr_snprintf(buff, 0, "%sBAR", "FOO");
    CuAssertIntEquals(tc, 6, rv);
    CuAssert(tc, "buff unmangled", strcmp(buff, "FOOBAR") != 0);
}
コード例 #30
0
ファイル: mod_usertrack.c プロジェクト: AzerTyQsdF/osx
static void make_cookie(request_rec *r)
{
    cookie_log_state *cls = ap_get_module_config(r->server->module_config,
                                                 &usertrack_module);
    char cookiebuf[2 * (sizeof(apr_uint64_t) + sizeof(int)) + 2];
    unsigned int random;
    apr_time_t now = r->request_time ? r->request_time : apr_time_now();
    char *new_cookie;
    cookie_dir_rec *dcfg;

    ap_random_insecure_bytes(&random, sizeof(random));
    apr_snprintf(cookiebuf, sizeof(cookiebuf), "%x.%" APR_UINT64_T_HEX_FMT,
                 random, (apr_uint64_t)now);
    dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module);
    if (cls->expires) {

        /* Cookie with date; as strftime '%a, %d-%h-%y %H:%M:%S GMT' */
        new_cookie = apr_psprintf(r->pool, "%s=%s; path=/",
                                  dcfg->cookie_name, cookiebuf);

        if ((dcfg->style == CT_UNSET) || (dcfg->style == CT_NETSCAPE)) {
            apr_time_exp_t tms;
            apr_time_exp_gmt(&tms, r->request_time
                                 + apr_time_from_sec(cls->expires));
            new_cookie = apr_psprintf(r->pool,
                                       "%s; expires=%s, "
                                       "%.2d-%s-%.2d %.2d:%.2d:%.2d GMT",
                                       new_cookie, apr_day_snames[tms.tm_wday],
                                       tms.tm_mday,
                                       apr_month_snames[tms.tm_mon],
                                       tms.tm_year % 100,
                                       tms.tm_hour, tms.tm_min, tms.tm_sec);
        }
        else {
            new_cookie = apr_psprintf(r->pool, "%s; max-age=%d",
                                      new_cookie, cls->expires);
        }
    }
    else {
        new_cookie = apr_psprintf(r->pool, "%s=%s; path=/",
                                  dcfg->cookie_name, cookiebuf);
    }
    if (dcfg->cookie_domain != NULL) {
        new_cookie = apr_pstrcat(r->pool, new_cookie, "; domain=",
                                 dcfg->cookie_domain,
                                 (dcfg->style == CT_COOKIE2
                                  ? "; version=1"
                                  : ""),
                                 NULL);
    }

    apr_table_addn(r->err_headers_out,
                   (dcfg->style == CT_COOKIE2 ? "Set-Cookie2" : "Set-Cookie"),
                   new_cookie);
    apr_table_setn(r->notes, "cookie", apr_pstrdup(r->pool, cookiebuf));   /* log first time */
    return;
}