diff options
Diffstat (limited to 'src/uscxml/plugins')
-rw-r--r-- | src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp | 154 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h | 4 | ||||
-rw-r--r-- | src/uscxml/plugins/element/file/FileElement.cpp | 10 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/expect/ExpectInvoker.cpp | 70 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/expect/ExpectInvoker.h | 4 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/im/IMConfig.h.in | 4 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/im/IMInvoker.cpp | 215 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/im/IMInvoker.h | 90 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/imap/IMAPInvoker.cpp | 55 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/imap/IMAPInvoker.h | 8 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/smtp/SMTPInvoker.cpp | 53 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/smtp/SMTPInvoker.h | 8 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/umundo/JSON.pb.h | 10 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp | 8 | ||||
-rw-r--r-- | src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp | 16 | ||||
-rw-r--r-- | src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp | 2 |
16 files changed, 490 insertions, 221 deletions
diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index 303d074..9bd8d9e 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -42,7 +42,7 @@ catch (PlException plex) { \ e.data.compound["cause"] = (char*)plex; \ throw e; \ } \ - + // this might evolve into multi-threaded prolog, but no need for now #define SET_PL_CONTEXT \ _dmPtr = this; @@ -76,8 +76,8 @@ bool pluginConnect(pluma::Host& host) { static SWIDataModel* _dmPtr; static std::map<SWIDataModel*, PL_engine_t> _swiEngines; -PL_blob_t SWIDataModel::blobType = -{ PL_BLOB_MAGIC, +PL_blob_t SWIDataModel::blobType = { + PL_BLOB_MAGIC, PL_BLOB_NOCOPY, (char*)"blob", releaseBlob, @@ -95,7 +95,8 @@ SWIDataModel::~SWIDataModel() { PL_destroy_engine(_swiEngines[this]); _swiEngines.erase(this); } - } RETHROW_PLEX_AS_EVENT; + } + RETHROW_PLEX_AS_EVENT; } boost::shared_ptr<DataModelImpl> SWIDataModel::create(InterpreterImpl* interpreter) { @@ -195,7 +196,8 @@ boost::shared_ptr<DataModelImpl> SWIDataModel::create(InterpreterImpl* interpret // the in predicate PlRegister("user", "in", 1, SWIDataModel::inPredicate); return dm; - } RETHROW_PLEX_AS_EVENT; + } + RETHROW_PLEX_AS_EVENT; } foreign_t SWIDataModel::inPredicate(term_t a0, int arity, void* context) { @@ -210,7 +212,8 @@ foreign_t SWIDataModel::inPredicate(term_t a0, int arity, void* context) { } } return FALSE; - } RETHROW_PLEX_AS_EVENT; + } + RETHROW_PLEX_AS_EVENT; } void SWIDataModel::registerIOProcessor(const std::string& name, const IOProcessor& ioprocessor) { @@ -318,7 +321,8 @@ void SWIDataModel::setEvent(const Event& event) { paramIter = lastValueIter; } } - } RETHROW_PLEX_AS_EVENT; + } + RETHROW_PLEX_AS_EVENT; } void SWIDataModel::assertFromData(const Data& data, const std::string& expr, size_t nesting) { @@ -332,14 +336,14 @@ void SWIDataModel::assertFromData(const Data& data, const std::string& expr, siz } else { ss << data.atom; } - + for (size_t i = 0; i < nesting; i++) { ss << ")"; } PlCall("assert", PlCompound(ss.str().c_str())); return; } - + if (data.compound.size() > 0) { std::map<std::string, Data>::const_iterator compIter = data.compound.begin(); while(compIter != data.compound.end()) { @@ -347,7 +351,7 @@ void SWIDataModel::assertFromData(const Data& data, const std::string& expr, siz compIter++; } } - + if (data.array.size() > 0) { std::list<Data>::const_iterator arrIter = data.array.begin(); while(arrIter != data.array.end()) { @@ -355,7 +359,7 @@ void SWIDataModel::assertFromData(const Data& data, const std::string& expr, siz arrIter++; } } - + if (data.node) { std::stringstream dataInitStr; std::stringstream xmlDoc; @@ -366,7 +370,7 @@ void SWIDataModel::assertFromData(const Data& data, const std::string& expr, siz dataInitStr << "copy_term(XML,DATA), "; dataInitStr << "assert("; dataInitStr << expr << "(DATA)"; - + for (size_t i = 0; i < nesting; i++) { dataInitStr << ")"; } @@ -381,66 +385,67 @@ Data SWIDataModel::getStringAsData(const std::string& content) { try { PlTerm term(content.c_str()); return(termAsData(term)); - } RETHROW_PLEX_AS_EVENT + } + RETHROW_PLEX_AS_EVENT } Data SWIDataModel::termAsData(PlTerm term) { Data data; // std::cout << term.name() << (char*)term << std::endl; - + switch (term.type()) { - case PL_TERM: - for (int i = 1; i <= term.arity(); i++) { // arguments start at 1 - data.compound[term.name()].array.push_back(termAsData(term[i])); - } - break; - case PL_INTEGER: - case PL_FLOAT: - case PL_SHORT: - case PL_INT: - case PL_LONG: - case PL_DOUBLE: - data.atom = std::string(term); - data.type = Data::INTERPRETED; - break; - case PL_ATOM: - data.atom = std::string(term); - data.type = Data::VERBATIM; - break; + case PL_TERM: + for (int i = 1; i <= term.arity(); i++) { // arguments start at 1 + data.compound[term.name()].array.push_back(termAsData(term[i])); + } + break; + case PL_INTEGER: + case PL_FLOAT: + case PL_SHORT: + case PL_INT: + case PL_LONG: + case PL_DOUBLE: + data.atom = std::string(term); + data.type = Data::INTERPRETED; + break; + case PL_ATOM: + data.atom = std::string(term); + data.type = Data::VERBATIM; + break; #ifdef SWI_HAS_PL_NIL - case PL_NIL: - data.array.push_back(Data("", Data::VERBATIM)); - break; + case PL_NIL: + data.array.push_back(Data("", Data::VERBATIM)); + break; #endif #ifdef SWI_HAS_PL_LIST_PAIR - case PL_LIST_PAIR: { - PlTail tail(term); - PlTerm item; - while(tail.next(item)) { - data.array.push_back(termAsData(item)); - } - break; + case PL_LIST_PAIR: { + PlTail tail(term); + PlTerm item; + while(tail.next(item)) { + data.array.push_back(termAsData(item)); } + break; + } #endif #ifdef SWI_HAS_DICT - case PL_DICT: { - std::string key(term); - size_t curlyPos = key.find_first_of("{"); - if (curlyPos == std::string::npos || curlyPos == 0) { - // no key given - PL_for_dict(term, SWIDataModel::dictCallBack, &data, 0); - } else { - // with key given - Data& tmp = data.compound[boost::trim_copy(key.substr(0, curlyPos))]; - PL_for_dict(term, SWIDataModel::dictCallBack, &tmp, 0); - } - break; + case PL_DICT: { + std::string key(term); + size_t curlyPos = key.find_first_of("{"); + if (curlyPos == std::string::npos || curlyPos == 0) { + // no key given + PL_for_dict(term, SWIDataModel::dictCallBack, &data, 0); + } else { + // with key given + Data& tmp = data.compound[boost::trim_copy(key.substr(0, curlyPos))]; + PL_for_dict(term, SWIDataModel::dictCallBack, &tmp, 0); } + break; + } #endif - default: - LOG(ERROR) << "Prolog type " << term.type() << " at '" << (char*)term << "' not supported"; - break; + default: + LOG(ERROR) << "Prolog type " << term.type() << " at '" << (char*)term << "' not supported"; + break; } return data; } @@ -459,7 +464,7 @@ PlTerm SWIDataModel::dataAsTerm(Data data) { if (data.array.size() > 0) { PlTerm head; PlTail list(head); - + std::list<Data>::const_iterator arrIter = data.array.begin(); while(arrIter != data.array.end()) { list.append(dataAsTerm(*arrIter)); @@ -487,7 +492,7 @@ PlTerm SWIDataModel::dataAsTerm(Data data) { std::stringstream dictSS; std::string seperator; dictSS << data.compound.begin()->first << "{"; - + std::map<std::string, Data>::const_iterator keyIter = data.compound.begin()->second.compound.begin(); while(keyIter != data.compound.begin()->second.compound.end()) { dictSS << seperator << keyIter->first << ":" << (char*)dataAsTerm(keyIter->second); @@ -496,12 +501,12 @@ PlTerm SWIDataModel::dataAsTerm(Data data) { } dictSS << "}"; return PlCompound(dictSS.str().c_str()); - + } else { // an array of dicts PlTermv termv(data.compound.size()); int index = 0; - + std::map<std::string, Data>::const_iterator compIter = data.compound.begin(); while(compIter != data.compound.end()) { termv[index] = PlCompound(compIter->first.c_str(), dataAsTerm(compIter->second)); @@ -528,7 +533,7 @@ PlTerm SWIDataModel::dataAsTerm(Data data) { dataInitStr << "load_xml_file('" << domUrl.asLocalFile(".pl") << "', XML), copy_term(XML,DATA), assert(event(data(DATA)))"; PlCall(dataInitStr.str().c_str()); } - + return PlTerm(); } @@ -551,7 +556,8 @@ uint32_t SWIDataModel::getLength(const std::string& expr) { while(query.next_solution() > 0) length++; return length; - } RETHROW_PLEX_AS_EVENT; + } + RETHROW_PLEX_AS_EVENT; } void SWIDataModel::setForeach(const std::string& item, @@ -584,7 +590,8 @@ void SWIDataModel::setForeach(const std::string& item, PlCall("assert", PlCompound(item.c_str(), varIter->second)); varIter++; } - } RETHROW_PLEX_AS_EVENT; + } + RETHROW_PLEX_AS_EVENT; } void SWIDataModel::eval(const Element<std::string>& scriptElem, const std::string& expr) { @@ -596,7 +603,8 @@ void SWIDataModel::eval(const Element<std::string>& scriptElem, const std::strin URL localPLFile = URL::toLocalFile(expr, ".pl"); PlCall("user", "load_files", PlTermv(localPLFile.asLocalFile(".pl").c_str())) || LOG(ERROR) << "Could not execute prolog from file"; } - } RETHROW_PLEX_AS_EVENT; + } + RETHROW_PLEX_AS_EVENT; } bool SWIDataModel::evalAsBool(const std::string& expr) { @@ -621,10 +629,10 @@ bool SWIDataModel::evalAsBool(const Arabica::DOM::Node<std::string>& node, const std::string SWIDataModel::evalAsString(const std::string& expr) { SET_PL_CONTEXT try { - + PlCompound orig(expr.c_str()); // keep the original to find variables PlCompound compound(expr.c_str()); - + if (strlen(compound.name())) { PlTermv termv(compound.arity()); for (int i = 0; i < compound.arity(); i++) { @@ -693,7 +701,8 @@ std::map<std::string, PlTerm> SWIDataModel::resolveAtoms(PlTerm& term, PlTerm& o LOG(ERROR) << "Resolving variable of unknown type in query solution"; } return atoms; - } RETHROW_PLEX_AS_EVENT + } + RETHROW_PLEX_AS_EVENT } void SWIDataModel::assign(const Element<std::string>& assignElem, @@ -771,7 +780,8 @@ void SWIDataModel::assign(const Element<std::string>& assignElem, } } } - } RETHROW_PLEX_AS_EVENT + } + RETHROW_PLEX_AS_EVENT } void SWIDataModel::assign(const std::string& location, const Data& data) { @@ -793,8 +803,8 @@ bool SWIDataModel::isDeclared(const std::string& expr) { void SWIDataModel::acquireBlob(atom_t symbol) { } - - + + int SWIDataModel::releaseBlob(atom_t symbol) { return TRUE; } @@ -807,5 +817,5 @@ int SWIDataModel::writeBlob(void *s, atom_t symbol, int flags) { return TRUE; } - + } diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index 0855d89..01d3556 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -87,11 +87,11 @@ public: protected: std::map<std::string, PlTerm> resolveAtoms(PlTerm& term, PlTerm& orig); void assertFromData(const Data& data, const std::string& expr, size_t nesting); - + static Data termAsData(PlTerm term); static PlTerm dataAsTerm(Data data); - + static int dictCallBack(term_t key, term_t value, int last, void *closure); static PL_blob_t blobType; diff --git a/src/uscxml/plugins/element/file/FileElement.cpp b/src/uscxml/plugins/element/file/FileElement.cpp index d88a598..aef63aa 100644 --- a/src/uscxml/plugins/element/file/FileElement.cpp +++ b/src/uscxml/plugins/element/file/FileElement.cpp @@ -135,8 +135,8 @@ void FileElement::enterElement(const Arabica::DOM::Node<std::string>& node) { _actualUrl.toAbsolute(URL::getResourceDir()); _filepath = _actualUrl.path(); - - + + std::string writeMode; switch (_operation) { case APPEND: @@ -178,9 +178,9 @@ void FileElement::enterElement(const Arabica::DOM::Node<std::string>& node) { Event event; event.name = callback; - + std::string filename = _actualUrl.pathComponents()[_actualUrl.pathComponents().size() - 1]; - + event.data.compound["file"].compound["name"] = Data(filename, Data::VERBATIM); event.data.compound["file"].compound["path"] = Data(_filepath, Data::VERBATIM); event.data.compound["file"].compound["mtime"] = toStr(fileStat.st_mtime); @@ -205,7 +205,7 @@ void FileElement::enterElement(const Arabica::DOM::Node<std::string>& node) { } switch (_type) { - case BINARY: { + case BINARY: { std::string mimetype = "application/octet-stream"; if (HAS_ATTR(node, "mimetype")) { mimetype = ATTR(node, "mimetype"); diff --git a/src/uscxml/plugins/invoker/expect/ExpectInvoker.cpp b/src/uscxml/plugins/invoker/expect/ExpectInvoker.cpp index 222624a..7d66b10 100644 --- a/src/uscxml/plugins/invoker/expect/ExpectInvoker.cpp +++ b/src/uscxml/plugins/invoker/expect/ExpectInvoker.cpp @@ -64,33 +64,33 @@ void ExpectInvoker::send(const SendRequest& req) { EventContext* ctx = new EventContext(); ctx->sendReq = req; ctx->instance = this; - + // LOG(ERROR) << "################ " << req; - + std::string eventId = UUID::getUUID(); _eventQueue->addEvent(eventId, ExpectInvoker::send, 0, ctx); - + // send(ctx, ""); } - + void ExpectInvoker::send(void *userdata, const std::string event) { EventContext* ctx = (EventContext*)userdata; if (!ctx) return; - + if (!ctx->instance) { delete(ctx); return; } const SendRequest& req = ctx->sendReq; - + if (iequals(req.name, "expect.match")) { int nrCases = req.params.size(); struct exp_case *cases = (struct exp_case*)malloc(sizeof(struct exp_case) * (nrCases + 1)); memset(cases, 0, sizeof(exp_case) * (nrCases + 1)); - + /** exp_end: indicates that no more patterns appear. exp_glob: indicates that the pattern is a glob-style string pattern. @@ -99,7 +99,7 @@ void ExpectInvoker::send(void *userdata, const std::string event) { exp_compiled: indicates that the pattern is a regexp-style string pattern, and that its compiled form is also provided. exp_null: indicates that the pattern is a null (for debugging purposes, a string pattern must also follow). */ - + Event::params_t::const_iterator paramIter = req.params.begin(); int index = 0; while (paramIter != req.params.end()) { @@ -119,7 +119,7 @@ void ExpectInvoker::send(void *userdata, const std::string event) { } else { expCase->type = exp_regexp; } - + expCase->pattern = strdup(paramIter->second.atom.c_str()); // LOG(ERROR) << "################ " << expCase->pattern; @@ -134,21 +134,21 @@ void ExpectInvoker::send(void *userdata, const std::string event) { paramIter++; index++; } - + assert(index == nrCases); - + cases[nrCases].type = exp_end; /** * The functions wait until the output from a process matches one of the * patterns, a specified time period has passed, or an EOF is seen. */ - + int rc = 0; // exp_fexpectv won't return on timeout when called in thread // rc = exp_fexpectv(ctx->instance->_cmdFP, cases); rc = exp_expectv(ctx->instance->_cmdFD, cases); - + if (rc == EXP_EOF) { Event ev; ev.name = "expect.match.eof"; @@ -175,7 +175,7 @@ void ExpectInvoker::send(void *userdata, const std::string event) { } if (paramIter != req.params.end()) { Event event; - + size_t colonPos = paramIter->first.find(":"); if (colonPos != std::string::npos) { std::string eventName = paramIter->first; @@ -186,7 +186,7 @@ void ExpectInvoker::send(void *userdata, const std::string event) { event.name = std::string("expect.match.") + paramIter->first; event.data.compound["type"] = Data("regex", Data::VERBATIM); } - + event.data.compound["pattern"] = Data(paramIter->second.atom, Data::VERBATIM); event.data.compound["buffer"] = Data(exp_buffer, Data::VERBATIM); event.data.compound["start"] = Data((int)(exp_match - exp_buffer)); @@ -216,7 +216,7 @@ void ExpectInvoker::send(void *userdata, const std::string event) { ctx->instance->_interpreter->getDataModel().replaceExpressions(toSend); fwrite(toSend.c_str(), toSend.length(), 1, ctx->instance->_cmdFP); } - + delete(ctx); } @@ -235,31 +235,31 @@ void ExpectInvoker::invoke(const InvokeRequest& req) { //_eventQueue->addEvent(req.sendid, ExpectInvoker::invoke, 0, ctx); invoke(ctx, ""); - + } - + void ExpectInvoker::invoke(void *userdata, const std::string event) { EventContext* ctx = (EventContext*)userdata; - + if (!ctx) return; - + if (!ctx->instance) { delete(ctx); return; } - + const InvokeRequest& req = ctx->invokeReq; - + // moved here for thread local storage if (ctx->instance->_tcl == NULL) { - ctx->instance->_tcl = Tcl_CreateInterp(); + ctx->instance->_tcl = Tcl_CreateInterp(); if (ctx->instance->_tcl) { Tcl_Init(ctx->instance->_tcl); Expect_Init(ctx->instance->_tcl); } ctx->instance->_cmdFP = NULL; - + bool debug = false; Event::getParam(req.params, "debug", debug); if (debug) { @@ -267,11 +267,11 @@ void ExpectInvoker::invoke(void *userdata, const std::string event) { } else { exp_is_debugging = 0; } - + int timeout = 20; Event::getParam(req.params, "timeout", timeout); exp_timeout = timeout; - + bool logUser = false; Event::getParam(req.params, "loguser", logUser); if (logUser) { @@ -279,12 +279,12 @@ void ExpectInvoker::invoke(void *userdata, const std::string event) { } else { exp_loguser = 0; } - + // exp_interactive = 1; exp_logfile = 0; // exp_remove_nulls = 1; // exp_ttyinit = 1; - + } else { // assert(false); } @@ -292,7 +292,7 @@ void ExpectInvoker::invoke(void *userdata, const std::string event) { char* cmd = NULL; char** args = NULL; int nrArgs = 0; - + if (req.params.count("spawn")) { // get command std::string command; @@ -314,14 +314,14 @@ void ExpectInvoker::invoke(void *userdata, const std::string event) { } args[index] = (char*)0; } else if(req.params.count("command")) { - + } - + // open socket ctx->instance->_cmdFD = exp_spawnv(cmd, args); if (ctx->instance->_cmdFD > 0) { ctx->instance->_cmdFP = fdopen(ctx->instance->_cmdFD, "r+"); - + if (ctx->instance->_cmdFP) { // disable buffering setbuf(ctx->instance->_cmdFP,(char *)0); @@ -330,7 +330,7 @@ void ExpectInvoker::invoke(void *userdata, const std::string event) { ctx->instance->returnEvent(event); } } - + if (ctx->instance->_cmdFP == NULL || ctx->instance->_cmdFD <= 0) { Event event; event.name = "spawn.failed"; @@ -345,14 +345,14 @@ void ExpectInvoker::invoke(void *userdata, const std::string event) { if (cmd) free(cmd); - + if (args) { for (int i = 0; i < nrArgs + 1; i++) { free(args[i]); } free(args); } - + } }
\ No newline at end of file diff --git a/src/uscxml/plugins/invoker/expect/ExpectInvoker.h b/src/uscxml/plugins/invoker/expect/ExpectInvoker.h index 7c9861e..902885e 100644 --- a/src/uscxml/plugins/invoker/expect/ExpectInvoker.h +++ b/src/uscxml/plugins/invoker/expect/ExpectInvoker.h @@ -57,14 +57,14 @@ public: virtual void invoke(const InvokeRequest& req); protected: - + static void send(void *userdata, const std::string event); static void invoke(void *userdata, const std::string event); static Tcl_Interp* _tcl; FILE* _cmdFP; int _cmdFD; - + DelayedEventQueue* _eventQueue; }; diff --git a/src/uscxml/plugins/invoker/im/IMConfig.h.in b/src/uscxml/plugins/invoker/im/IMConfig.h.in index e69de29..b43fef6 100644 --- a/src/uscxml/plugins/invoker/im/IMConfig.h.in +++ b/src/uscxml/plugins/invoker/im/IMConfig.h.in @@ -0,0 +1,4 @@ +#define LIBPURPLE_VERSION_MAJOR @LIBPURPLE_VERSION_MAJOR@ +#define LIBPURPLE_VERSION_MINOR @LIBPURPLE_VERSION_MINOR@ +#define LIBPURPLE_VERSION_PATCH @LIBPURPLE_VERSION_PATCH@ +#define LIBPURPLE_VERSION "@LIBPURPLE_VERSION@" diff --git a/src/uscxml/plugins/invoker/im/IMInvoker.cpp b/src/uscxml/plugins/invoker/im/IMInvoker.cpp index 23594f3..6de4063 100644 --- a/src/uscxml/plugins/invoker/im/IMInvoker.cpp +++ b/src/uscxml/plugins/invoker/im/IMInvoker.cpp @@ -116,13 +116,21 @@ PurpleConnectionUiOps IMInvoker::_uiConnectOps = { purpleConnected, purpleDisonnected, purpleNotice, +#if LIBPURPLE_VERSION_MAJOR >= 3 purpleNetworkConnected, purpleNetworkDisconnected, purpleReportDisconnect, NULL, NULL, NULL - +#else + purpleReportDisconnect, + purpleNetworkConnected, + purpleNetworkDisconnected, + NULL, + NULL, + NULL +#endif }; //libpurple conversation operations @@ -163,7 +171,7 @@ PurpleNotifyUiOps IMInvoker::_uiNotifyOps = { NULL }; -#if 0 +#if LIBPURPLE_VERSION_MAJOR < 3 PurplePrivacyUiOps IMInvoker::_uiPrivacyOps = { purplePermitAdded, purplePermitRemoved, @@ -176,8 +184,11 @@ PurplePrivacyUiOps IMInvoker::_uiPrivacyOps = { }; #endif +#if LIBPURPLE_VERSION_MAJOR >= 3 PurpleRequestFeature IMInvoker::_features; +#endif PurpleRequestUiOps IMInvoker::_uiRequestOps = { +#if LIBPURPLE_VERSION_MAJOR >= 3 _features, purpleRequestInput, purpleRequestChoice, @@ -192,6 +203,21 @@ PurpleRequestUiOps IMInvoker::_uiRequestOps = { NULL, NULL, NULL +#else + purpleRequestInput, + purpleRequestChoice, + purpleRequestAction, + purpleRequestFields, + purpleRequestFile, + purpleRequestClose, + purpleRequestFolder, + purpleRequestActionWithIcon, + NULL, + NULL, + NULL + +#endif + }; PurpleWhiteboardUiOps IMInvoker::_uiWhiteboardOps = { @@ -447,16 +473,16 @@ Data IMInvoker::statusToData(PurpleStatus *status) { const char* statusName = purple_status_get_name(status); if (statusName) data.compound["name"] = Data(statusName, Data::VERBATIM); - PurpleStatusType* statusType = purple_status_get_status_type(status); + PurpleStatusType* statusType = PURPLE_STATUS_GET_TYPE(status); GList *statusAttrElem; - PurpleStatusAttribute* statusAttr; + PURPLE_STATUS_ATTR* statusAttr; GList *statusAttrList = purple_status_type_get_attrs(statusType); for(statusAttrElem = statusAttrList; statusAttrElem; statusAttrElem = statusAttrElem->next) { - statusAttr = (PurpleStatusAttribute*)statusAttrElem->data; - const char* statusAttrId = purple_status_attribute_get_id(statusAttr); - GValue* statusValue = purple_status_get_attr_value(status, statusAttrId); + statusAttr = (PURPLE_STATUS_ATTR*)statusAttrElem->data; + const char* statusAttrId = PURPLE_STATUS_ATTR_GET_ID(statusAttr); + PURPLE_VALUE* statusValue = purple_status_get_attr_value(status, statusAttrId); if (statusValue) { data.compound[statusAttrId] = purpleValueToData(statusValue); } @@ -510,15 +536,15 @@ Data IMInvoker::buddyToData(PurpleBuddy *buddy) { continue; data.compound["status"].compound[statusId] = statusToData(status); } - } return data; } -Data IMInvoker::purpleValueToData(GValue* value) { +Data IMInvoker::purpleValueToData(PURPLE_VALUE* value) { Data data; +#if LIBPURPLE_VERSION_MAJOR >= 3 if (false) { } else if (g_type_check_value_holds(value, G_TYPE_CHAR)) { data = Data(g_value_get_schar(value), Data::VERBATIM); @@ -567,6 +593,58 @@ Data IMInvoker::purpleValueToData(GValue* value) { } else { LOG(ERROR) << "purple thingy unknown"; } +#else + switch (purple_value_get_type(value)) { + case PURPLE_TYPE_BOOLEAN: + if (purple_value_get_boolean(value)) + data = Data("true"); + data = Data("false"); + break; + case PURPLE_TYPE_STRING: + if (purple_value_get_string(value)) { + data = Data(purple_value_get_string(value), Data::VERBATIM); + } + break; + case PURPLE_TYPE_CHAR: + Data(purple_value_get_char(value)); + break; + case PURPLE_TYPE_UCHAR: + Data(purple_value_get_uchar(value)); + break; + case PURPLE_TYPE_SHORT: + Data(purple_value_get_short(value)); + break; + case PURPLE_TYPE_USHORT: + Data(purple_value_get_ushort(value)); + break; + case PURPLE_TYPE_INT: + Data(purple_value_get_int(value)); + break; + case PURPLE_TYPE_UINT: + Data(purple_value_get_uint(value)); + break; + case PURPLE_TYPE_LONG: + Data(purple_value_get_long(value)); + break; + case PURPLE_TYPE_ULONG: + Data(purple_value_get_ulong(value)); + break; + case PURPLE_TYPE_INT64: + Data(purple_value_get_int64(value)); + break; + case PURPLE_TYPE_UINT64: + Data(purple_value_get_uint64(value)); + break; + case PURPLE_TYPE_OBJECT: + case PURPLE_TYPE_POINTER: + case PURPLE_TYPE_ENUM: + case PURPLE_TYPE_BOXED: + case PURPLE_TYPE_UNKNOWN: + case PURPLE_TYPE_SUBTYPE: + LOG(ERROR) << "purple thingy not supported"; + break; + } +#endif return data; } @@ -634,10 +712,16 @@ void IMInvoker::send(void *userdata, const std::string event) { Data data; Event::getParam(ctx->sendReq.params, "data", data); +#if LIBPURPLE_VERSION_MAJOR >= 3 PurpleIMConversation* conv = purple_im_conversation_new(ctx->instance->_account, receiver.c_str()); if (ctx->sendReq.content.length() > 0) purple_conversation_send(PURPLE_CONVERSATION(conv), ctx->sendReq.content.c_str()); - +#else + PurpleConversation* conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, ctx->instance->_account, receiver.c_str()); + if (ctx->sendReq.content.length() > 0) + purple_conv_im_send(purple_conversation_get_im_data(conv), ctx->sendReq.content.c_str()); +#endif + #if 0 if (data.binary) { PurpleConnection *gc = purple_account_get_connection(ctx->instance->_account); @@ -681,17 +765,28 @@ void IMInvoker::send(void *userdata, const std::string event) { PurpleBuddy* buddy = purple_buddy_new(ctx->instance->_account, buddyName.c_str(), NULL); purple_blist_add_buddy(buddy, NULL, NULL, NULL); +#if LIBPURPLE_VERSION_MAJOR >= 3 purple_account_add_buddy(ctx->instance->_account, buddy, reqMsg.c_str()); - +#else + purple_account_add_buddy(ctx->instance->_account, buddy); +#endif + } else if (iequals(ctx->sendReq.name, "im.buddy.remove")) { std::string buddyName; Event::getParam(ctx->sendReq.params, "name", buddyName); +#if LIBPURPLE_VERSION_MAJOR >= 3 PurpleBuddy* buddy = purple_blist_find_buddy(ctx->instance->_account, buddyName.c_str()); if (PURPLE_IS_BUDDY(buddy)) { purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy)); purple_blist_remove_buddy(buddy); } +#else + PurpleBuddy* buddy = purple_find_buddy(ctx->instance->_account, buddyName.c_str()); + purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy)); + purple_blist_remove_buddy(buddy); + +#endif } delete(ctx); @@ -725,7 +820,11 @@ void IMInvoker::invoke(void *userdata, const std::string event) { instance->_account = purple_account_new(username.c_str(), protocolId.c_str()); _accountInstances[instance->_account] = instance; +#if LIBPURPLE_VERSION_MAJOR >= 3 purple_account_set_password(instance->_account, password.c_str(), NULL, NULL); +#else + purple_account_set_password(instance->_account, password.c_str()); +#endif purple_account_set_enabled(instance->_account, "uscxml", true); GSList* buddies = purple_blist_get_buddies(); @@ -903,7 +1002,11 @@ void* IMInvoker::accountRequestAuthorize(PurpleAccount *account, PurpleAccountRequestAuthorizationCb deny_cb, void *user_data) { // always accept all "may I add you as a buddy?" requests +#if LIBPURPLE_VERSION_MAJOR >= 3 authorize_cb(message, user_data); +#else + authorize_cb(user_data); +#endif return user_data; } @@ -1093,7 +1196,11 @@ void IMInvoker::purpleAddThumbnail(PurpleXfer *xfer, const gchar *formats) { } // notification operations +#if LIBPURPLE_VERSION_MAJOR >= 3 void* IMInvoker::purpeNotifyMessage(PurpleNotifyMsgType type, const char *title, const char *primary, const char *secondary, PurpleRequestCommonParameters *cpar) { +#else +void* IMInvoker::purpeNotifyMessage(PurpleNotifyMsgType type, const char *title, const char *primary, const char *secondary) { +#endif return NULL; } void* IMInvoker::purpeNotifyEmail(PurpleConnection *gc, const char *subject, const char *from, const char *to, const char *url) { @@ -1125,6 +1232,8 @@ void IMInvoker::purpleDenyRemoved(PurpleAccount *account, const char *name) {} // request ui operations +#if LIBPURPLE_VERSION_MAJOR >= 3 + void* IMInvoker::purpleRequestInput(const char *title, const char *primary, const char *secondary, const char *default_value, gboolean multiline, gboolean masked, gchar *hint, @@ -1136,7 +1245,7 @@ void* IMInvoker::purpleRequestInput(const char *title, const char *primary, void* IMInvoker::purpleRequestChoice(const char *title, const char *primary, const char *secondary, gpointer default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, - GCallback cancel_cb, PurpleRequestCommonParameters *cpar, + GCallback cancel_cb , PurpleRequestCommonParameters *cpar, void *user_data, va_list choices) { return NULL; } @@ -1146,6 +1255,7 @@ void* IMInvoker::purpleRequestAction(const char *title, const char *primary, size_t action_count, va_list actions) { return NULL; } + void* IMInvoker::purpleRequestWait(const char *title, const char *primary, const char *secondary, gboolean with_progress, PurpleRequestCancelCb cancel_cb, @@ -1154,8 +1264,8 @@ void* IMInvoker::purpleRequestWait(const char *title, const char *primary, } void IMInvoker::purpleRequestWaitUpdate(void *ui_handle, gboolean pulse, gfloat fraction) { - } + void* IMInvoker::purpleRequestFields(const char *title, const char *primary, const char *secondary, PurpleRequestFields *fields, const char *ok_text, GCallback ok_cb, @@ -1182,14 +1292,82 @@ void* IMInvoker::purpleRequestFile(const char *title, const char *filename, } void* IMInvoker::purpleRequestFolder(const char *title, const char *dirname, - GCallback ok_cb, GCallback cancel_cb, - PurpleRequestCommonParameters *cpar, void *user_data) { + GCallback ok_cb, GCallback cancel_cb + , PurpleRequestCommonParameters *cpar, void *user_data) { return NULL; } void IMInvoker::purpleRequestClose(PurpleRequestType type, void *ui_handle) { } +#else + +void* IMInvoker::purpleRequestInput(const char *title, const char *primary, + const char *secondary, const char *default_value, + gboolean multiline, gboolean masked, gchar *hint, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data) { + return NULL; +} + +void* IMInvoker::purpleRequestChoice(const char *title, const char *primary, + const char *secondary, int default_value, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data, + va_list choices) { + return NULL; +} + +void* IMInvoker::purpleRequestAction(const char *title, const char *primary, + const char *secondary, int default_action, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data, + size_t action_count, va_list actions) { + return NULL; +} + +void* IMInvoker::purpleRequestFields(const char *title, const char *primary, + const char *secondary, PurpleRequestFields *fields, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data) { + return NULL; +} + +void* IMInvoker::purpleRequestFile(const char *title, const char *filename, + gboolean savedialog, GCallback ok_cb, + GCallback cancel_cb, PurpleAccount *account, + const char *who, PurpleConversation *conv, + void *user_data) { + return NULL; +} + +void IMInvoker::purpleRequestClose(PurpleRequestType type, void *ui_handle) { +} + +void* IMInvoker::purpleRequestFolder(const char *title, const char *dirname, + GCallback ok_cb, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data) { + return NULL; +} + +void* IMInvoker::purpleRequestActionWithIcon(const char *title, const char *primary, + const char *secondary, int default_action, + PurpleAccount *account, const char *who, + PurpleConversation *conv, + gconstpointer icon_data, gsize icon_size, + void *user_data, + size_t action_count, va_list actions) { + return NULL; +} + +#endif // connection ui operations @@ -1199,8 +1377,13 @@ void IMInvoker::purpleDisonnected(PurpleConnection *gc) {} void IMInvoker::purpleNotice(PurpleConnection *gc, const char *text) {} void IMInvoker::purpleNetworkConnected(void) {} void IMInvoker::purpleNetworkDisconnected(void) {} -void IMInvoker::purpleReportDisconnect(PurpleConnection *gc, PurpleConnectionError reason, const char *text) {} +#if LIBPURPLE_VERSION_MAJOR >= 3 +void IMInvoker::purpleReportDisconnect(PurpleConnection *gc, PurpleConnectionError reason, const char *text) { +#else +void IMInvoker::purpleReportDisconnect(PurpleConnection *gc, const char *text) { +#endif +} // whiteboard ui operations void IMInvoker::purpleCreateWB(PurpleWhiteboard *wb) {} void IMInvoker::purpleDestroyWB(PurpleWhiteboard *wb) {} diff --git a/src/uscxml/plugins/invoker/im/IMInvoker.h b/src/uscxml/plugins/invoker/im/IMInvoker.h index cb7032b..a3f129a 100644 --- a/src/uscxml/plugins/invoker/im/IMInvoker.h +++ b/src/uscxml/plugins/invoker/im/IMInvoker.h @@ -28,6 +28,18 @@ extern "C" { #include "uscxml/IMConfig.h" +#if LIBPURPLE_VERSION_MAJOR < 3 +#define PURPLE_STATUS_GET_TYPE purple_status_get_type +#define PURPLE_STATUS_ATTR_GET_ID purple_status_attr_get_id +#define PURPLE_STATUS_ATTR PurpleStatusAttr +#define PURPLE_VALUE PurpleValue +#else +#define PURPLE_STATUS_GET_TYPE purple_status_get_status_type +#define PURPLE_STATUS_ATTR_GET_ID purple_status_attribute_get_id +#define PURPLE_STATUS_ATTR PurpleStatusAttribute +#define PURPLE_VALUE GValue +#endif + #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" #endif @@ -81,7 +93,7 @@ private: static Data buddyToData(PurpleBuddy *buddy); static Data statusToData(PurpleStatus *status); - static Data purpleValueToData(GValue* value); + static Data purpleValueToData(PURPLE_VALUE* value); static PurpleAccountUiOps _uiAccountOps; static PurpleEventLoopUiOps _uiEventLoopOps; @@ -90,13 +102,18 @@ private: static PurpleBlistUiOps _uiBuddyOps; static PurpleXferUiOps _uiXferOps; static PurpleNotifyUiOps _uiNotifyOps; -// static PurplePrivacyUiOps _uiPrivacyOps; +#if LIBPURPLE_VERSION_MAJOR < 3 + static PurplePrivacyUiOps _uiPrivacyOps; +#endif static PurpleRequestUiOps _uiRequestOps; static PurpleConnectionUiOps _uiConnectOps; static PurpleWhiteboardUiOps _uiWhiteboardOps; static PurpleDebugUiOps _uiDebugOps; +#if LIBPURPLE_VERSION_MAJOR >= 3 static PurpleRequestFeature _features; +#endif + static GHashTable* _uiInfo; static GRand* _gRand; @@ -205,7 +222,11 @@ private: static void purpleAddThumbnail(PurpleXfer *xfer, const gchar *formats); // notification operations - static void* purpeNotifyMessage(PurpleNotifyMsgType type, const char *title, const char *primary, const char *secondary, PurpleRequestCommonParameters *cpar); +#if LIBPURPLE_VERSION_MAJOR >= 3 + static void* purpeNotifyMessage(PurpleNotifyMsgType type, const char *title, const char *primary, const char *secondary , PurpleRequestCommonParameters *cpar); +#else + static void* purpeNotifyMessage(PurpleNotifyMsgType type, const char *title, const char *primary, const char *secondary); +#endif static void* purpeNotifyEmail(PurpleConnection *gc, const char *subject, const char *from, const char *to, const char *url); static void* purpeNotifyEmails(PurpleConnection *gc, size_t count, gboolean detailed, const char **subjects, const char **froms, const char **tos, const char **urls); static void* purpeNotifyFormatted(const char *title, const char *primary, const char *secondary, const char *text); @@ -229,6 +250,8 @@ private: static void purpleDenyRemoved(PurpleAccount *account, const char *name); // request ui operations +#if LIBPURPLE_VERSION_MAJOR >= 3 + static void* purpleRequestInput(const char *title, const char *primary, const char *secondary, const char *default_value, gboolean multiline, gboolean masked, gchar *hint, @@ -238,7 +261,7 @@ private: static void* purpleRequestChoice(const char *title, const char *primary, const char *secondary, gpointer default_value, const char *ok_text, GCallback ok_cb, const char *cancel_text, - GCallback cancel_cb, PurpleRequestCommonParameters *cpar, + GCallback cancel_cb , PurpleRequestCommonParameters *cpar, void *user_data, va_list choices); static void* purpleRequestAction(const char *title, const char *primary, const char *secondary, int default_action, @@ -250,6 +273,7 @@ private: PurpleRequestCommonParameters *cpar, void *user_data); static void purpleRequestWaitUpdate(void *ui_handle, gboolean pulse, gfloat fraction); + static void* purpleRequestFields(const char *title, const char *primary, const char *secondary, PurpleRequestFields *fields, const char *ok_text, GCallback ok_cb, @@ -262,6 +286,59 @@ private: GCallback ok_cb, GCallback cancel_cb, PurpleRequestCommonParameters *cpar, void *user_data); static void purpleRequestClose(PurpleRequestType type, void *ui_handle); +#else + + static void* purpleRequestInput(const char *title, const char *primary, + const char *secondary, const char *default_value, + gboolean multiline, gboolean masked, gchar *hint, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data); + + static void* purpleRequestChoice(const char *title, const char *primary, + const char *secondary, int default_value, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data, + va_list choices); + + static void* purpleRequestAction(const char *title, const char *primary, + const char *secondary, int default_action, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data, + size_t action_count, va_list actions); + + static void* purpleRequestFields(const char *title, const char *primary, + const char *secondary, PurpleRequestFields *fields, + const char *ok_text, GCallback ok_cb, + const char *cancel_text, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data); + + static void* purpleRequestFile(const char *title, const char *filename, + gboolean savedialog, GCallback ok_cb, + GCallback cancel_cb, PurpleAccount *account, + const char *who, PurpleConversation *conv, + void *user_data); + + static void purpleRequestClose(PurpleRequestType type, void *ui_handle); + + static void* purpleRequestFolder(const char *title, const char *dirname, + GCallback ok_cb, GCallback cancel_cb, + PurpleAccount *account, const char *who, + PurpleConversation *conv, void *user_data); + + static void* purpleRequestActionWithIcon(const char *title, const char *primary, + const char *secondary, int default_action, + PurpleAccount *account, const char *who, + PurpleConversation *conv, + gconstpointer icon_data, gsize icon_size, + void *user_data, + size_t action_count, va_list actions); + +#endif // connection ui operations @@ -271,8 +348,11 @@ private: static void purpleNotice(PurpleConnection *gc, const char *text); static void purpleNetworkConnected(void); static void purpleNetworkDisconnected(void); +#if LIBPURPLE_VERSION_MAJOR >= 3 static void purpleReportDisconnect(PurpleConnection *gc, PurpleConnectionError reason, const char *text); - +#else + static void purpleReportDisconnect(PurpleConnection *gc, const char *text); +#endif // whiteboard ui operations static void purpleCreateWB(PurpleWhiteboard *wb); diff --git a/src/uscxml/plugins/invoker/imap/IMAPInvoker.cpp b/src/uscxml/plugins/invoker/imap/IMAPInvoker.cpp index 22e32da..ffe00a9 100644 --- a/src/uscxml/plugins/invoker/imap/IMAPInvoker.cpp +++ b/src/uscxml/plugins/invoker/imap/IMAPInvoker.cpp @@ -61,16 +61,16 @@ size_t IMAPInvoker::writeCurlData(void *ptr, size_t size, size_t nmemb, void *us size_t toWrite = std::min(ctx->content.length() - ctx->readPtr, size * nmemb); if (toWrite > 0) { - memcpy (ptr, ctx->content.c_str() + ctx->readPtr, toWrite); + memcpy (ptr, ctx->content.c_str() + ctx->readPtr, toWrite); ctx->readPtr += toWrite; } - + return toWrite; } std::list<std::string> IMAPInvoker::getAtoms(std::list<Data> list) { std::list<std::string> atoms; - + std::list<Data>::const_iterator iter = list.begin(); while(iter != list.end()) { const Data& data = *iter; @@ -106,7 +106,7 @@ void IMAPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme att.compound["mimetype"] = Data("text/plain", Data::VERBATIM); } } - + if (!att.hasKey("filename")) { std::stringstream filenameSS; filenameSS << "attachment" << attachments.size() + 1; @@ -119,19 +119,19 @@ void IMAPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme } attachments.push_back(att); - + } else if (data.binary) { // a single binary blob Data att; att.compound["data"].binary = data.binary; - + if (data.binary->mimeType.size() > 0) { att.compound["mimetype"] = Data(attachments.back()["data"].binary->mimeType, Data::VERBATIM); } else { att.compound["mimetype"] = Data("application/octet-stream", Data::VERBATIM); } - + std::stringstream filenameSS; filenameSS << "attachment" << attachments.size() + 1; if (boost::starts_with(att.compound["mimetype"].atom, "text")) { @@ -140,7 +140,7 @@ void IMAPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme filenameSS << ".bin"; } att.compound["filename"] = Data(filenameSS.str(), Data::VERBATIM); - + attachments.push_back(att); } else if (data.compound.size() > 0) { @@ -159,10 +159,10 @@ void IMAPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme iter++; } } - + void IMAPInvoker::send(const SendRequest& req) { if (iequals(req.name, "mail.send")) { - + struct curl_slist* recipients = NULL; CURLcode curlError; std::string multipartSep; @@ -177,7 +177,7 @@ void IMAPInvoker::send(const SendRequest& req) { std::list<Data> ccParams; std::list<Data> bccParams; std::list<Data> attachmentParams; - + Event::getParam(req.params, "verbose", verbose); Event::getParam(req.params, "ssl", useSSL); Event::getParam(req.params, "Content-Type", contentType); @@ -191,7 +191,7 @@ void IMAPInvoker::send(const SendRequest& req) { if (contentType.size() == 0) contentType = "text/plain; charset=\"UTF-8\""; - + IMAPContext* ctx = new IMAPContext(); std::stringstream contentSS; @@ -200,11 +200,12 @@ void IMAPInvoker::send(const SendRequest& req) { std::list<std::string> cc = getAtoms(ccParams); std::list<std::string> bcc = getAtoms(bccParams); std::list<std::string> headers = getAtoms(headerParams); - std::list<Data> attachments; getAttachments(attachmentParams, attachments); + std::list<Data> attachments; + getAttachments(attachmentParams, attachments); if (to.size() == 0) return; - + recIter = to.begin(); recIter++; // skip first as we need it in CURLOPT_MAIL_RCPT while(recIter != to.end()) { @@ -235,7 +236,7 @@ void IMAPInvoker::send(const SendRequest& req) { boost::replace_all(subject, "\r", " "); contentSS << "Subject: " << subject << "\n"; } - + // content type is different when we have attachments if (attachments.size() > 0) { multipartSep = UUID::getUUID(); @@ -249,10 +250,10 @@ void IMAPInvoker::send(const SendRequest& req) { // when we have no attachment, respect user-defined or use text/plain contentSS << "Content-Type: " << contentType << "\n"; } - + contentSS << "\n"; contentSS << req.content; - + std::list<Data>::iterator attIter = attachments.begin(); while(attIter != attachments.end()) { // only send valid attachments @@ -263,7 +264,7 @@ void IMAPInvoker::send(const SendRequest& req) { contentSS << "--" << multipartSep << "\n"; contentSS << "Content-Disposition: attachment; filename=\"" << attIter->compound["filename"].atom << "\""; contentSS << "\n"; - + contentSS << "Content-Type: " << attIter->compound["mimetype"].atom << "; "; contentSS << "name=\"" << attIter->compound["filename"].atom << "\""; contentSS << "\n"; @@ -280,10 +281,10 @@ void IMAPInvoker::send(const SendRequest& req) { } attIter++; } - + ctx->content = contentSS.str(); ctx->invoker = this; - + // see http://curl.haxx.se/libcurl/c/imap-tls.html _curl = curl_easy_init(); @@ -294,7 +295,7 @@ void IMAPInvoker::send(const SendRequest& req) { LOG(ERROR) << "Cannot set password: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(_curl, CURLOPT_URL, _server.c_str())) == CURLE_OK || LOG(ERROR) << "Cannot set server string: " << curl_easy_strerror(curlError); - + if (useSSL) { (curlError = curl_easy_setopt(_curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL)) == CURLE_OK || LOG(ERROR) << "Cannot use SSL: " << curl_easy_strerror(curlError); @@ -309,12 +310,12 @@ void IMAPInvoker::send(const SendRequest& req) { #endif } - + // this is needed, even if we have a callback function recipients = curl_slist_append(recipients, to.begin()->c_str()); (curlError = curl_easy_setopt(_curl, CURLOPT_MAIL_RCPT, recipients)) == CURLE_OK || LOG(ERROR) << "Cannot set mail recipient: " << curl_easy_strerror(curlError); - + (curlError = curl_easy_setopt(_curl, CURLOPT_READFUNCTION, IMAPInvoker::writeCurlData)) == CURLE_OK || LOG(ERROR) << "Cannot register read function: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(_curl, CURLOPT_READDATA, ctx)) == CURLE_OK || @@ -326,16 +327,16 @@ void IMAPInvoker::send(const SendRequest& req) { (curlError = curl_easy_setopt(_curl, CURLOPT_MAIL_FROM, from.c_str())) == CURLE_OK || LOG(ERROR) << "Cannot set from parameter: " << curl_easy_strerror(curlError); } - + if (verbose) { (curlError = curl_easy_setopt(_curl, CURLOPT_VERBOSE, 1L)) == CURLE_OK || LOG(ERROR) << "Cannot set curl to verbose: " << curl_easy_strerror(curlError); } CURLcode res = curl_easy_perform(_curl); - + /* Check for errors */ - if(res != CURLE_OK){ + if(res != CURLE_OK) { LOG(ERROR) << "curl_easy_perform() failed: " << curl_easy_strerror(res); returnErrorExecution("error.mail.send"); } else { @@ -344,7 +345,7 @@ void IMAPInvoker::send(const SendRequest& req) { /* Free the list of recipients */ if (recipients) curl_slist_free_all(recipients); - + /* Always cleanup */ curl_easy_cleanup(_curl); diff --git a/src/uscxml/plugins/invoker/imap/IMAPInvoker.h b/src/uscxml/plugins/invoker/imap/IMAPInvoker.h index b772bdd..5ffa727 100644 --- a/src/uscxml/plugins/invoker/imap/IMAPInvoker.h +++ b/src/uscxml/plugins/invoker/imap/IMAPInvoker.h @@ -49,20 +49,20 @@ public: virtual void invoke(const InvokeRequest& req); protected: - + class IMAPContext { public: IMAPContext() : readPtr(0) {} std::string content; - size_t readPtr; + size_t readPtr; IMAPInvoker* invoker; }; - + CURL* _curl; std::string _username; std::string _password; std::string _server; - + std::list<std::string> getAtoms(std::list<Data> list); void getAttachments(std::list<Data> list, std::list<Data>& attachments); static size_t writeCurlData(void *ptr, size_t size, size_t nmemb, void *userdata); diff --git a/src/uscxml/plugins/invoker/smtp/SMTPInvoker.cpp b/src/uscxml/plugins/invoker/smtp/SMTPInvoker.cpp index 9234fc5..3e130a0 100644 --- a/src/uscxml/plugins/invoker/smtp/SMTPInvoker.cpp +++ b/src/uscxml/plugins/invoker/smtp/SMTPInvoker.cpp @@ -61,16 +61,16 @@ size_t SMTPInvoker::writeCurlData(void *ptr, size_t size, size_t nmemb, void *us size_t toWrite = std::min(ctx->content.length() - ctx->readPtr, size * nmemb); if (toWrite > 0) { - memcpy (ptr, ctx->content.c_str() + ctx->readPtr, toWrite); + memcpy (ptr, ctx->content.c_str() + ctx->readPtr, toWrite); ctx->readPtr += toWrite; } - + return toWrite; } std::list<std::string> SMTPInvoker::getAtoms(std::list<Data> list) { std::list<std::string> atoms; - + std::list<Data>::const_iterator iter = list.begin(); while(iter != list.end()) { const Data& data = *iter; @@ -106,7 +106,7 @@ void SMTPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme att.compound["mimetype"] = Data("text/plain", Data::VERBATIM); } } - + if (!att.hasKey("filename")) { std::stringstream filenameSS; filenameSS << "attachment" << attachments.size() + 1; @@ -119,19 +119,19 @@ void SMTPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme } attachments.push_back(att); - + } else if (data.binary) { // a single binary blob Data att; att.compound["data"].binary = data.binary; - + if (data.binary->mimeType.size() > 0) { att.compound["mimetype"] = Data(attachments.back()["data"].binary->mimeType, Data::VERBATIM); } else { att.compound["mimetype"] = Data("application/octet-stream", Data::VERBATIM); } - + std::stringstream filenameSS; filenameSS << "attachment" << attachments.size() + 1; if (boost::starts_with(att.compound["mimetype"].atom, "text")) { @@ -140,7 +140,7 @@ void SMTPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme filenameSS << ".bin"; } att.compound["filename"] = Data(filenameSS.str(), Data::VERBATIM); - + attachments.push_back(att); } else if (data.compound.size() > 0) { @@ -159,10 +159,10 @@ void SMTPInvoker::getAttachments(std::list<Data> list, std::list<Data>& attachme iter++; } } - + void SMTPInvoker::send(const SendRequest& req) { if (iequals(req.name, "mail.send")) { - + struct curl_slist* recipients = NULL; CURLcode curlError; std::string multipartSep; @@ -176,7 +176,7 @@ void SMTPInvoker::send(const SendRequest& req) { std::list<Data> ccParams; std::list<Data> bccParams; std::list<Data> attachmentParams; - + Event::getParam(req.params, "verbose", verbose); Event::getParam(req.params, "Content-Type", contentType); Event::getParam(req.params, "attachment", attachmentParams); @@ -189,7 +189,7 @@ void SMTPInvoker::send(const SendRequest& req) { if (contentType.size() == 0) contentType = "text/plain; charset=\"UTF-8\""; - + SMTPContext* ctx = new SMTPContext(); std::stringstream contentSS; @@ -198,11 +198,12 @@ void SMTPInvoker::send(const SendRequest& req) { std::list<std::string> cc = getAtoms(ccParams); std::list<std::string> bcc = getAtoms(bccParams); std::list<std::string> headers = getAtoms(headerParams); - std::list<Data> attachments; getAttachments(attachmentParams, attachments); + std::list<Data> attachments; + getAttachments(attachmentParams, attachments); if (to.size() == 0) return; - + recIter = to.begin(); recIter++; // skip first as we need it in CURLOPT_MAIL_RCPT while(recIter != to.end()) { @@ -233,7 +234,7 @@ void SMTPInvoker::send(const SendRequest& req) { boost::replace_all(subject, "\r", " "); contentSS << "Subject: " << subject << "\n"; } - + // content type is different when we have attachments if (attachments.size() > 0) { multipartSep = UUID::getUUID(); @@ -247,10 +248,10 @@ void SMTPInvoker::send(const SendRequest& req) { // when we have no attachment, respect user-defined or use text/plain contentSS << "Content-Type: " << contentType << "\n"; } - + contentSS << "\n"; contentSS << req.content; - + std::list<Data>::iterator attIter = attachments.begin(); while(attIter != attachments.end()) { // only send valid attachments @@ -261,7 +262,7 @@ void SMTPInvoker::send(const SendRequest& req) { contentSS << "--" << multipartSep << "\n"; contentSS << "Content-Disposition: attachment; filename=\"" << attIter->compound["filename"].atom << "\""; contentSS << "\n"; - + contentSS << "Content-Type: " << attIter->compound["mimetype"].atom << "; "; contentSS << "name=\"" << attIter->compound["filename"].atom << "\""; contentSS << "\n"; @@ -278,10 +279,10 @@ void SMTPInvoker::send(const SendRequest& req) { } attIter++; } - + ctx->content = contentSS.str(); ctx->invoker = this; - + // see http://curl.haxx.se/libcurl/c/smtp-tls.html _curl = curl_easy_init(); @@ -294,12 +295,12 @@ void SMTPInvoker::send(const SendRequest& req) { LOG(ERROR) << "Cannot set server string: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(_curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL)) == CURLE_OK || LOG(ERROR) << "Cannot use SSL: " << curl_easy_strerror(curlError); - + // this is needed, even if we have a callback function recipients = curl_slist_append(recipients, to.begin()->c_str()); (curlError = curl_easy_setopt(_curl, CURLOPT_MAIL_RCPT, recipients)) == CURLE_OK || LOG(ERROR) << "Cannot set mail recipient: " << curl_easy_strerror(curlError); - + (curlError = curl_easy_setopt(_curl, CURLOPT_READFUNCTION, SMTPInvoker::writeCurlData)) == CURLE_OK || LOG(ERROR) << "Cannot register read function: " << curl_easy_strerror(curlError); (curlError = curl_easy_setopt(_curl, CURLOPT_READDATA, ctx)) == CURLE_OK || @@ -321,16 +322,16 @@ void SMTPInvoker::send(const SendRequest& req) { (curlError = curl_easy_setopt(_curl, CURLOPT_MAIL_FROM, from.c_str())) == CURLE_OK || LOG(ERROR) << "Cannot set from parameter: " << curl_easy_strerror(curlError); } - + if (verbose) { (curlError = curl_easy_setopt(_curl, CURLOPT_VERBOSE, 1L)) == CURLE_OK || LOG(ERROR) << "Cannot set curl to verbose: " << curl_easy_strerror(curlError); } CURLcode res = curl_easy_perform(_curl); - + /* Check for errors */ - if(res != CURLE_OK){ + if(res != CURLE_OK) { LOG(ERROR) << "curl_easy_perform() failed: " << curl_easy_strerror(res); returnErrorExecution("error.mail.send"); } else { @@ -339,7 +340,7 @@ void SMTPInvoker::send(const SendRequest& req) { /* Free the list of recipients */ if (recipients) curl_slist_free_all(recipients); - + /* Always cleanup */ curl_easy_cleanup(_curl); diff --git a/src/uscxml/plugins/invoker/smtp/SMTPInvoker.h b/src/uscxml/plugins/invoker/smtp/SMTPInvoker.h index 1167153..2ae5482 100644 --- a/src/uscxml/plugins/invoker/smtp/SMTPInvoker.h +++ b/src/uscxml/plugins/invoker/smtp/SMTPInvoker.h @@ -49,20 +49,20 @@ public: virtual void invoke(const InvokeRequest& req); protected: - + class SMTPContext { public: SMTPContext() : readPtr(0) {} std::string content; - size_t readPtr; + size_t readPtr; SMTPInvoker* invoker; }; - + CURL* _curl; std::string _username; std::string _password; std::string _server; - + std::list<std::string> getAtoms(std::list<Data> list); void getAttachments(std::list<Data> list, std::list<Data>& attachments); static size_t writeCurlData(void *ptr, size_t size, size_t nmemb, void *userdata); diff --git a/src/uscxml/plugins/invoker/umundo/JSON.pb.h b/src/uscxml/plugins/invoker/umundo/JSON.pb.h index a8125bf..ff65656 100644 --- a/src/uscxml/plugins/invoker/umundo/JSON.pb.h +++ b/src/uscxml/plugins/invoker/umundo/JSON.pb.h @@ -8,16 +8,6 @@ #include <google/protobuf/stubs/common.h> -#if GOOGLE_PROTOBUF_VERSION < 2005000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 2005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif #include <google/protobuf/generated_message_util.h> #include <google/protobuf/message.h> diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp index dd9c37d..1861db7 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp @@ -177,9 +177,9 @@ void UmundoInvoker::invoke(const InvokeRequest& req) { umundo::MDNSDiscoveryOptions discOpts; _discovery = new umundo::Discovery(umundo::Discovery::MDNS, &discOpts); - + _discovery->add(*_node); - + // add type from .proto or .desc files std::list<std::string> type; Event::getParam(req.params, "type", type); @@ -194,7 +194,7 @@ void UmundoInvoker::invoke(const InvokeRequest& req) { } typeIter++; } - + // add directory with .proto or .desc files std::list<std::string> types; Event::getParam(req.params, "type", types); @@ -282,7 +282,7 @@ void UmundoInvoker::receive(void* object, umundo::Message* msg) { if (msg->size() > 0) { event.data.compound["protobuf"] = Data(msg->data(), msg->size(), "application/x-protobuf"); } - + returnEvent(event); } diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp index 7a24c79..51e1e28 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp @@ -86,11 +86,11 @@ boost::shared_ptr<IOProcessorImpl> BasicHTTPIOProcessor::create(InterpreterImpl* Data BasicHTTPIOProcessor::getDataModelVariables() { Data data; - + // we are not connected! if(_url.length() == 0) return data; - + data.compound["location"] = Data(_url, Data::VERBATIM); URL url(_url); @@ -105,7 +105,7 @@ Data BasicHTTPIOProcessor::getDataModelVariables() { data.compound["pathComponens"].array.push_back(Data(*pathCompIter, Data::VERBATIM)); pathCompIter++; } - + return data; } @@ -114,13 +114,13 @@ bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { reqEvent.eventType = Event::EXTERNAL; // std::cout << req.raw << std::endl; - + /** - * If a single instance of the parameter '_scxmleventname' is present, the - * SCXML Processor must use its value as the name of the SCXML event that it + * If a single instance of the parameter '_scxmleventname' is present, the + * SCXML Processor must use its value as the name of the SCXML event that it * raises. */ - + // this will call the const subscript operator if (req.data["content"]["_scxmleventname"]) { reqEvent.name = req.data["content"]["_scxmleventname"].atom; @@ -128,7 +128,7 @@ bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { if (req.data["content"]["content"]) { reqEvent.content = req.data["content"]["content"].atom; } - + // check whether we can parse it as XML if (reqEvent.content.length() > 0) { NameSpacingParser parser = NameSpacingParser::fromXML(reqEvent.content); diff --git a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp index 8c3f1da..17b5cb4 100644 --- a/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/scxml/SCXMLIOProcessor.cpp @@ -82,7 +82,7 @@ boost::shared_ptr<IOProcessorImpl> SCXMLIOProcessor::create(InterpreterImpl* int Data SCXMLIOProcessor::getDataModelVariables() { Data data; if(_url.length() > 0); - data.compound["location"] = Data(_url, Data::VERBATIM); + data.compound["location"] = Data(_url, Data::VERBATIM); return data; } |