[asterisk-commits] rizzo: trunk r45485 - /trunk/main/manager.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Oct 17 23:28:35 MST 2006
Author: rizzo
Date: Wed Oct 18 01:28:34 2006
New Revision: 45485
URL: http://svn.digium.com/view/asterisk?rev=45485&view=rev
Log:
+ move the enum declaration for output formats near the head
of the file, so it can be used from more places;
+ make the declaration of contenttype[] more robust;
+ remove the wrappers around __xml_translate(), since they were
used only in one place, and rename to xml_translate().
This allows for a bit of simplifications.
+ document the output produced by the above function.
Modified:
trunk/main/manager.c
Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?rev=45485&r1=45484&r2=45485&view=diff
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Wed Oct 18 01:28:34 2006
@@ -90,6 +90,18 @@
int category;
struct eventqent *next;
char eventdata[1]; /* really variable size, allocated by append_event() */
+};
+
+enum output_format {
+ FORMAT_RAW,
+ FORMAT_HTML,
+ FORMAT_XML,
+};
+
+static char *contenttype[] = {
+ [FORMAT_RAW] = "plain",
+ [FORMAT_HTML] = "html",
+ [FORMAT_XML] = "xml",
};
static int enabled = 0;
@@ -285,7 +297,32 @@
}
}
-static char *__xml_translate(char *in, struct ast_variable *vars, int xml)
+/*! \brief Convert the input into XML or HTML.
+ * The input is supposed to be a sequence of lines of the form
+ * Name: value
+ * optionally followed by a blob of unformatted text.
+ * A blank line is a section separator. Basically, this is a
+ * mixture of the format of Manager Interface and CLI commands.
+ * The unformatted text is considered as a single value of a field
+ * named 'Opaque-data'.
+ *
+ * At the moment the output format is the following (but it may
+ * change depending on future requirements so don't count too
+ * much on it when writing applications):
+ *
+ * General: the unformatted text is used as a value of
+ * XML output: to be completed
+ * Each section is within <response type="object" id="xxx">
+ * where xxx is taken from ajaxdest variable or defaults to unknown
+ * Each row is reported as an attribute Name="value" of an XML
+ * entity named from the variable ajaxobjtype, default to "generic"
+ *
+ * HTML output:
+ * each Name-value pair is output as a single row of a two-column table.
+ * Sections (blank lines in the input) are separated by a <HR>
+ *
+ */
+static char *xml_translate(char *in, struct ast_variable *vars, enum output_format format)
{
struct ast_variable *v;
char *dest = NULL;
@@ -298,6 +335,7 @@
int escaped = 0;
int inobj = 0;
int x;
+ int xml = (format == FORMAT_XML);
for (v = vars; v; v = v->next) {
if (!dest && !strcasecmp(v->name, "ajaxdest"))
@@ -313,6 +351,8 @@
/* determine how large is the response.
* This is a heuristic - counting colons (for headers),
* newlines (for extra arguments), and escaped chars.
+ * XXX needs to be checked carefully for overflows.
+ * Even better, use some code that allows extensible strings.
*/
for (x = 0; in[x]; x++) {
if (in[x] == ':')
@@ -375,21 +415,12 @@
}
} else {
xml_copy_escape(&tmp, &len, val, 0);
+ ast_build_string(&tmp, &len, xml ? "\n" : "<br>\n");
}
}
if (inobj)
ast_build_string(&tmp, &len, xml ? " /></response>\n" : "</body>\n");
return out;
-}
-
-static char *xml_translate(char *in, struct ast_variable *vars)
-{
- return __xml_translate(in, vars, 1);
-}
-
-static char *html_translate(char *in)
-{
- return __xml_translate(in, NULL, 0);
}
static struct ast_manager_user *ast_get_manager_by_name_locked(const char *name)
@@ -2348,14 +2379,11 @@
}
}
-enum {
- FORMAT_RAW,
- FORMAT_HTML,
- FORMAT_XML,
-};
-static char *contenttype[] = { "plain", "html", "xml" };
-
-static char *generic_http_callback(int format, struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
+
+static char *generic_http_callback(enum output_format format,
+ struct sockaddr_in *requestor, const char *uri,
+ struct ast_variable *params, int *status,
+ char **title, int *contentlength)
{
struct mansession *s = NULL;
unsigned long ident = 0;
@@ -2472,10 +2500,8 @@
if (s->outputstr) {
char *tmp;
- if (format == FORMAT_XML)
- tmp = xml_translate(s->outputstr->str, params);
- else if (format == FORMAT_HTML)
- tmp = html_translate(s->outputstr->str);
+ if (format == FORMAT_XML || format == FORMAT_HTML)
+ tmp = xml_translate(s->outputstr->str, params, format);
else
tmp = s->outputstr->str;
if (tmp) {
More information about the asterisk-commits
mailing list