Exemplo n.º 1
0
/*
 * jsonwr_log10num_value
 * Write a number that has been converted into log base 10
 * because it may be too small to represent.
 */
void jsonwr_log10num_value(JSONWR_T* jsonwr, double value, int prec) {
  double m, e;
  m = 0;
  e = 0;
  if (value > -HUGE_VAL && value < HUGE_VAL) { // normal value
    e = floor(value);
    m = pow(10.0, value - e);
    // check that rounding up won't cause a 9.9999 to go to a 10
    if (m + (.5 * pow(10,-prec)) >= 10) {
      m = 1;
      e += 1;
    }
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, m, e);
    write_value(jsonwr);
  } else if (value >= HUGE_VAL) { // infinity
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"inf\"");
    write_value(jsonwr);
  } else { // negative infinity
    str_clear(jsonwr->value_buf);
    // note that m and e are both 0, but it is important that we pass them
    // and not constants because if I pass a 0 then it is of int type which
    // takes up less space on the stack then the format string is expecting
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, m, e);
    write_value(jsonwr);
  }
}
Exemplo n.º 2
0
void
rq_clear(request_t *h)
{
	h->length = 0;
	h->done = 0;
	h->error = 0;
	h->state = ST_START;

	str_clear(&h->method_str);
	str_clear(&h->resource_str);
	str_clear(&h->protocol_str);

	str_clear(&h->host_str);
	str_clear(&h->upgrade_str);
	str_clear(&h->connection_str);
	str_clear(&h->ws_key_str);
	str_clear(&h->ws_protocol_str);
	str_clear(&h->ws_version_str);
	str_clear(&h->origin_str);
	h->protocols_head = NULL;
	h->protocol_count = 0;
	h->error_code = 0;
	h->fl_upgrade_found = 0;
	h->fl_connection_found = 0;
}
Exemplo n.º 3
0
int create_lpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type)
{
	dstring_t buf;
	int err;
	
	if (!dst) return -1;
	
	str_clear(dst);
	if (dst_content_type) str_clear(dst_content_type);

	if (!p) return -1;
	
	if (dst_content_type) {
		if (str_dup_zt(dst_content_type, "text/lpidf") < 0) {
			return -1;
		}
	}

/*	if (!p->first_tuple) return 0;*/	/* no tuples => nothing to say */ 
	
	dstr_init(&buf, 2048);
	
	doc_add_presentity(&buf, p);
	
	err = dstr_get_str(&buf, dst);
	dstr_destroy(&buf);
	
	if (err != 0) {
		str_free_content(dst);
		if (dst_content_type) str_free_content(dst_content_type);
	}
	
	return err;
}
Exemplo n.º 4
0
/*
 * jsonwr_log10num_value
 * Write a number that has been converted into log base 10
 * because it may be too small to represent.
 */
