1 #include "TRACE/trace.h"
2 #define TRACE_NAME "ECLTest"
4 #define __E__ std::endl
6 #define QUOTE(X) QQQQ(X)
8 #define __SHORTFILE__ \
9 (__builtin_strstr(&__FILE__[0], "/srcs/") \
10 ? __builtin_strstr(&__FILE__[0], "/srcs/") + 6 \
12 #define __COUT_HDR_L__ ":" << std::dec << __LINE__ << " |\t"
13 #define __COUT_HDR__ __SHORTFILE__ << "" << __COUT_HDR_L__
15 #define __COUTV__(X) std::cout << __COUT_HDR__ << QUOTE(X) << " = " << X << __E__
16 #define __COUT__ std::cout << __COUT_HDR__
18 #include "otsdaq-utilities/ECLWriter/ECLConnection.h"
20 #include <boost/program_options.hpp>
21 namespace bpo = boost::program_options;
24 std::string encodeURIComponent(
const std::string& sourceStr)
26 std::string retStr =
"";
28 for(
const auto& c : sourceStr)
29 if((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') || (c >=
'0' && c <=
'9'))
33 sprintf(encodeStr,
"%%%2.2X", (uint8_t)c);
52 int main(
int argc,
char* argv[])
54 std::ostringstream descstr;
56 <<
" --host <ECL host> --user <Username> --pwd <Password> [--cat <Category "
57 "name>] [--title <Message "
58 "title>] [--msg message] #add quotes for any entry with spaces";
59 bpo::options_description desc(descstr.str());
60 desc.add_options()(
"host,i", bpo::value<std::string>(),
"ECL Instance Address")(
61 "user,u", bpo::value<std::string>(),
"ECL Username")(
62 "pwd,p", bpo::value<std::string>(),
"ECL Password")(
63 "cat,c", bpo::value<std::string>(),
"ECL Category")(
64 "title,t", bpo::value<std::string>(),
"Message title")(
65 "msg,m", bpo::value<std::string>(),
"Log Message")(
"help,h",
66 "produce help message");
67 bpo::positional_options_description p;
69 bpo::variables_map vm;
72 bpo::store(bpo::command_line_parser(argc, argv).options(desc).positional(p).run(),
76 catch(bpo::error
const& e)
78 std::cout <<
"Exception from command line processing in " << argv[0] <<
": "
84 std::cout << desc << std::endl;
88 std::string ECLUser =
"", ECLPwd =
"", ECLHost =
"",
89 ECLCategory =
"general" , title =
"ECL Test Message",
93 ECLUser = vm[
"user"].as<std::string>();
97 ECLPwd = vm[
"pwd"].as<std::string>();
101 ECLHost = vm[
"host"].as<std::string>();
105 ECLCategory = vm[
"cat"].as<std::string>();
107 if(vm.count(
"title"))
109 title = vm[
"title"].as<std::string>();
113 message = vm[
"msg"].as<std::string>();
121 eclEntry.author(ECLUser);
122 eclEntry.category(ECLCategory);
123 eclEntry.subject(title);
126 Form_t::field_sequence fields;
128 form.name(
"default");
130 field =
Field_t(message,
"text");
131 fields.push_back(field);
139 if(ECLCategory ==
"GetRecent")
141 __COUT__ <<
"Getting posts... matching category=" << title << __E__;
142 std::string response,
143 url =
"/E/xml_search?l=100&c=" + encodeURIComponent(title);
144 eclConn.Get(url, response);
148 else if(ECLCategory ==
"GetCategories")
150 __COUT__ <<
"Getting categories..." << __E__;
151 std::string response, url =
"/A/xml_category_list";
152 eclConn.Get(url, response);
156 else if(!eclConn.Post(eclEntry))