kopia lustrzana https://github.com/jamescoxon/dl-fldigi
added extra.h which contains rjh pipe and also editted configure.ac to look for libcurl - currently does not make cleanly
rodzic
30c247d71d
commit
a066f19b60
|
@ -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
|
||||
|
|
12
src/main.cxx
12
src/main.cxx
|
@ -112,6 +112,13 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
//jcoxon include files
|
||||
#include <curl/curl.h>
|
||||
#include <curl/types.h>
|
||||
#include <curl/easy.h>
|
||||
#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);
|
||||
|
||||
|
|
|
@ -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
|
Ładowanie…
Reference in New Issue