void jsonwr_log10num_value(JSONWR_T* jsonwr, double value, int prec) {
  double m, e;
  m = 0;
  e = 0;
  if (value > -HUGE_VAL && value < HUGE_VAL) { // normal value
    e = floor(value);
    m = exp10(value - e);
    // check that rounding up won't cause a 9.9999 to go to a 10
    if (m + (.5 * pow(10,-prec)) >= 10) {
      m = 1;
      e += 1;
    }
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, m, e);
    write_value(jsonwr);
  } else if (value >= HUGE_VAL) { // infinity
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"inf\"");
    write_value(jsonwr);
  } else { // negative infinity
    str_clear(jsonwr->value_buf);
    str_appendf(jsonwr->value_buf, "\"%.*fe%+04.0f\"", prec, 0, 0);
    write_value(jsonwr);
  }
}
Exemplo n.º 5
0
rl_subscription_t *rls_alloc_subscription(rls_subscription_type_t type)
{
	rl_subscription_t *s;
	
	s = (rl_subscription_t*)mem_alloc(sizeof(rl_subscription_t));
	if (!s) {
		LOG(L_ERR, "rls_alloc_subscription(): can't allocate memory\n");
		return NULL;
	}
	memset(s, 0, sizeof(*s));
	
	s->u.external.status = subscription_uninitialized;
	s->u.external.usr_data = s;
	s->doc_version = 0;
	s->changed = 0;
	s->type = type;
	s->dbid[0] = 0;

	/* s->first_vs = NULL;
	s->last_vs = NULL; */
	str_clear(&s->from_uid);
	ptr_vector_init(&s->vs, 4);
	
	return s;
}
Exemplo n.º 6
0
/* returns a part of string of given length - it is NOT a copy !!! */
int sstream_get_str_ex(sstream_t *ss, int len, str_t *dst)
{
	int l;
	int res = 0;
	
	if (!is_input_sstream(ss)) return -1;
	if (!dst) return -1;

	if (len == 0) {
		str_clear(dst);
		return 0;
	}
	
	l = ss->in.len - ss->in_pos;
	dst->s = ss->in.s + ss->in_pos;

	if (len > l) {
		dst->len = l;
		res = 1; /* not whole requested string is returned ! */
	}
	else dst->len = len;
	ss->in_pos += dst->len;
	
	return 0;
}
Exemplo n.º 7
0
/*
 * converts a string into a JSON allowed string and stores it
 * in the storage string builder.
 */
static void convert_string(STR_T* storage, const char* string) {
  const char *c;
  assert(storage != NULL);
  str_clear(storage);
  str_append(storage, "\"", 1);
  for (c = string; *c != '\0'; c++) {
    switch(*c) {
    case '"':
      str_append(storage, "\\\"", 2);
      break;
    case '\\':
      str_append(storage, "\\\\", 2);
      break;
    case '/':
      str_append(storage, "\\/", 2);
      break;
    case '\b':
      str_append(storage, "\\b", 2);
      break;
    case '\f':
      str_append(storage, "\\f", 2);
      break;
    case '\n':
      str_append(storage, "\\n", 2);
      break;
    case '\r':
      str_append(storage, "\\r", 2);
      break;
    default:
      str_append(storage, c, 1);
    }
  }
  str_append(storage, "\"", 1);
}
Exemplo n.º 8
0
static int
print_clfjson(void *ctx, str_t *str, logmeta_t *meta) {
    json_printer jp;
    str_clear(str);
    json_print_init(&jp, jp_callback, str); 

    char timestamp[50];
    memset(timestamp, 0, sizeof(timestamp));
    strftime(timestamp, sizeof(timestamp), "%d/%b/%Y:%H:%M:%S %z", &meta->utc_timestamp);

    json_print_raw(&jp, JSON_ARRAY_BEGIN, NULL, 0);    
        print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_C_IP));
        print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_CS_IDENT));
        print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_CS_USERNAME));
        json_print_raw(&jp, JSON_STRING, timestamp, strlen(timestamp));
        print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_CS_METHOD));
        print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_CS_URI_STEM));
        print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_SC_STATUS));
        print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_BYTES));
        if( ! logmeta_field_isempty(meta, LOGPIPE_CS_REFERER) ) {
            print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_CS_REFERER));
            if( ! logmeta_field_isempty(meta, LOGPIPE_CS_USER_AGENT) ) {
                print_strraw_or_null(&jp, logmeta_field(meta, LOGPIPE_CS_USER_AGENT));
            }
        }
    json_print_raw(&jp, JSON_ARRAY_END, NULL, 0);    
    json_print_free(&jp);
    return 1;
}
Exemplo n.º 9
0
/* Open the source file for reading, closing any previously open file.
   If dir_list is not NULL, calls search_file() to search the file in dir_list */
