From e80ccdfac750fdd318eecb35b5f48a3d251ec7ec Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 9 Jun 2008 06:49:58 +0000 Subject: Made output accumulation in a buffer and write in the end, thus enabling the corretc outputting of the error box if neccessary. --- server/src/widgetgenerator.cc | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'server/src/widgetgenerator.cc') diff --git a/server/src/widgetgenerator.cc b/server/src/widgetgenerator.cc index 6234513..43b202f 100644 --- a/server/src/widgetgenerator.cc +++ b/server/src/widgetgenerator.cc @@ -26,17 +26,18 @@ */ #include "widgetgenerator.h" -static void send_macro_widget(Macro ¯o, - Widget &widget, - TCPSocket &socket, - std::string tabs, - LUAQueryMapper &mapper, - Values &values) +static std::string send_macro_widget(Macro ¯o, + Widget &widget, + std::string tabs, + LUAQueryMapper &mapper, + Values &values) { + std::string result; + std::string prefilled; time_t timestamp = 0; - socket.write(tabs + "<" + widget.attributes["type"]); + result = tabs + "<" + widget.attributes["type"]; std::map< std::string, std::string >::iterator p = widget.attributes.begin(); // Check if the field has a map, and fill in the value if it has... @@ -72,26 +73,28 @@ static void send_macro_widget(Macro ¯o, while(p != widget.attributes.end()) { if(p->first != "type" && p->first != "map") { - socket.write(" " + p->first + "=\"" + p->second + "\""); + result += " " + p->first + "=\"" + p->second + "\""; } p++; } - if(prefilled != "") socket.write(" prefilled=\"" + prefilled + "\""); + if(prefilled != "") result += " prefilled=\"" + prefilled + "\""; if(widget.widgets.size() == 0) { // If node is empty, use short tag form - socket.write("/>\n"); - return; + result += "/>\n"; + return result; } - socket.write(">\n"); + result += ">\n"; std::vector< Widget >::iterator w = widget.widgets.begin(); while(w != widget.widgets.end()) { - send_macro_widget(macro, *w, socket, tabs + " ", mapper, values); + result += send_macro_widget(macro, *w, tabs + " ", mapper, values); w++; } - socket.write(tabs + "\n"); + result += tabs + "\n"; + + return result; } static void get_fields(Widget &widget, Fieldnames &fields) @@ -107,12 +110,12 @@ static void get_fields(Widget &widget, Fieldnames &fields) } } -void widgetgenerator(TCPSocket &socket, Macro ¯o, LUAQueryMapper &mapper, Database &db) +std::string widgetgenerator(Macro ¯o, LUAQueryMapper &mapper, Database &db) { Fieldnames fields; get_fields(macro.window, fields); Values values = db.getValues("2003791613", fields); - send_macro_widget(macro, macro.window, socket, " ", mapper, values); + return send_macro_widget(macro, macro.window, " ", mapper, values); } -- cgit v1.2.3