| 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-pastebin-mozilla.h" |
| 30 |
|
| 31 |
#define URL "http://pastebin.mozilla.org" |
| 32 |
#define FORMAT "text" |
| 33 |
#define EXPIRE "d" |
| 34 |
|
| 35 |
#define NB_URLS 1 |
| 36 |
static const gchar *s_UrlLabels[NB_URLS] = {N_("Direct Link")}; |
| 37 |
|
| 38 |
/*HTTP/1.1 302 Found |
| 39 |
Date: Sun, 23 Jan 2011 00:57:12 GMT |
| 40 |
Server: Apache |
| 41 |
X-Backend-Server: pm-app-generic03 |
| 42 |
X-Powered-By: PHP/5.2.9 |
| 43 |
Location: http://pastebin.mozilla.org/972341 |
| 44 |
Content-Length: 0 |
| 45 |
Content-Type: text/html; charset=UTF-8*/ |
| 46 |
|
| 47 |
|
| 48 |
static void upload (const gchar *cText, gchar *cLocalDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls, GError **pError) |
| 49 |
{ |
| 50 |
if (cText == NULL || *cText == '\0') |
| 51 |
{ |
| 52 |
g_set_error (pError, 1, 1, D_("Your text is empty and couldn't be uploaded to this server")); |
| 53 |
return; |
| 54 |
} |
| 55 |
GError *erreur = NULL; |
| 56 |
gchar *cResult = cairo_dock_get_url_data_with_post (URL, TRUE, &erreur, |
| 57 |
"code2", cText, |
| 58 |
"expiry", EXPIRE, |
| 59 |
"format", FORMAT, |
| 60 |
"paste", "Send", |
| 61 |
"poster", (bAnonymous ? "Anonymous" : g_getenv("USER")), |
| 62 |
"remember", "0", |
| 63 |
"parent_pid", "", |
| 64 |
NULL); |
| 65 |
if (erreur) |
| 66 |
{ |
| 67 |
cd_warning (erreur->message); |
| 68 |
g_error_free (erreur); |
| 69 |
DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("Pastebin Mozilla"); |
| 70 |
} |
| 71 |
else if (cResult) |
| 72 |
{ |
| 73 |
cd_debug (" --> got '%s'", cResult); |
| 74 |
gchar *str = strstr (cResult, "Location:"); |
| 75 |
if (!str) |
| 76 |
{ |
| 77 |
DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("Pastebin Mozilla"); |
| 78 |
return; |
| 79 |
} |
| 80 |
str += 9; |
| 81 |
while (*str == ' ') |
| 82 |
str ++; |
| 83 |
gchar *rc = strchr (str, '\r'); // header's lines are separated by CRLF (\r\n). |
| 84 |
if (rc) |
| 85 |
*rc = '\0'; |
| 86 |
cResultUrls[0] = g_strdup (str); |
| 87 |
g_free (cResult); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
void cd_dnd2share_register_pastebin_mozilla_backend (void) |
| 93 |
{ |
| 94 |
cd_dnd2share_register_new_backend (CD_TYPE_TEXT, |
| 95 |
"pastebin-mozilla.org", |
| 96 |
NB_URLS, |
| 97 |
s_UrlLabels, |
| 98 |
0, |
| 99 |
upload); |
| 100 |
} |