Bool SrcFile_open( SrcFile *self, char *filename, UT_array *dir_list )
{
    char *filename_path;
	
	/* close last file */
	if (self->file != NULL)
	{
		myfclose(self->file);
		self->file = NULL;
	}

	/* search path, add to strpool */
	filename_path = search_file(filename, dir_list);

	/* check for recursive includes, return if found */
	if (!check_recursive_include(self, filename_path))
		return FALSE;
	
	self->filename = filename_path;

    /* open new file in binary mode, for cross-platform newline processing */
    self->file = myfopen( self->filename, "rb" );

	/* init current line */
    str_clear( self->line );
    self->line_nr = 0;

	if (self->file)
		return TRUE;
	else
		return FALSE;		/* error opening file */
}
Exemplo n.º 10
0
void 
env_set(struct lacy_env *env, char *ident, char *value)
{
    struct page_attr *e = env_attr_lookup(env, ident);
    if (NULL == e) {

        e = malloc(sizeof(struct page_attr));
        e->next = NULL;
        str_init(&(e->name));
        str_init(&(e->value));

        str_append_str(&(e->name), ident);
        str_append_str(&(e->value), value);

        if (env->sym_tbl == NULL) {
            env->sym_tbl = e;
        }
        else {
            struct page_attr *t = env->sym_tbl;
            while (t->next != NULL) 
                t = t->next;
            
            t->next = e;
        }
    }
    else {
        str_clear(&(e->value));
        str_append_str(&(e->value), value);
    }
}
Exemplo n.º 11
0
static int db_add_watcher(presentity_t *_p, watcher_t *watcher)
{
	str_t tmp;
	db_key_t query_cols[20];
	db_val_t query_vals[20];
	
	int n_query_cols = 0;

	if (!use_db) return 0;
	
	str_clear(&tmp);

	if (pa_dbf.use_table(pa_db, watcherinfo_table) < 0) {
		LOG(L_ERR, "db_add_watcher: Error in use_table\n");
		return -1;
	}
	
	if (set_watcher_db_data(_p, watcher, 
				query_cols, query_vals, &n_query_cols,
				&tmp) != 0) {
		return -1;
	}

	/* insert new record into database */
	if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) {
		LOG(L_ERR, "db_add_watcher: Error while inserting watcher\n");
		str_free_content(&tmp);
		return -1;
	}
	str_free_content(&tmp);
	
	return 0;
}
Exemplo n.º 12
0
pstr  STDCALL gettempdir( pstr name )
{
   if ( !str_len( &_gentee.tempdir ))
   {
      uint   id = 0;
      str    path;
      pstr   ps;

      ps = &_gentee.tempdir;

      os_tempdir( str_init( &path ));

      while ( 1 )
      {
         str_clear( ps );
         str_printf( ps, (pubyte)("%s%cgentee%02X.tmp"), str_ptr( &path ), SLASH, id );
         _gentee.tempfile = os_fileopen( ps, FOP_CREATE | FOP_EXCLUSIVE );

         if ( !_gentee.tempfile )
         {
            if ( id++ > 0xFFFF )
               msg( MFileopen | MSG_STR | MSG_EXIT, ps );
         }
         else
            break;
      }
      os_dircreate( str_setlen( ps, str_len( ps ) - 4 ));
      str_delete( &path );
   }
   return str_copy( name, &_gentee.tempdir );

   //return str_copy( name, os_gettemp());
}
Exemplo n.º 13
0
static
int replace_cmd(struct main_server_st* s, proc_st *proc, 
		char **cmd, const char* pattern, 
		const char* route, const char* dev)
{
	str_st str;
	int ret;
	str_rep_tab tab[6];

	STR_TAB_SET(0, "%{R}", route);
	STR_TAB_SET(1, "%R", route);
	STR_TAB_SET(2, "%{D}", dev);
	STR_TAB_SET(3, "%D", dev);
	STR_TAB_SET_FUNC(4, "%{RI}", ipv4_route_to_cidr, route);
	STR_TAB_TERM(5);

	str_init(&str, proc);

	ret = str_append_str(&str, pattern);
	if (ret < 0)
		return ERR_MEM;

	ret = str_replace_str(&str, tab);
	if (ret < 0)
		goto fail;

	*cmd = (char*)str.data;

	return 0;
 fail:
	str_clear(&str);
	return ERR_MEM;
}
Exemplo n.º 14
0
void str_copy(str_t* dest, str_t* src)
{
    while (dest->size < src->n + 1) str_expand(dest);
    str_clear(dest);
    memcpy(dest->s, src->s, src->n);
    dest->n = src->n;
    dest->s[dest->n] = '\0';
}
Exemplo n.º 15
0
void
var_clear(struct variable *var)
{
	assert(var != NULL);

	mpl_clear(&var->bnum);
	str_clear(&var->str);
	octstr_clear(&var->octstr);
}
Exemplo n.º 16
0
/*
 * jsonwr_bool_value
 * Write a boolean value
 */
