forked from gregkh/smugbatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smug.h
142 lines (124 loc) · 4 KB
/
smug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright (C) 2008 Greg Kroah-Hartman <[email protected]>
*
* 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 version 2 of the License.
*
* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __SMUG_H
#define __SMUG_H
#include <curl/curl.h>
#include "list.h"
#define dbg(format, arg...) \
do { \
if (debug) \
printf("%s: " format , __func__ , ## arg); \
} while (0)
/**
* struct album: holds the information for one album/gallery
*
* entry: list structure to hook it with other albums
* id: the album id
* key: the album key
* title: the album title
* number: unique number for selection
* files: the list of files currently in this album
*/
struct album {
struct list_head entry;
char *id;
char *key;
char *title;
char *category;
char *subcategory;
int number;
struct list_head files;
};
#define MD5_LEN_MAX 16
struct filename {
struct list_head entry;
char *filename;
char *basename;
unsigned char md5[MD5_LEN_MAX];
char *id;
char *key;
char *caption;
char *size;
char *md5_string;
char *original_url;
};
struct session {
char *password;
char *email;
char *session_id;
char *su_cookie;
struct list_head albums;
struct list_head files_upload;
struct list_head files_download;
int quiet;
};
struct progress {
char *filename;
int position;
int total;
int upload;
time_t start;
};
struct smug_curl_buffer {
char *data;
int length;
};
#define zalloc(size) calloc(size, 1)
extern char *my_basename(char *name);
extern char *get_string_from_stdin(void);
extern struct smug_curl_buffer *smug_curl_buffer_alloc(void);
extern void smug_curl_buffer_free(struct smug_curl_buffer *buffer);
extern struct session *session_alloc(void);
extern void session_free(struct session *session);
extern size_t curl_callback(void *buffer, size_t size, size_t nmemb,
void *userp);
extern int curl_progress_func(void *arg_progress,
double dltotal, double dlnow,
double ultotal, double ulnow);
extern void album_list_free(struct list_head *albums);
extern void files_list_free(struct list_head *files);
extern char *find_value(const char *haystack, const char *needle,
char **new_pos);
extern int get_session_id(struct smug_curl_buffer *buffer,
struct session *session);
extern int get_albums(struct smug_curl_buffer *buffer,
struct session *session);
extern CURL *curl_init(void);
extern int upload_file(struct session *session, struct filename *filename,
struct album *album, int position, int total);
extern int upload_files(struct session *session, struct album *album);
extern struct album *select_album(const char *album_title,
const char *category_title,
const char *subcategory_title,
const char *quicksettings_name,
struct session *session);
extern int smug_login(struct session *session);
extern int smug_logout(struct session *session);
extern int generate_md5s(struct list_head *files);
extern char *smug_get_category_id(const char *category_title,
struct session *session);
extern struct album *smug_create_album(const char *album_title,
const char *category_title,
const char *subcategory_title,
const char *quicksettings_name,
struct session *session);
extern int smug_get_albums(struct session *session);
extern int smug_read_images(struct session *session, struct album *album);
extern void smug_parse_configfile(struct session *session);
extern int smug_download(struct session *session, struct filename *filename);
extern int debug;
#endif