diff --git a/include/postman.cpp b/include/postman.cpp index 3b44c6eee..9a44aabea 100755 --- a/include/postman.cpp +++ b/include/postman.cpp @@ -1,10 +1,12 @@ #include #include #include +#include #include #include #include #include +#include /////////////////////////////////////////////////////////// // TRecipient @@ -168,6 +170,57 @@ bool TPostman::can_dispatch_transaction(const TRectype& rec) return _recipient.items() > 0; } +static int write_xml(TConfig& cfg, void* jolly) +{ + TAssoc_array &vars = cfg.list_variables(); + TXmlItem &item = *(TXmlItem *) jolly; + TToken_string tag(cfg.get_paragraph(), ','); + const int logicnum = tag.get_int(); + const char * attr = logicnum > 0 ? "Field" : "Attr"; + int rownum = tag.get_int(); + + if (logicnum > 0) + tag = "Record"; + TXmlItem & child =item.AddChild(tag); + if (logicnum > 0) + { + child.SetAttr("LogicNumber", logicnum); + child.SetAttr("TableName", logic2table(logicnum)); + + + if (rownum > 0) + child.SetAttr("RowNumber", rownum); + } + + TString s; + + FOR_EACH_ASSOC_STRING(vars, hobj, key, val) + if (val && *val) + { + s = val; + if (s[0] == '"' && s.ends_with("\"")) + { + s.rtrim(1); + s.ltrim(1); + } + s.trim(); + if (TDate::isdate(s)) + { + TDate date(s); + + child.AddSoapInt(attr, date.date2ansi()).SetAttr("Name", key); + } + else + { + if (real::is_natural(s)) + child.AddSoapInt(attr, atoi(s)).SetAttr("Name", key); + else + child.AddSoapString(attr, s).SetAttr("Name", key); + } + } + return 0; +} + bool TPostman::dispatch_transaction(const TRectype& rec, const TFilename& name) { @@ -176,6 +229,7 @@ bool TPostman::dispatch_transaction(const TRectype& rec, { TToken_string dest; TToken_string file_dest; + TToken_string soap_dest; TString last_error; for (int r = 0; r < _recipient.items(); r++) @@ -186,6 +240,8 @@ bool TPostman::dispatch_transaction(const TRectype& rec, const TString& addr = a.address(); if (addr.find('@') >= 0) // Indirizzo posta dest.add(addr); + if (addr.starts_with("http")) // Indirizzo http + soap_dest.add(addr); else { if (fexist(addr)) @@ -258,6 +314,53 @@ bool TPostman::dispatch_transaction(const TRectype& rec, ok = fcopy(name, output); } } + + if (soap_dest.items() > 0) + { + TConfig trans(name); + TXmlItem item; + TSocketClient socket; + char * buf = new char[1024 * 256]; + strstream stream(buf, 1024 * 256); + bool ok = true; + + item.SetTag("Campo"); + trans.for_each_paragraph(write_xml, &item); + + item.Write(stream, 0); + stream << '\0'; + +#ifdef DBG + TFilename name; + char hostname[256]; + int len = strlen(buf); + + len += 79; + xvt_sys_get_host_name(hostname, sizeof(hostname)); + + name.temp(); + + ofstream f(name); + + f << "POST / HTTP/1.1\n" + << "User-Agent: Campo\n" + << "Host: " << hostname << "\n" + << "Content-Type: text/xml; charset=utf-8\n" + << "Content-length: " << len << "\n" + << "SOAPAction: \"/\"\r\n\r\n" + << "\n\n"; + + item.Write(f, 0); + + f << "\n\n\r\n"; +#endif + + FOR_EACH_TOKEN(soap_dest, r) + { + CONNID id = socket.QueryConnection("", r); + socket.HttpSoap(id, buf); + } + } } return ok; } diff --git a/include/xml.cpp b/include/xml.cpp index 76ca2fc48..8de971fc7 100755 --- a/include/xml.cpp +++ b/include/xml.cpp @@ -343,7 +343,8 @@ TXmlItem& TXmlItem::AddSoapString(const char* name, const char* value, bool typi TXmlItem& xmlVar = AddChild(name); if (typized) xmlVar.SetAttr("xsi:type", "xsd:string"); - xmlVar.AddChild("").SetText(value); + if (value && *value) + xmlVar.AddChild("").SetText(value); return xmlVar; }