void jsonwr_bool_value(JSONWR_T* jsonwr, int value) {
  str_clear(jsonwr->value_buf);
  if (value) {
    str_append(jsonwr->value_buf, "true", 4);
  } else {
    str_append(jsonwr->value_buf, "false", 5);
  }
  write_value(jsonwr);
}
Exemplo n.º 17
0
/*-----------------------------------------------------------------------------
*   Output error message
*----------------------------------------------------------------------------*/
static void do_error( enum ErrType err_type, char *message )
{
	STR_DEFINE(msg, STR_SIZE);
    size_t len_at, len_prefix;

    init_module();

    /* init empty message */
    str_clear( msg );

    /* Information messages have no prefix */
    if ( err_type != ErrInfo )
    {
        str_append( msg, err_type == ErrWarn ? "Warning" : "Error" );

        /* prepare to remove " at" if no prefix */
        len_at = str_len(msg);
        str_append( msg, " at" );
        len_prefix = str_len(msg);

        /* output filename */
        if ( errors.filename && *errors.filename )
            str_append_sprintf( msg, " file '%s'", errors.filename );

        /* output module */
        if ( errors.module != NULL && *errors.module )
            str_append_sprintf( msg, " module '%s'", errors.module );

        /* output line number */
        if ( errors.line > 0 )
            str_append_sprintf( msg, " line %d", errors.line );

        /* remove at if no prefix */
        if ( len_prefix == str_len(msg) )	/* no prefix loaded to string */
        {
            str_data(msg)[ len_at ] = '\0';	/* go back 3 chars to before at */
            str_sync_len( msg );
        }

        str_append( msg, ": " );
    }

    /* output error message */
    str_append( msg, message );
    str_append_char( msg, '\n' );

    /* CH_0001 : Assembly error messages should appear on stderr */
    fputs( str_data(msg), stderr );

    /* send to error file */
    puts_error_file( str_data(msg) );

    if ( err_type == ErrError )
        errors.count++;		/* count number of errors */

	STR_DELETE(msg);
}
Exemplo n.º 18
0
END_TEST

