15#include "../../ctdl_module.h"
16#include "../../config.h"
28 if (
CC->room.msgnum_pic < 1) {
38 safestrncpy(
CC->download_desired_section,
"1",
sizeof CC->download_desired_section);
58 data_length = extract_long(cmdbuf, 0);
59 extract_token(mimetype, cmdbuf, 1,
'|',
sizeof mimetype);
61 if (data_length < 20) {
66 if (strncasecmp(mimetype,
"image/", 6)) {
71 char *unencoded_data =
malloc(data_length + 1);
72 if (!unencoded_data) {
81 char *encoded_data =
malloc((data_length * 2) + 100);
83 sprintf(encoded_data,
"Content-type: %s\nContent-transfer-encoding: base64\n\n", mimetype);
84 CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, BASE64_YES_LINEBREAKS);
88 long old_msgnum =
CC->room.msgnum_pic;
89 syslog(LOG_DEBUG,
"Message %ld is now the photo for %s", new_msgnum,
CC->room.QRname);
90 CC->room.msgnum_pic = new_msgnum;
93 syslog(LOG_DEBUG,
"Deleting old message %ld from %s", old_msgnum,
SYSCONFIGROOM);
100 free(unencoded_data);
113 extract_token(buf, cmdbuf, 0,
'|',
sizeof buf);
128 safestrncpy(
CC->download_desired_section,
"1",
sizeof CC->download_desired_section);
150 if (num_parms(cmdbuf) < 2) {
155 data_length = extract_long(cmdbuf, 0);
156 extract_token(mimetype, cmdbuf, 1,
'|',
sizeof mimetype);
157 extract_token(username, cmdbuf, 2,
'|',
sizeof username);
159 if (data_length < 20) {
164 if (strncasecmp(mimetype,
"image/", 6)) {
169 if (IsEmptyStr(username)) {
170 safestrncpy(username,
CC->curr_user,
sizeof username);
174 if ( (strcasecmp(username,
CC->curr_user)) && (
CC->user.axlevel < AxAideU) && (!
CC->internal_pgm) ) {
186 char *unencoded_data =
malloc(data_length + 1);
187 if (!unencoded_data) {
196 char *encoded_data =
malloc((data_length * 2) + 100);
198 sprintf(encoded_data,
"Content-type: %s\nContent-transfer-encoding: base64\n\n", mimetype);
199 CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, BASE64_YES_LINEBREAKS);
200 long new_msgnum =
quickie_message(
"Citadel", NULL, NULL, userconfigroomname, encoded_data,
FMT_RFC822,
"Photo uploaded by user");
204 syslog(LOG_DEBUG,
"Message %ld is now the photo for %s", new_msgnum, username);
207 if (old_msgnum > 0) {
208 syslog(LOG_DEBUG,
"Deleting old message %ld from %s", old_msgnum, userconfigroomname);
216 free(unencoded_data);
224 syslog(LOG_DEBUG,
"Import legacy userpic for %s, usernum=%ld, filename=%s", username,
usernum, path);
226 FILE *fp = fopen(path,
"r");
229 fseek(fp, 0, SEEK_END);
230 long data_length = ftell(fp);
232 if (data_length >= 1) {
234 char *unencoded_data =
malloc(data_length);
235 if (unencoded_data) {
236 fread(unencoded_data, data_length, 1, fp);
237 char *encoded_data =
malloc((data_length * 2) + 100);
239 sprintf(encoded_data,
"Content-type: %s\nContent-transfer-encoding: base64\n\n", GuessMimeByFilename(path, strlen(path)));
240 CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, BASE64_YES_LINEBREAKS);
248 long new_msgnum =
quickie_message(
"Citadel", NULL, NULL, userconfigroomname, encoded_data,
FMT_RFC822,
"Photo imported from file");
249 syslog(LOG_DEBUG,
"Message %ld is now the photo for %s", new_msgnum, username);
253 if (old_msgnum > 0) {
254 syslog(LOG_DEBUG,
"Deleting old message %ld from %s", old_msgnum, userconfigroomname);
260 free(unencoded_data);
272 struct dirent *filedir_entry;
281 syslog(LOG_DEBUG,
"Importing old style userpic files into the message base");
283 if (filedir == NULL) {
286 while ( (filedir_entry = readdir(filedir)) , (filedir_entry != NULL))
288#ifdef _DIRENT_HAVE_D_NAMLEN
289 d_namelen = filedir_entry->d_namlen;
292 d_namelen = strlen(filedir_entry->d_name);
295#ifdef _DIRENT_HAVE_D_TYPE
296 d_type = filedir_entry->d_type;
305#define IFTODT(mode) (((mode) & 0170000) >> 12)
306#define DTTOIF(dirtype) ((dirtype) << 12)
310 if ((d_namelen == 1) &&
311 (filedir_entry->d_name[0] ==
'.'))
314 if ((d_namelen == 2) &&
315 (filedir_entry->d_name[0] ==
'.') &&
316 (filedir_entry->d_name[1] ==
'.'))
319 snprintf(path, PATH_MAX,
"%s/%s",
ctdl_usrpic_dir, filedir_entry->d_name);
321 if (lstat(path, &s) == 0) {
322 d_type =
IFTODT(s.st_mode);
331 usernum = atol(filedir_entry->d_name);
void CtdlPutUser(struct ctdluser *usbuf)
void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name)
void CtdlPutUserLock(struct ctdluser *usbuf)
int CtdlGetUser(struct ctdluser *usbuf, char *name)
void CtdlPutRoomLock(struct ctdlroom *qrbuf)
void CtdlRegisterProtoHook(void(*handler)(char *), char *cmd, char *desc)
#define HIGHER_ACCESS_REQUIRED
#define MESSAGE_NOT_FOUND
void CM_Free(struct CtdlMessage *msg)
int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, int mode, int headers_only, int do_proto, int crlf, int flags)
struct CtdlMessage * CtdlFetchMessage(long msgnum, int with_body)
int CtdlDeleteMessages(const char *room_name, long *dmsgnums, int num_dmsgnums, char *content_type)
long quickie_message(char *from, char *fromaddr, char *to, char *room, char *text, int format_type, char *subject)
void cmd_ului(char *cmdbuf)
char * ctdl_module_init_image(void)
void cmd_dlui(char *cmdbuf)
void cmd_ulri(char *cmdbuf)
void import_one_userpic_file(char *username, long usernum, char *path)
void cmd_dlri(char *cmdbuf)
void import_old_userpic_files(void)
void cprintf(const char *format,...)
int client_read(char *buf, int bytes)