mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 01:49:05 +00:00
add xmlrpc-c 1.03.14 to in tree libs
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3772 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
75
libs/xmlrpc-c/src/xmlrpc_strutil.c
Normal file
75
libs/xmlrpc-c/src/xmlrpc_strutil.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "xmlrpc_config.h"
|
||||
#include "xmlrpc-c/base.h"
|
||||
#include "xmlrpc-c/base_int.h"
|
||||
|
||||
|
||||
|
||||
const char *
|
||||
xmlrpc_makePrintable(const char * const input) {
|
||||
/*----------------------------------------------------------------------------
|
||||
Convert an arbitrary string of bytes (null-terminated, though) to
|
||||
printable ASCII. E.g. convert newlines to "\n".
|
||||
|
||||
Return the result in newly malloc'ed storage. Return NULL if we can't
|
||||
get the storage.
|
||||
-----------------------------------------------------------------------------*/
|
||||
char * output;
|
||||
const unsigned int inputLength = strlen(input);
|
||||
|
||||
output = malloc(inputLength*4+1);
|
||||
|
||||
if (output != NULL) {
|
||||
unsigned int inputCursor, outputCursor;
|
||||
|
||||
for (inputCursor = 0, outputCursor = 0;
|
||||
inputCursor < inputLength;
|
||||
++inputCursor) {
|
||||
|
||||
if (isprint(input[inputCursor]))
|
||||
output[outputCursor++] = input[inputCursor];
|
||||
else if (input[inputCursor] == '\n') {
|
||||
output[outputCursor++] = '\\';
|
||||
output[outputCursor++] = 'n';
|
||||
} else if (input[inputCursor] == '\t') {
|
||||
output[outputCursor++] = '\\';
|
||||
output[outputCursor++] = 't';
|
||||
} else if (input[inputCursor] == '\a') {
|
||||
output[outputCursor++] = '\\';
|
||||
output[outputCursor++] = 'a';
|
||||
} else if (input[inputCursor] == '\r') {
|
||||
output[outputCursor++] = '\\';
|
||||
output[outputCursor++] = 'r';
|
||||
} else {
|
||||
snprintf(&output[outputCursor], 4, "\\x%02x",
|
||||
input[inputCursor]);
|
||||
}
|
||||
}
|
||||
output[outputCursor++] = '\0';
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *
|
||||
xmlrpc_makePrintableChar(char const input) {
|
||||
|
||||
const char * retval;
|
||||
|
||||
if (input == '\0')
|
||||
retval = strdup("\\0");
|
||||
else {
|
||||
char buffer[2];
|
||||
|
||||
buffer[0] = input;
|
||||
buffer[1] = '\0';
|
||||
|
||||
retval = xmlrpc_makePrintable(buffer);
|
||||
}
|
||||
return retval;
|
||||
}
|
Reference in New Issue
Block a user