START_TEST(test_str_clear)
{
	str_t *str = str_from_cstr("nsf");
	str_clear(str);
	CHECK_STR(str, >= 3, == 0, "");
	str_free(str);
}
Exemplo n.º 19
0
static inline int create_headers(struct watcher* _w, str *dst, str *content_type)
{
    dstring_t buf;
    time_t t;
    int err = 0;

    dstr_init(&buf, 256);
    str_clear(dst);

    /* required by RFC 3261 */
    dstr_append_zt(&buf, "Max-Forwards: 70\r\n");

    /* Event header */

    dstr_append_zt(&buf, "Event: ");
    dstr_append_zt(&buf, event_package2str(_w->event_package));
    dstr_append_zt(&buf, "\r\n");

    /* Content-Type header */

    /* content types can have dynamical parameters (multipart/related)
     * => don't generate them "staticaly"; use values created in the
     * time of document creation */
    if (!is_str_empty(content_type)) { /* documents without body doesn't need it */
        dstr_append_zt(&buf, "Content-Type: ");
        dstr_append_str(&buf, content_type);
        dstr_append_zt(&buf, "\r\n");
    }

    /* Contact header */

    if (is_str_empty(&_w->server_contact)) {
        LOG(L_WARN, "add_contact_hf(): Can't add empty contact to NOTIFY.\n");
    }
    else {
        dstr_append_zt(&buf, "Contact: ");
        dstr_append_str(&buf, &_w->server_contact);
        dstr_append_zt(&buf, "\r\n");
    }

    /* Subscription-State header */

    if (_w->expires) t = _w->expires - time(0);
    else t = 0;

    if (add_subs_state_hf(&buf, _w->status, t) < 0) {
        LOG(L_ERR, "create_headers(): Error while adding Subscription-State\n");
        dstr_destroy(&buf);
        return -3;
    }

    err = dstr_get_str(&buf, dst);
    dstr_destroy(&buf);

    return err;
}
Exemplo n.º 20
0
/* returns a copy of string from input buffer */
int sstream_get_str(sstream_t *ss, int len, str_t *dst)
{
	str_t tmp;
	int res = sstream_get_str_ex(ss, len, &tmp);
	if (res >= 0) {
		res = str_dup(dst, &tmp);
		if (res != 0) str_clear(dst);
	}
	return res;
}
Exemplo n.º 21
0
int init_output_sstream(sstream_t *ss, int out_buff_resize)
{
	if (!ss) return -1;
	
	ss->type = sstream_out;
	str_clear(&ss->in);
	ss->in_pos = 0;
	dstr_init(&ss->out, out_buff_resize);
	return 0;
}
Exemplo n.º 22
0
str_t* str_alloc()
{
    str_t* s = malloc_or_die(sizeof(str_t));
    s->s = malloc_or_die(init_str_size);
    s->n = 0;
    s->size = init_str_size;
    str_clear(s);

    return s;
}
Exemplo n.º 23
0
static void gtf_row_clear(gtf_row_t* row)
{
    /* Attributes must be cleared because they may not be overwritten.
     * Everything else is, so we can leave it. */

    str_clear(row->seqname);
    str_clear(row->source);
    str_clear(row->feature);

    str_map_pair* u;
    size_t i;
    for (i = 0; i < row->attributes->n; ++i) {
        u = row->attributes->A[i];
        while (u) {
            str_clear((str_t*)u->value);
            u = u->next;
        }
    }
}
Exemplo n.º 24
0
struct tree_node *
write_for(FILE *out, struct tree_node *t, struct lacy_env *env)
{
    DIR *d;
    struct tree_node *var, *list;
    struct dirent *de; 

    /* Pop var IDENT */
    t = t->next; var = t;        
    /* Pop var list IDENT */
    t = t->next; list = t;        
    t = t->next;

    if (list->token == SH_BLOCK) {
        char c;
        struct ut_str file_path;
        str_init(&file_path);

        FILE *cmd = popen(list->buffer.s, "r");
        while ((c = fgetc(cmd)) != EOF) {
            if (!iswhitespace(c)) {
                str_append(&file_path, c);
            }
            else {
                if (!str_is_empty(&file_path)) {
                    env_set(env, var->buffer.s, file_path.s);
                    do_write_tree(out, env, t);

                    str_clear(&file_path);
                }
            }
        }
        fclose(cmd);
        str_free(&file_path);
    }
    else if (file_exists(list->buffer.s)) {
        /* Read directory */
        if (NULL != (d = opendir(list->buffer.s))) {
            while ((de = readdir(d)) != NULL) {
                if (strcmp(de->d_name, ".") == 0 
                || strcmp(de->d_name, "..") == 0)
                    continue;

                env_set(env, var->buffer.s, de->d_name);
                do_write_tree(out, env, t);
            }
            closedir(d);
        }
    }

    while (t->scope != var->scope) 
        t = t->next;

    return t;
}
Exemplo n.º 25
0
static int
clfjson_state(void *_state, int type, const char *data, size_t length) {
	clfjson_state_t *state = _state;
	logmeta_t *meta = state->meta;
	if( state->finished || state->errored ) {
		return 1;
	}
	clfjson_step_t steps[] = {
		{NULL, JSON_ARRAY_BEGIN, 0},
		{logmeta_field(meta, LOGPIPE_C_IP), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_CS_IDENT), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_CS_USERNAME), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_TIMESTAMP), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_CS_METHOD), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_CS_URI_STEM), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_SC_STATUS), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_BYTES), JSON_STRING, 0},
		{logmeta_field(meta, LOGPIPE_CS_REFERER), JSON_STRING, 1},
		{logmeta_field(meta, LOGPIPE_CS_USER_AGENT), JSON_STRING, 1},
		{NULL, JSON_ARRAY_END, 0},
	};	
	clfjson_step_t *step = &steps[state->i];
	if( ! step->opt ) {
		// Got array end during optional string...
		if( state->i > 0 && type == JSON_ARRAY_END ) {			
			state->finished = 1;
			return 0;
		}
		if( type != step->token && type != JSON_NULL ) {
			state->errored = 1;
			state->i++;
			return 1;
		}
	}
	else {
		if( type == JSON_ARRAY_END ) {
			state->finished = 1;
			return 0;
		}
		if( step->token != type && type != JSON_NULL ) {
			state->errored = 1;
			state->i++;
			return 1;
		}		
	}
	if( step->str ) {
		// Append to raw buffer, separated by \0, save in ptr
		if( type == JSON_NULL ) {
			str_clear(step->str);
		}
		str_append(step->str, data, length);
	}
	state->i++;
	return 0;
}
Exemplo n.º 26
0
Arquivo: pam.c Projeto: fqtools/ocserv
static void pam_auth_deinit(void* ctx)
{
struct pam_ctx_st * pctx = ctx;

	pam_end(pctx->ph, pctx->cr_ret);
	free(pctx->replies);
	str_clear(&pctx->msg);
	if (pctx->cr != NULL)
		co_delete(pctx->cr);
	talloc_free(pctx);
}
Exemplo n.º 27
0
static int make_ac_proposal(struct make_ac_ctx *ctx, struct ac_proposal *p,
			    CXCompletionResult *r, str_t *fmt)
{
	unsigned int chunks_n;

	chunks_n = clang_getNumCompletionChunks(r->CompletionString);
	str_clear(ctx->word);
	str_clear(ctx->abbr);
	str_clear(ctx->type);
	str_clear(ctx->text);

	for (unsigned int i = 0; i < chunks_n; ++i) {
		enum CXCompletionChunkKind kind;
		CXString s;

		kind = clang_getCompletionChunkKind(r->CompletionString, i);
		s = clang_getCompletionChunkText(r->CompletionString, i);
		switch (kind) {
		case CXCompletionChunk_ResultType:
			str_add_printf(&ctx->type, "%s", clang_getCString(s));
			break;
		case CXCompletionChunk_TypedText:
			str_add_cstr(&ctx->word, clang_getCString(s));
		default:
			str_add_cstr(&ctx->text, clang_getCString(s));
			break;
		}
		clang_disposeString(s);
	}

	if (ctx->type->len > MAX_TYPE_CHARS) {
		ctx->type->len = MAX_TYPE_CHARS-1;
		str_add_cstr(&ctx->type, "…");
	}
	str_add_printf(&ctx->abbr, fmt->data,
		       ctx->type->data, ctx->text->data);

	p->abbr = strdup(ctx->abbr->data);
	p->word = strdup(ctx->word->data);
	return 1;
}
Exemplo n.º 28
0
isc_result_t
dnsname_to_dn(zone_register_t *zr, dns_name_t *name, dns_name_t *zone,
	      ld_string_t *target)
{
	isc_result_t result;
	int label_count;
	const char *zone_dn = NULL;
	char *dns_str = NULL;
	char *escaped_name = NULL;
	int dummy;
	dns_name_t labels;
	unsigned int common_labels;
	dns_namereln_t namereln;


	REQUIRE(zr != NULL);
	REQUIRE(name != NULL);
	REQUIRE(target != NULL);

	isc_mem_t * mctx = zr_get_mctx(zr);
	str_clear(target);

	/* Find the DN of the zone we belong to. */
	CHECK(zr_get_zone_dn(zr, zone, &zone_dn));

	namereln = dns_name_fullcompare(name, zone, &dummy, &common_labels);
	if (namereln != dns_namereln_equal) {
		label_count = dns_name_countlabels(name) - common_labels;

		dns_name_init(&labels, NULL);
		dns_name_getlabelsequence(name, 0, label_count, &labels);
		CHECK(dns_name_tostring(&labels, &dns_str, mctx));

		CHECK(dns_to_ldap_dn_escape(mctx, dns_str, &escaped_name));
		CHECK(str_cat_char(target, "idnsName="));
		CHECK(str_cat_char(target, escaped_name));
		/* 
		 * Modification of following line can affect modify_ldap_common().
		 * See line with: char *zone_dn = strstr(str_buf(owner_dn),", ") + 1;  
		 */
		CHECK(str_cat_char(target, ", "));
	}
	CHECK(str_cat_char(target, zone_dn));

cleanup:
	if (dns_str)
		isc_mem_free(mctx, dns_str);
	if (escaped_name)
		isc_mem_free(mctx, escaped_name);
	return result;
}
Exemplo n.º 29
0
/*
 * Separates multiple values in an array and ensures that the
 * line length is within the preferred value when possible.
 */
