*/
int fr_utf8_char(uint8_t const *str);
char const *fr_utf8_strchr(int *chr_len, char const *str, char const *chr);
-size_t fr_print_string(char const *in, ssize_t inlen,
- char *out, size_t outlen, char quote);
-size_t fr_print_string_len(char const *in, ssize_t inlen, char quote);
+size_t fr_prints(char const *in, ssize_t inlen, char *out, size_t outlen, char quote);
+size_t fr_prints_len(char const *in, ssize_t inlen, char quote);
char *fr_aprints(TALLOC_CTX *ctx, char const *in, ssize_t inlen, char quote);
#define is_truncated(_ret, _max) ((_ret) >= (_max))
if (!dict_attr_allowed_chars[*p]) {
char buff[5];
- fr_print_string((char const *)p, 1, buff, sizeof(buff), '\'');
+ fr_prints((char const *)p, 1, buff, sizeof(buff), '\'');
fr_strerror_printf("Invalid character '%s' in attribute", buff);
return -(p - (uint8_t const *)name);
* @param[in] quote the quotation character
* @return the number of bytes written to the out buffer, or a number >= outlen if truncation has occurred.
*/
-size_t fr_print_string(char const *in, ssize_t inlen, char *out, size_t outlen, char quote)
+size_t fr_prints(char const *in, ssize_t inlen, char *out, size_t outlen, char quote)
{
uint8_t const *p = (uint8_t const *) in;
int utf8 = 0;
/*
* IF YOU MODIFY THIS FUNCTION, YOU MUST MAKE
- * EQUIVALENT MODIFICATIONS TO fr_print_string_len
+ * EQUIVALENT MODIFICATIONS TO fr_prints_len
*/
/* Can't '\0' terminate */
return outlen - freespace;
}
-/** Find the length of the buffer required to fully escape a string with fr_print_string
+/** Find the length of the buffer required to fully escape a string with fr_prints
*
* Were assuming here that's it's cheaper to figure out the length and do one
* alloc than repeatedly expand the buffer when we find extra chars which need
* @param[in] quote the quotation character.
* @return the size of buffer required to hold the escaped string including the NULL byte.
*/
-size_t fr_print_string_len(char const *in, ssize_t inlen, char quote)
+size_t fr_prints_len(char const *in, ssize_t inlen, char quote)
{
uint8_t const *p = (uint8_t const *) in;
size_t outlen = 1; /* Need one byte for \0 */
size_t len, ret;
char *out;
- len = fr_print_string_len(in, inlen, quote);
+ len = fr_prints_len(in, inlen, quote);
out = talloc_array(ctx, char, len);
- ret = fr_print_string(in, inlen, out, len, quote);
+ ret = fr_prints(in, inlen, out, len, quote);
/*
* This is a fatal error, but fr_assert is the strongest
* assert we're allowed to use in library functions.
*/
- if (!fr_assert(ret == len)) {
+ if (!fr_assert(ret == (len - 1))) {
talloc_free(out);
return NULL;
}
*out++ = quote;
freespace--;
- len = fr_print_string(data->strvalue, inlen, out, freespace, quote);
+ len = fr_prints(data->strvalue, inlen, out, freespace, quote);
/* always terminate the quoted string with another quote */
if (len >= (freespace - 1)) {
out[outlen - 2] = (char) quote;
return len + 2;
}
- return fr_print_string(data->strvalue, inlen, out, outlen, quote);
+ return fr_prints(data->strvalue, inlen, out, outlen, quote);
case PW_TYPE_INTEGER:
i = data->integer;
}
/* Gets us the size of the buffer we need to alloc */
- len = fr_print_string_len(data->strvalue, inlen, quote);
+ len = fr_prints_len(data->strvalue, inlen, quote);
p = talloc_array(ctx, char, len);
if (!p) return NULL;
- ret = fr_print_string(data->strvalue, inlen, p, len, quote);
- if (!fr_assert(ret == len)) {
+ ret = fr_prints(data->strvalue, inlen, p, len, quote);
+ if (!fr_assert(ret == (len - 1))) {
talloc_free(p);
return NULL;
}
if (username == NULL) {
strcpy(clean_username, "<no User-Name attribute>");
} else {
- fr_print_string(username->vp_strvalue,
- username->vp_length,
- clean_username, sizeof(clean_username), '\0');
+ fr_prints(username->vp_strvalue, username->vp_length, clean_username, sizeof(clean_username), '\0');
}
/*
} else if (pairfind(request->packet->vps, PW_CHAP_PASSWORD, 0, TAG_ANY)) {
strcpy(clean_password, "<CHAP-Password>");
} else {
- fr_print_string(request->password->vp_strvalue,
- request->password->vp_length,
- clean_password, sizeof(clean_password), '\0');
+ fr_prints(request->password->vp_strvalue, request->password->vp_length,
+ clean_password, sizeof(clean_password), '\0');
}
}
/*
* Plugin is ASCII only and no '/'
*/
- fr_print_string(conf->stats.prefix, strlen(conf->stats.prefix),
- value->identifier.plugin, sizeof(value->identifier.plugin), '\0');
+ fr_prints(conf->stats.prefix, strlen(conf->stats.prefix),
+ value->identifier.plugin, sizeof(value->identifier.plugin), '\0');
for (p = value->identifier.plugin; *p; ++p) {
if ((*p == '-') || (*p == '/'))*p = '_';
}
/*
* Plugin instance is ASCII only (assuming printable only) and no '/'
*/
- fr_print_string(plugin_instance, strlen(plugin_instance),
- value->identifier.plugin_instance, sizeof(value->identifier.plugin_instance), '\0');
+ fr_prints(plugin_instance, strlen(plugin_instance), value->identifier.plugin_instance,
+ sizeof(value->identifier.plugin_instance), '\0');
for (p = value->identifier.plugin_instance; *p; ++p) {
if ((*p == '-') || (*p == '/')) *p = '_';
}
/*
* Type is ASCII only (assuming printable only) and no '/' or '-'
*/
- fr_print_string(type, strlen(type),
- value->identifier.type, sizeof(value->identifier.type), '\0');
+ fr_prints(type, strlen(type), value->identifier.type,
+ sizeof(value->identifier.type), '\0');
for (p = value->identifier.type; *p; ++p) {
if ((*p == '-') || (*p == '/')) *p = '_';
}
- fr_print_string(type_instance, strlen(type_instance),
- value->identifier.type_instance, sizeof(value->identifier.type_instance), '\0');
+ fr_prints(type_instance, strlen(type_instance), value->identifier.type_instance,
+ sizeof(value->identifier.type_instance), '\0');
for (p = value->identifier.type_instance; *p; ++p) {
if ((*p == '-') || (*p == '/')) *p = '_';
}
memcpy(nasname, rt.login, sizeof(rt.login));
nasname[sizeof(rt.login)] = '\0';
- fr_print_string(nasname, -1, buffer, sizeof(buffer), '"');
+ fr_prints(nasname, -1, buffer, sizeof(buffer), '"');
printf("User-Name = \"%s\"\n", buffer);
- fr_print_string(session_id, -1, buffer, sizeof(buffer), '"');
+ fr_prints(session_id, -1, buffer, sizeof(buffer), '"');
printf("Acct-Session-Id = \"%s\"\n", buffer);
if (zap) printf("Acct-Status-Type = Stop\n");
sizeof(rt.caller_id));
nasname[sizeof(rt.caller_id)] = '\0';
- fr_print_string(nasname, -1, buffer, sizeof(buffer), '"');
+ fr_prints(nasname, -1, buffer, sizeof(buffer), '"');
printf("Calling-Station-Id = \"%s\"\n", buffer);
}
/*
* Print it with appropriate escaping
*/
- len = fr_print_string(vpt->name, -1, q, bufsize - 3, c);
+ len = fr_prints(vpt->name, -1, q, bufsize - 3, c);
q += len;
*(q++) = c;
switch (vp->da->type) {
case PW_TYPE_OCTETS:
- len = fr_print_string((char const *) p, vp->vp_length, out, outlen, '"');
+ len = fr_prints((char const *) p, vp->vp_length, out, outlen, '"');
break;
case PW_TYPE_STRING:
break;
default:
- len = fr_print_string((char const *) p, ret, out, outlen, '\0');
+ len = fr_prints((char const *) p, ret, out, outlen, '\0');
break;
}
*
* The OUTPUT of xlat is a printable string. The INPUT might not be...
*
- * This is really the reverse of fr_print_string().
+ * This is really the reverse of fr_prints().
*/
if (cf_new_escape && *child) {
ssize_t slen;
{
char escaped[1024];
- fr_print_string((char *) in, t, escaped, sizeof(escaped), '\0');
+ fr_prints((char *) in, t, escaped, sizeof(escaped), '\0');
REDEBUG("Received %zu bytes of response data: %s", t, escaped);
ctx->code = -1;