~ubuntu-branches/ubuntu/vivid/cairo-dock-plug-ins/vivid

« back to all changes in this revision

Viewing changes to dnd2share/src/applet-backend-imagebin.c

  • Committer: Matthieu Baerts
  • Date: 2013-08-27 14:46:47 UTC
  • mto: (53.1.4 cairo-dock-plug-ins)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: matttbe@gmail.com-20130827144647-wm0kyawa8vcg0cso
Tags: upstream-3.2.99.beta1.1~20130827~bzr2928
Import upstream version 3.2.99.beta1.1~20130827~bzr2928

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "applet-backend-imagebin.h"
30
30
 
31
31
#define NB_URLS 1
32
 
static const gchar *s_UrlLabels[NB_URLS] = {"DirectLink"};
33
 
 
34
 
 
35
 
static void upload (const gchar *cFilePath, gchar *cDropboxDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls)
 
32
static const gchar *s_UrlLabels[NB_URLS] = {N_("Direct Link")};
 
33
 
 
34
 
 
35
static void upload (const gchar *cFilePath, gchar *cLocalDir, gboolean bAnonymous, gint iLimitRate, gchar **cResultUrls, GError **pError)
36
36
{
37
 
        // On cree un fichier de log temporaire.
38
 
        gchar *cLogFile = g_strdup ("/tmp/dnd2share-log.XXXXXX");
39
 
        int fds = mkstemp (cLogFile);
40
 
        if (fds == -1)
41
 
        {
42
 
                g_free (cLogFile);
43
 
                return ;
44
 
        }
45
 
        close(fds);
46
 
        
47
 
        // On lance la commande d'upload.
48
 
        gchar *cCommand = g_strdup_printf ("curl -L --connect-timeout 5 --retry 2 --limit-rate %dk http://imagebin.ca/upload.php -F f=@\"%s\" -F t=file -o \"%s\"", iLimitRate, cFilePath, cLogFile);
 
37
        // Upload the file
 
38
        gchar *cCommand = g_strdup_printf ("curl -L --connect-timeout 5 --retry 2 --limit-rate %dk http://imagebin.ca/upload.php -F f=@\"%s\" -F t=file", iLimitRate, cFilePath);
49
39
        cd_debug ("%s", cCommand);
50
 
        int r = system (cCommand);
51
 
        if (r < 0)
52
 
                cd_warning ("Not able to launch this command: %s", cCommand);
 
40
        gchar *cContent = cairo_dock_launch_command_sync (cCommand);
53
41
        g_free (cCommand);
54
 
        
55
 
        // On récupère l'URL dans le log :
 
42
 
 
43
        if (! cContent)
 
44
        {
 
45
                DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("ImageBin");
 
46
                return;
 
47
        }
 
48
 
 
49
        // We have the content, now we can extract data
56
50
        gchar *cURL = NULL;
57
 
        gchar *cContent = NULL;
58
 
        gsize length = 0;
59
 
        g_file_get_contents (cLogFile, &cContent, &length, NULL);
60
 
        gchar *str = g_strstr_len (cContent, -1, "href='");
 
51
        gchar *str = strstr (cContent, "href='");
61
52
        if (str != NULL)
62
53
        {
63
54
                str += 6;
69
60
                }
70
61
        }
71
62
        g_free (cContent);
72
 
        
73
 
        g_remove (cLogFile);
74
 
        g_free (cLogFile);
75
 
        
 
63
 
76
64
        if (cURL == NULL)
77
65
        {
78
 
                return ;
 
66
                DND2SHARE_SET_GENERIC_ERROR_WEBSITE ("ImageBin");
 
67
                return;
79
68
        }
80
 
        
81
 
        // Enfin on remplit la memoire partagee avec nos URLs.
 
69
 
82
70
        cResultUrls[0] = cURL;
83
71
}
84
72