summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/.gitignore1
-rw-r--r--sca-cpp/trunk/components/chat/Makefile.am18
-rw-r--r--sca-cpp/trunk/components/chat/chat-send.cpp55
-rw-r--r--sca-cpp/trunk/components/chat/chat-sender2.componentType31
-rw-r--r--sca-cpp/trunk/components/chat/chat-sender2.cpp115
-rwxr-xr-xsca-cpp/trunk/components/chat/server-test4
-rw-r--r--sca-cpp/trunk/components/http/Makefile.am11
-rw-r--r--sca-cpp/trunk/components/http/httpdelete.componentType28
-rw-r--r--sca-cpp/trunk/components/http/httpdelete.cpp90
9 files changed, 346 insertions, 7 deletions
diff --git a/sca-cpp/trunk/.gitignore b/sca-cpp/trunk/.gitignore
index e399629c54..e9a9947138 100644
--- a/sca-cpp/trunk/.gitignore
+++ b/sca-cpp/trunk/.gitignore
@@ -136,4 +136,5 @@ value-element
modules/edit/apps/*/htdocs
modules/edit/apps/*/nuvem
modules/edit/apps/*/lib
+chat-send
diff --git a/sca-cpp/trunk/components/chat/Makefile.am b/sca-cpp/trunk/components/chat/Makefile.am
index 35fb57daf3..8856e536fd 100644
--- a/sca-cpp/trunk/components/chat/Makefile.am
+++ b/sca-cpp/trunk/components/chat/Makefile.am
@@ -31,10 +31,10 @@ comp_DATA = vysper.prefix
vysper.prefix: $(top_builddir)/config.status
echo ${VYSPER_PREFIX} >vysper.prefix
-EXTRA_DIST = chat.composite chat-sendreceiver.componentType chat-sender.componentType *.scm
+EXTRA_DIST = chat.composite chat-sendreceiver.componentType chat-sender.componentType chat-sender2.componentType *.scm
-comp_LTLIBRARIES = libchat-sendreceiver.la libchat-sender.la
-noinst_DATA = libchat-sendreceiver.so libchat-sender.so
+comp_LTLIBRARIES = libchat-sendreceiver.la libchat-sender.la libchat-sender2.la
+noinst_DATA = libchat-sendreceiver.so libchat-sender.so libchat-sender2.so
libchat_sendreceiver_la_SOURCES = chat-sendreceiver.cpp
libchat_sendreceiver_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
@@ -46,12 +46,22 @@ libchat_sender_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -l
libchat-sender.so:
ln -s .libs/libchat-sender.so
+libchat_sender2_la_SOURCES = chat-sender2.cpp
+libchat_sender2_la_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
+libchat-sender2.so:
+ ln -s .libs/libchat-sender2.so
+
+chat_send_SOURCES = chat-send.cpp
+chat_send_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
+
xmpp_test_SOURCES = xmpp-test.cpp
xmpp_test_LDFLAGS = -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
client_test_SOURCES = client-test.cpp
client_test_LDFLAGS = -lxml2 -lcurl -lmozjs -L${LIBSTROPHE_LIB} -R${LIBSTROPHE_LIB} -lstrophe -lssl -lresolv
+comp_PROGRAMS = chat-send
+
noinst_PROGRAMS = xmpp-test client-test
dist_noinst_SCRIPTS = server-test
@@ -62,7 +72,7 @@ dist_noinst_JAVA = test/*.java
CLEANFILES = test/*.class
dist_noinst_SCRIPTS += echo-test
-TESTS = echo-test
+TESTS = echo-test server-test
endif
endif
diff --git a/sca-cpp/trunk/components/chat/chat-send.cpp b/sca-cpp/trunk/components/chat/chat-send.cpp
new file mode 100644
index 0000000000..bb3907acfd
--- /dev/null
+++ b/sca-cpp/trunk/components/chat/chat-send.cpp
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * Test sending a message to an XMPP id.
+ */
+
+#include <assert.h>
+#include "stream.hpp"
+#include "string.hpp"
+#include "list.hpp"
+#include "element.hpp"
+#include "monad.hpp"
+#include "value.hpp"
+#include "perf.hpp"
+#include "parallel.hpp"
+#include "xmpp.hpp"
+
+namespace tuscany {
+namespace chat {
+
+bool sendmsg(const string& jid, const string& pass, const string& to, const string& msg) {
+ XMPPClient xc(jid, pass);
+ const failable<bool> c = connect(xc);
+ assert(hasContent(c));
+ const failable<bool> p = post(to, msg, xc);
+ assert(hasContent(p));
+ return true;
+}
+
+}
+}
+
+int main(unused const int argc, const char** argv) {
+ tuscany::chat::sendmsg(argv[1], argv[2], argv[3], argv[4]);
+ return 0;
+}
diff --git a/sca-cpp/trunk/components/chat/chat-sender2.componentType b/sca-cpp/trunk/components/chat/chat-sender2.componentType
new file mode 100644
index 0000000000..fb7a61ed90
--- /dev/null
+++ b/sca-cpp/trunk/components/chat/chat-sender2.componentType
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <service name="send"/>
+ <reference name="jid"/>
+ <reference name="pass"/>
+ <reference name="to"/>
+ <reference name="msg"/>
+
+</composite>
diff --git a/sca-cpp/trunk/components/chat/chat-sender2.cpp b/sca-cpp/trunk/components/chat/chat-sender2.cpp
new file mode 100644
index 0000000000..2224f64542
--- /dev/null
+++ b/sca-cpp/trunk/components/chat/chat-sender2.cpp
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * XMPP chat sender component implementation.
+ * This sender gets its configuration from a single property and its
+ * input data from component references instead of function parameters.
+ */
+
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "parallel.hpp"
+#include "xmpp.hpp"
+
+namespace tuscany {
+namespace chat {
+namespace sender {
+
+/**
+ * Post an item to an XMPP JID.
+ */
+const failable<value> post(const lambda<value(const list<value>&)> jid, const lambda<value(const list<value>&)> pass, const lambda<value(const list<value>&)> to, const lambda<value(const list<value>&)> msg, const list<value>& params) {
+
+ const value vjid = jid(mklist<value>("get", params));
+ const value vpass = pass(mklist<value>("get", params));
+ const value vto = to(mklist<value>("get", params));
+ const value vmsg = msg(mklist<value>("get", params));
+ debug(vjid, "chat::post::from");
+ debug(vto, "chat::post::to");
+ debug(vmsg, "chat::post::value");
+
+ // Create an XMPP client session
+ XMPPClient xc(vjid, vpass);
+ const failable<bool> c = connect(xc);
+ if (!hasContent(c))
+ return mkfailure<value>(reason(c));
+
+ // Post the message
+ const failable<bool> r = post(vto, vmsg, xc);
+ if (!hasContent(r))
+ return mkfailure<value>(reason(r));
+ return value(mklist<value>(vto));
+}
+
+/**
+ * Chat sender component lambda function
+ */
+class chatSender {
+public:
+ chatSender(const lambda<value(const list<value>&)> jid, const lambda<value(const list<value>&)> pass, const lambda<value(const list<value>&)> to, const lambda<value(const list<value>&)> msg) : jid(jid), pass(pass), to(to), msg(msg) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ const tuscany::value func(car(params));
+ if (func == "get")
+ return post(jid, pass, to, msg, cdr(params));
+
+ // Stop the chat sender component
+ if (func != "stop")
+ return tuscany::mkfailure<tuscany::value>();
+ debug("chat::sender::stop");
+ return failable<value>(value(lambda<value(const list<value>&)>()));
+ }
+
+private:
+ const lambda<value(const list<value>&)> jid;
+ const lambda<value(const list<value>&)> pass;
+ const lambda<value(const list<value>&)> to;
+ const lambda<value(const list<value>&)> msg;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+
+ // Return the chat sender component lambda function
+ return value(lambda<value(const list<value>&)>(chatSender(car(params), cadr(params), caddr(params), cadddr(params))));
+}
+
+}
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::chat::sender::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}
diff --git a/sca-cpp/trunk/components/chat/server-test b/sca-cpp/trunk/components/chat/server-test
index dd1dc6faa7..fcac90741c 100755
--- a/sca-cpp/trunk/components/chat/server-test
+++ b/sca-cpp/trunk/components/chat/server-test
@@ -26,6 +26,8 @@ SCAContribution `pwd`/
SCAComposite chat.composite
EOF
+./vysper-start
+sleep 3
../../modules/http/httpd-start tmp
sleep 2
@@ -36,4 +38,6 @@ rc=$?
# Cleanup
../../modules/http/httpd-stop tmp
sleep 1
+./vysper-stop
+sleep 1
return $rc
diff --git a/sca-cpp/trunk/components/http/Makefile.am b/sca-cpp/trunk/components/http/Makefile.am
index 05e41bb9e1..4388ec8057 100644
--- a/sca-cpp/trunk/components/http/Makefile.am
+++ b/sca-cpp/trunk/components/http/Makefile.am
@@ -17,16 +17,21 @@
compdir=$(prefix)/components/http
-EXTRA_DIST = http.composite httpget.componentType *.scm
+EXTRA_DIST = http.composite httpget.componentType httpdelete.componentType *.scm
-comp_LTLIBRARIES = libhttpget.la
-noinst_DATA = libhttpget.so
+comp_LTLIBRARIES = libhttpget.la libhttpdelete.la
+noinst_DATA = libhttpget.so libhttpdelete.so
libhttpget_la_SOURCES = httpget.cpp
libhttpget_la_LDFLAGS = -lxml2 -lmozjs -curl
libhttpget.so:
ln -s .libs/libhttpget.so
+libhttpdelete_la_SOURCES = httpdelete.cpp
+libhttpdelete_la_LDFLAGS = -lxml2 -lmozjs -curl
+libhttpdelete.so:
+ ln -s .libs/libhttpdelete.so
+
client_test_SOURCES = client-test.cpp
client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
diff --git a/sca-cpp/trunk/components/http/httpdelete.componentType b/sca-cpp/trunk/components/http/httpdelete.componentType
new file mode 100644
index 0000000000..620f549e21
--- /dev/null
+++ b/sca-cpp/trunk/components/http/httpdelete.componentType
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/components">
+
+ <service name="http"/>
+ <reference name="url"/>
+
+</composite>
diff --git a/sca-cpp/trunk/components/http/httpdelete.cpp b/sca-cpp/trunk/components/http/httpdelete.cpp
new file mode 100644
index 0000000000..0bebfb9de2
--- /dev/null
+++ b/sca-cpp/trunk/components/http/httpdelete.cpp
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * HTTP client component implementation.
+ */
+
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "../../modules/http/http.hpp"
+
+namespace tuscany {
+namespace httpdelete {
+
+/**
+ * Evaluate an HTTP delete.
+ */
+const failable<value> get(const lambda<value(const list<value>&)> url, http::CURLSession& ch) {
+ debug("httpdelete::get");
+ const value u = url(mklist<value>("get", list<value>()));
+ debug(u, "httpdelete::get::url");
+ return http::del(u, ch);
+}
+
+/**
+ * Component implementation lambda function.
+ */
+class applyhttp {
+public:
+ applyhttp(const lambda<value(const list<value>&)> url, http::CURLSession& ch) : url(url), ch(ch) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ debug(params, "httpdelete::applyhttp::params");
+ const value func(car(params));
+ if (func == "get")
+ return get(url, ch);
+ return tuscany::mkfailure<tuscany::value>();
+ }
+
+private:
+ const lambda<value(const list<value>&)> url;
+ http::CURLSession& ch;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(const list<value>& params) {
+ // Create a CURL session
+ http::CURLSession& ch = *(new (gc_new<http::CURLSession>()) http::CURLSession("", "", ""));
+
+ // Return the component implementation lambda function
+ return value(lambda<value(const list<value>&)>(applyhttp(car(params), ch)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+ const tuscany::value func(car(params));
+ if (func == "start")
+ return tuscany::httpdelete::start(cdr(params));
+ return tuscany::mkfailure<tuscany::value>();
+}
+
+}