| 1 |
/** |
| 2 |
* This file is a part of the Cairo-Dock project |
| 3 |
* |
| 4 |
* Copyright : (C) see the 'copyright' file. |
| 5 |
* E-mail : see the 'copyright' file. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 3 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#define _BSD_SOURCE |
| 21 |
#include <stdlib.h> |
| 22 |
#include <math.h> |
| 23 |
#include <unistd.h> |
| 24 |
#include <glib/gstdio.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "applet-struct.h" |
| 28 |
#include "applet-dnd2share.h" |
| 29 |
#include "applet-backend-paste-ubuntu.h" |
| 30 |
|
| 31 |
#define URL "http://paste.ubuntu.com" |
| 32 |
#define FORMAT "text" |
| 33 |
|
| 34 |
#define NB_URLS 1 |
| 35 |
static const gchar *s_UrlLabels[NB_URLS] = {N_("Direct Link")}; |
| 36 |
|
| 37 |
/*HTTP/1.1 302 Found |
| 38 |
Date: Sun, 23 Jan 2011 00:48:37 GMT |
| 39 |
Server: Apache/2.2.8 (Ubuntu) mod_python/3.3.1 Python/2.5.2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_wsgi/1.3 mod_perl/2.0.3 Perl/v5.8.8 |
| 40 |
Vary: Cookie |
| 41 |
Content-Type: text/html; charset=utf-8 |
| 42 |
Location: http://paste.ubuntu.com/557014/ |
| 43 |
Content-Length: 0*/ |
| 44 |
|
| 45 |
static void upload (const gchar *cText, gchar *cLocalDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls, GError **pError) |
| 46 |
{ |
| 47 |
if (cText == NULL || *cText == '\0') |
| 48 |
{ |
| 49 |
g_set_error (pError, 1, 1, D_("Your text is empty and couldn't be uploaded to this server")); |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
GError *erreur = NULL; |
| 54 |
gchar *cResult = cairo_dock_get_url_data_with_post (URL, TRUE, &erreur, |
| 55 |
"content", cText, |
| 56 |
"poster", (bAnonymous ? "Anonymous" : g_getenv("USER")), |
| 57 |
"syntax", FORMAT, |
| 58 |
"submit", "Paste!", |
| 59 |
NULL); |
| 60 |
if (erreur) |
| 61 |
{ |
| 62 |
cd_warning (erreur->message); |
| 63 |
g_error_free (erreur); |
| 64 |
DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("paste.ubuntu.com"); |
| 65 |
} |
| 66 |
else if (cResult) |
| 67 |
{ |
| 68 |
cd_debug (" --> got '%s'", cResult); |
| 69 |
gchar *str = strstr (cResult, "Location:"); |
| 70 |
if (!str) |
| 71 |
{ |
| 72 |
DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("paste.ubuntu.com"); |
| 73 |
return; |
| 74 |
} |
| 75 |
str += 9; |
| 76 |
while (*str == ' ') |
| 77 |
str ++; |
| 78 |
gchar *rc = strchr (str, '\r'); // header's lines are separated by CRLF (\r\n). |
| 79 |
if (rc) |
| 80 |
*rc = '\0'; |
| 81 |
cResultUrls[0] = g_strdup (str); |
| 82 |
g_free (cResult); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
void cd_dnd2share_register_paste_ubuntu_backend (void) |
| 87 |
{ |
| 88 |
cd_dnd2share_register_new_backend (CD_TYPE_TEXT, |
| 89 |
"paste-ubuntu.com", |
| 90 |
NB_URLS, |
| 91 |
s_UrlLabels, |
| 92 |
0, |
| 93 |
upload); |
| 94 |
} |