From a066f19b60cb29419667e6c578525b7bab22b92b Mon Sep 17 00:00:00 2001 From: James Coxon Date: Sat, 20 Mar 2010 11:42:36 +0000 Subject: [PATCH] added extra.h which contains rjh pipe and also editted configure.ac to look for libcurl - currently does not make cleanly --- configure.ac | 9 ++++- src/main.cxx | 12 ++++++ src/misc/extra.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/misc/extra.h diff --git a/configure.ac b/configure.ac index 4e357e98..886595f4 100644 --- a/configure.ac +++ b/configure.ac @@ -206,13 +206,20 @@ AC_FLDIGI_XMLRPC # Define USE_OSS in config.h AC_FLDIGI_OSS +### libcurl +# check if curl is available +if test "x$ac_cv_want_fldigi" = "xyes"; then + AC_FLDIGI_PKG_CHECK([libcurl], [libcurl >= 7.20.0], [no], [no]) +fi + + ### libpng # Required if $ac_cv_want_fldigi is "yes" # Set ac_cv_png to yes/no (not used) # Define USE_PNG in config.h (as above) # Substitute PNG_CFLAGS and PNG_LIBS in Makefile if test "x$ac_cv_want_fldigi" = "xyes"; then - AC_FLDIGI_PKG_CHECK([png], [libpng >= 1.2.8], [no], [no]) + AC_FLDIGI_PKG_CHECK([png], [libpng >= 1.2.0], [no], [no]) fi ### libsamplerate diff --git a/src/main.cxx b/src/main.cxx index db3f0b5d..1c9cd3ab 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -112,6 +112,13 @@ using namespace std; +//jcoxon include files +#include +#include +#include +#include "misc/extra.h" +// + string appname; string scDevice[2]; @@ -188,10 +195,15 @@ static void arg_error(const char* name, const char* arg, bool missing) noreturn_ # define SHOW_WIZARD_BEFORE_MAIN_WINDOW 0 #endif + int main(int argc, char ** argv) { appname = argv[0]; debug_exec(argv); + + //jcoxon + serverCommunicator(); + // CREATE_THREAD_ID(); // only call this once SET_THREAD_ID(FLMAIN_TID); diff --git a/src/misc/extra.h b/src/misc/extra.h new file mode 100644 index 00000000..34a74003 --- /dev/null +++ b/src/misc/extra.h @@ -0,0 +1,100 @@ +#ifndef _EXTRA_H_ +#define _EXTRA_H_ + +//void UpperCase(string& str); + +/* RJH Pipe vars */ +int rjh_pfds[2]; +pid_t rjh_cpid; + + // This is the writer call back function used by curl + static int writer(char *data, size_t size, size_t nmemb, std::string *buffer) + { + // What we will return + int result = 0; + + // Is there anything in the buffer? + if (buffer != NULL) + { + // Append the data to the buffer + buffer->append(data, size * nmemb); + + // How much did we write? + result = size * nmemb; + } + + return result; + } + +int serverCommunicator() +{ + if (pipe(rjh_pfds) == -1) { perror("pipe"); exit(EXIT_FAILURE); } + + rjh_cpid = fork(); + + if (rjh_cpid == -1) { perror("fork"); exit(EXIT_FAILURE); } + if (rjh_cpid == 0) { + + char c; + char buffer [2000]; + int charpos = 0; + + CURL *easyhandle_status; + CURLcode result; + + // ofstream fout; + + // fout.clear(); + // fout.open ("log.txt"); + // if (fout.fail()) { + // cout << "Failed to open log.txt\n"; + // } + + /* Close the write side of the pipe */ + close(rjh_pfds[1]); + + buffer[0] ='\0'; + + while (read(rjh_pfds[0], &c, 1) > 0) + { + buffer[charpos] = c; + if (charpos <1999) charpos ++; + + if (c == '\n') + { + + if (charpos > 0) + buffer[charpos-1] = '\0'; + else + buffer[0] = '\0'; + + charpos=0; + + printf(" CHILD: received \"%s\"\n", buffer); + + // fout << "Buffer string : '" << buffer << "'" << endl; + + if (strlen(buffer) > 0) + { + easyhandle_status = curl_easy_init(); + if(easyhandle_status) { + curl_easy_setopt(easyhandle_status, CURLOPT_POSTFIELDS, buffer); + curl_easy_setopt(easyhandle_status, CURLOPT_URL, "http://www.robertharrison.org/listen/listen.php"); + result = curl_easy_perform(easyhandle_status); /* post away! */ + cout << "result: " << result << "\n"; + LOG_INFO("Server Data: %s", result); + curl_easy_cleanup(easyhandle_status); + } + } + buffer[0] = '\0'; + } + } + close(rjh_pfds[0]); + _exit (0); + } + + /* Close the read side of the pipe */ + close(rjh_pfds[0]); +} + +#endif \ No newline at end of file