parent
8b109d0736
commit
d3cb0ea6f6
9 changed files with 131 additions and 66 deletions
@ -1,17 +1,18 @@ |
||||
bin_PROGRAMS = ncmpcpp
|
||||
ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp conv.cpp display.cpp \
|
||||
error.cpp help.cpp helpers.cpp info.cpp lyrics.cpp media_library.cpp menu.cpp \
|
||||
mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp playlist_editor.cpp scrollpad.cpp \
|
||||
search_engine.cpp sel_items_adder.cpp server_info.cpp settings.cpp song.cpp status.cpp \
|
||||
tag_editor.cpp tiny_tag_editor.cpp tolower.cpp visualizer.cpp window.cpp
|
||||
ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp conv.cpp curl_handle.cpp \
|
||||
display.cpp error.cpp help.cpp helpers.cpp info.cpp lyrics.cpp media_library.cpp \
|
||||
menu.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp playlist_editor.cpp \
|
||||
scrollpad.cpp search_engine.cpp sel_items_adder.cpp server_info.cpp settings.cpp \
|
||||
song.cpp status.cpp tag_editor.cpp tiny_tag_editor.cpp tolower.cpp \
|
||||
visualizer.cpp window.cpp
|
||||
|
||||
# set the include path found by configure
|
||||
INCLUDES= $(all_includes)
|
||||
|
||||
# the library search path.
|
||||
ncmpcpp_LDFLAGS = $(all_libraries)
|
||||
noinst_HEADERS = browser.h charset.h clock.h conv.h display.h error.h global.h \
|
||||
help.h helpers.h home.h info.h lyrics.h media_library.h menu.h mpdpp.h \
|
||||
outputs.h playlist_editor.h screen.h scrollpad.h search_engine.h \
|
||||
noinst_HEADERS = browser.h charset.h clock.h conv.h curl_handle.h display.h \
|
||||
error.h global.h help.h helpers.h home.h info.h lyrics.h media_library.h menu.h \
|
||||
mpdpp.h outputs.h playlist_editor.h screen.h scrollpad.h search_engine.h \
|
||||
sel_items_adder.h server_info.h settings.h song.h tag_editor.h tiny_tag_editor.h \
|
||||
tolower.h visualizer.h window.h
|
||||
|
||||
@ -0,0 +1,67 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2008-2009 by Andrzej Rybczak * |
||||
* electricityispower@gmail.com * |
||||
* * |
||||
* This program is free software; you can redistribute it and/or modify * |
||||
* it under the terms of the GNU General Public License as published by * |
||||
* the Free Software Foundation; either version 2 of the License, or * |
||||
* (at your option) any later version. * |
||||
* * |
||||
* This program is distributed in the hope that it will be useful, * |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||||
* GNU General Public License for more details. * |
||||
* * |
||||
* You should have received a copy of the GNU General Public License * |
||||
* along with this program; if not, write to the * |
||||
* Free Software Foundation, Inc., * |
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * |
||||
***************************************************************************/ |
||||
|
||||
#include "curl_handle.h" |
||||
|
||||
#ifdef HAVE_CURL_CURL_H |
||||
|
||||
#include <cstdlib> |
||||
|
||||
namespace |
||||
{ |
||||
size_t write_data(char *buffer, size_t size, size_t nmemb, void *data) |
||||
{ |
||||
size_t result = size*nmemb; |
||||
static_cast<std::string *>(data)->append(buffer, result); |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
CURLcode Curl::perform(const std::string &URL, std::string &data, unsigned timeout) |
||||
{ |
||||
# ifdef HAVE_PTHREAD_H |
||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; |
||||
pthread_mutex_lock(&lock); |
||||
# endif |
||||
CURLcode result; |
||||
CURL *c = curl_easy_init(); |
||||
curl_easy_setopt(c, CURLOPT_URL, URL.c_str()); |
||||
curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, write_data); |
||||
curl_easy_setopt(c, CURLOPT_WRITEDATA, &data); |
||||
curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT, timeout); |
||||
curl_easy_setopt(c, CURLOPT_NOSIGNAL, 1); |
||||
result = curl_easy_perform(c); |
||||
curl_easy_cleanup(c); |
||||
# ifdef HAVE_PTHREAD_H |
||||
pthread_mutex_unlock(&lock); |
||||
# endif |
||||
return result; |
||||
} |
||||
|
||||
std::string Curl::escape(const std::string &s) |
||||
{ |
||||
char *cs = curl_easy_escape(0, s.c_str(), s.length()); |
||||
std::string result(cs); |
||||
curl_free(cs); |
||||
return result; |
||||
} |
||||
|
||||
#endif // HAVE_CURL_CURL_H
|
||||
|
||||
@ -0,0 +1,47 @@ |
||||
/***************************************************************************
|
||||
* Copyright (C) 2008-2009 by Andrzej Rybczak * |
||||
* electricityispower@gmail.com * |
||||
* * |
||||
* This program is free software; you can redistribute it and/or modify * |
||||
* it under the terms of the GNU General Public License as published by * |
||||
* the Free Software Foundation; either version 2 of the License, or * |
||||
* (at your option) any later version. * |
||||
* * |
||||
* This program is distributed in the hope that it will be useful, * |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||||
* GNU General Public License for more details. * |
||||
* * |
||||
* You should have received a copy of the GNU General Public License * |
||||
* along with this program; if not, write to the * |
||||
* Free Software Foundation, Inc., * |
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * |
||||
***************************************************************************/ |
||||
|
||||
#ifndef _CURL_HANDLE_H |
||||
#define _CURL_HANDLE_H |
||||
|
||||
#ifdef HAVE_CONFIG_H |
||||
# include "config.h" |
||||
#endif |
||||
|
||||
#ifdef HAVE_CURL_CURL_H |
||||
|
||||
#ifdef HAVE_PTHREAD_H |
||||
# include <pthread.h> |
||||
#endif // HAVE_PTHREAD_H
|
||||
|
||||
#include <string> |
||||
#include "curl/curl.h" |
||||
|
||||
namespace Curl |
||||
{ |
||||
CURLcode perform(const std::string &URL, std::string &data, unsigned timeout = 10); |
||||
|
||||
std::string escape(const std::string &s); |
||||
} |
||||
|
||||
#endif // HAVE_CURL_CURL_H
|
||||
|
||||
#endif |
||||
|
||||
Loading…
Reference in new issue