Skip to content

Commit

Permalink
Merge pull request #166 from hildrum/httpFunc
Browse files Browse the repository at this point in the history
httpPost, httpGet, and httpPut
  • Loading branch information
hildrum committed Oct 6, 2015
2 parents 826e61d + 10ea47c commit 81b8672
Show file tree
Hide file tree
Showing 16 changed files with 688 additions and 18 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ impl/nl/include/*.h
/com.ibm.streamsx.inet/impl/nl/InetResource.dat

# generated operator models
/com.ibm.streamsx.inet/com.ibm.streamsx.inet.wsserver/WebSocketInject/WebSocketInject.xml
/com.ibm.streamsx.inet/com.ibm.streamsx.inet.wsserver/WebSocketSend/WebSocketSend.xm
/com.ibm.streamsx.inet/com.ibm.streamsx.inet.wsserver/WebSocketInject/*
/com.ibm.streamsx.inet/com.ibm.streamsx.inet.wsserver/WebSocketSend/*
/com.ibm.streamsx.inet/com.ibm.streamsx.inet.rest/*/*.gif
/com.ibm.streamsx.inet/com.ibm.streamsx.inet.http/*/*.gif

samples/*/output
samples/*/toolkit.xml
Expand Down
4 changes: 2 additions & 2 deletions com.ibm.streamsx.inet/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ artifacts were left around and caused issues with the ant build.
<target name="cpp">
<exec executable="make" failonerror="true" dir="impl">
<arg value="-f" />
<arg value="Makefile.libftp" />
<arg value="Makefile" />
<arg value="all" />
</exec>
</target>

<target name="cpp-clean">
<exec executable="make" failonerror="true" dir="impl">
<arg value="-f" />
<arg value="Makefile.libftp" />
<arg value="Makefile" />
<arg value="clean" />
</exec>
</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The command string and the command arguments are received from port 0.
<library>
<cmn:description>FTP wrapper lib</cmn:description>
<cmn:managedLibrary>
<cmn:lib>ftpwrapper</cmn:lib>
<cmn:lib>inettoolkit</cmn:lib>
<cmn:libPath>../../impl/lib</cmn:libPath>
<cmn:includePath>../../impl/cpp/include/libftp</cmn:includePath>
</cmn:managedLibrary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ You can optionally rename the file after you complete the transfer.</description
<library>
<cmn:description>FTP wrapper lib</cmn:description>
<cmn:managedLibrary>
<cmn:lib>ftpwrapper</cmn:lib>
<cmn:lib>inettoolkit</cmn:lib>
<cmn:libPath>../../impl/lib</cmn:libPath>
<cmn:includePath>../../impl/cpp/include/libftp</cmn:includePath>
</cmn:managedLibrary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ character. An complete empty line indicates an empty file. This function must no
<library>
<cmn:description>FTP wrapper lib</cmn:description>
<cmn:managedLibrary>
<cmn:lib>ftpwrapper</cmn:lib>
<cmn:lib>inettoolkit</cmn:lib>
<cmn:libPath>../../impl/lib</cmn:libPath>
<cmn:includePath>../../impl/cpp/include/libftp</cmn:includePath>
</cmn:managedLibrary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="ASCII"?>
<function:functionModel xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:function="http://www.ibm.com/xmlns/prod/streams/spl/function">
<function:functionSet>
<function:headerFileName>httpFunctions.h</function:headerFileName>
<function:cppNamespaceName>com_ibm_streamsx_inet_http</function:cppNamespaceName>
<function:functions>
<function:function>
<function:description>HTTP GET on the given url, using the username and password, if present. It follows redirects. If there is an error, a non-zero is returned by error.</function:description>
<function:prototype cppName="">public rstring httpGet(rstring url,list&lt;rstring> extraHeaders, rstring user, rstring password, mutable int32 error)</function:prototype>
</function:function>
<function:function>
<function:description>HTTP DELETE on the given url, using the username and password, if present. It follows redirects. If there is an error, a non-zero is returned by error.</function:description>
<function:prototype cppName="">public rstring httpDelete(rstring url,list&lt;rstring> extraHeaders, rstring user, rstring password, mutable int32 error)</function:prototype>
</function:function>
<function:function>
<function:description>HTTP PUT data to the given url using the username and password given if not empty. Does not follow redirects. Headers are returned in the headers list, error is set to a non-zero if there is an error, and the result of the PUT is returned in the rstring.</function:description>
<function:prototype>public rstring httpPut(rstring data, rstring url, list&lt;rstring> extraHeaders, rstring username, rstring password, mutable list&lt;rstring> headers, mutable int32 error)</function:prototype>
</function:function>
<function:function>
<function:description>HTTP POST data to the given url using the username and password (if non-empty). Does not follow redirects. Headers are returned in the headers list. Error is set to non-zero if there is an error. The result of the POST is returned as an rstring. </function:description>
<function:prototype>public rstring httpPost(rstring data, rstring url, list&lt;rstring> extraHeaders, rstring username, rstring password, mutable list&lt;rstring> headers, mutable int32 error)</function:prototype>
</function:function>
<function:function>
<function:description>Decode a URL encoded rstring.</function:description>
<function:prototype>public rstring urlDecode(rstring decode)</function:prototype>
</function:function>
<function:function>
<function:description>URL encode the given rstring.</function:description>
<function:prototype>public rstring urlEncode(rstring raw)</function:prototype>
</function:function>
</function:functions>
<function:dependencies>
<function:library>
<common:description></common:description>
<common:managedLibrary>
<common:lib>curl</common:lib>
<common:lib>inettoolkit</common:lib>
<common:libPath>../../impl/lib</common:libPath>
<common:includePath>../../impl/cpp/include</common:includePath>
</common:managedLibrary>
</function:library>
</function:dependencies>
</function:functionSet>
</function:functionModel>
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ SPL_LINK_OPTIONS = $(shell $(SPL_PKGCFG) --libs $(SPL_PKG))
# Folders
# -----------------------------------------------------------------------------
TRG := .
INC:= $(TRG)/cpp/include/libftp
INC:= $(TRG)/cpp/include
LIB := $(TRG)/lib
OBJ := $(TRG)/cpp/obj/libftp
SRC := $(TRG)/cpp/src/libftp
OBJ := $(TRG)/cpp/bin
SRC := $(TRG)/cpp/src

# -----------------------------------------------------------------------------
# phony targets are targets being not in the filesystem but are always "active"
Expand All @@ -34,7 +34,7 @@ SRC := $(TRG)/cpp/src/libftp
# Library
# -----------------------------------------------------------------------------

LIBRARY := $(LIB)/libftpwrapper.so
LIBRARY := $(LIB)/libinettoolkit.so

# -----------------------------------------------------------------------------
# Helpers
Expand All @@ -55,7 +55,7 @@ $(LIB) $(OBJ):

$(OBJ)/%.o: $(SRC)/%.cpp $(INCLUDES)
@echo Compiling '$<' ...
$(CXX) $(CXXFLAGS) -c $< -o $@
$(CXX) $(CXXFLAGS) -c $< -o $@ -I $(INC)

$(LIBRARY): $(LIB) $(OBJ) $(OBJECTS)
@echo Building C++ shared library '$@'
Expand All @@ -78,4 +78,4 @@ help:
@echo "all: clean build this is the default target"
@echo "clean: remove library and object files"
@echo "build: build the library"


28 changes: 28 additions & 0 deletions com.ibm.streamsx.inet/impl/cpp/include/httpFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef HTTP_FOR_STREAMS
#define HTTP_FOR_STREAMS
#include "curl/curl.h"
#include <SPL/Runtime/Type/Blob.h>
#include <SPL/Runtime/Type/List.h>

namespace com_ibm_streamsx_inet_http {


// We're just writing bytes.
size_t populate_rstring(char *ptr,size_t size, size_t nmemb, void*userdata);

SPL::rstring httpGet(const SPL::rstring & url, const SPL::list<SPL::rstring> & extraHeaders, const SPL::rstring & username, const SPL::rstring & password,SPL::int32 & error);

SPL::rstring httpDelete(const SPL::rstring & url, const SPL::list<SPL::rstring> & extraHeaders, const SPL::rstring & username, const SPL::rstring & password, SPL::int32 & error);

SPL::rstring httpPut(const SPL::rstring & data, const SPL::rstring & url, const SPL::list<SPL::rstring> & extraHeaders, const SPL::rstring & username, const SPL::rstring & password, SPL::list<SPL::rstring>& headers, SPL::int32 & error);

SPL::rstring httpPost(const SPL::rstring & data, const SPL::rstring & url, const SPL::list<SPL::rstring> & extraHeaders, const SPL::rstring & username, const SPL::rstring & password, SPL::list<SPL::rstring>& headers, SPL::int32 & error);


SPL::rstring urlEncode(const SPL::rstring & raw);

SPL::rstring urlDecode(const SPL::rstring & encoded);


}
#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright (C) 2013-2014, International Business Machines Corporation */
/* All Rights Reserved */

#include "../../include/libftp/FTPWrapper.h"
#include "FTPWrapper.h"
#include <SPL/Runtime/Common/RuntimeException.h>
#include <cstdio>
#include <iostream>
Expand Down
Loading

0 comments on commit 81b8672

Please sign in to comment.