static void write_value(JSONWR_T* jsonwr) {
  int line_len, val_len;
  enforce_state(jsonwr->state, 4, JSON_PROPERTY, JSON_EMPTY_ARRAY, 
      JSON_SL_ARRAY, JSON_ML_ARRAY);
  val_len = str_len(jsonwr->value_buf);
  if (jsonwr->state == JSON_EMPTY_ARRAY) {
    if ((jsonwr->indent + 1 + val_len + 2) < jsonwr->line_cols) {
      str_clear(jsonwr->line_buf);
      str_append(jsonwr->line_buf, str_internal(jsonwr->value_buf), val_len);
      jsonwr->state = JSON_SL_ARRAY;
      return; // don't write anything yet
    } else {
      fputc('[', jsonwr->file);
      jsonwr->column += 1;
      write_nl_indent(jsonwr);
    }
  } else if (jsonwr->state == JSON_SL_ARRAY) {
    line_len = str_len(jsonwr->line_buf);
    if ((jsonwr->indent + 1 + line_len + 2 + val_len + 2) < jsonwr->line_cols) {
      str_append(jsonwr->line_buf, ", ", 2);
      str_append(jsonwr->line_buf, str_internal(jsonwr->value_buf), val_len);
      return; // don't write anything yet
    } else {
      fputc('[', jsonwr->file);
      jsonwr->column += 1;
      write_nl_indent(jsonwr);
      fputs(str_internal(jsonwr->line_buf), jsonwr->file);
      jsonwr->column += line_len;
      jsonwr->state = JSON_ML_ARRAY;
    }
  }
  if (jsonwr->state == JSON_ML_ARRAY) {
    fputc(',', jsonwr->file);
    jsonwr->column += 1;
    if ((jsonwr->column + 1 + val_len + 2) < jsonwr->line_cols) {
      fputc(' ', jsonwr->file);
      jsonwr->column += 1;
    } else {
      write_nl_indent(jsonwr);
    }
  }
  fputs(str_internal(jsonwr->value_buf), jsonwr->file);
  jsonwr->column += str_len(jsonwr->value_buf);
  if (jsonwr->state == JSON_PROPERTY) {
    jsonwr->state = pop_state(jsonwr->stack);
  } else { // ARRAY
    jsonwr->state = JSON_ML_ARRAY;
  }
}
Exemplo n.º 30
0
pstr STDCALL str_substr( pstr dest, pstr src, uint off, uint len )
{
   uint slen = str_len( src );

   if ( len && off < slen )
   {
      if ( len > slen - off )
         len = slen - off;
      str_copylen( dest, str_ptr( src ) + off, len );
   }
   else 
      str_clear( dest );

   return dest;
}