citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
serv_bio.c
Go to the documentation of this file.
1// This module implements server commands related to the display and
2// manipulation of user profiles (also known as "bio" files).
3//
4// Copyright (c) 1987-2022 by the citadel.org team
5//
6// This program is open source software. Use, duplication, or disclosure
7// is subject to the terms of the GNU General Public License, version 3.
8// The program is distributed without any warranty, expressed or implied.
9
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <dirent.h>
13
14#include "../../ctdl_module.h"
15#include "../../config.h"
16
17
18// Command to enter user bio (profile) in plain text.
19// This is deprecated , or at least it will be when its replacement is written :)
20// I want commands to get/set bio in full MIME wonderfulness.
21void cmd_ebio(char *cmdbuf) {
22 char buf[SIZ];
23
25
26 if (!(CC->logged_in)) {
27 cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
28 return;
29 }
30
31 StrBuf *NewProfile = NewStrBufPlain("Content-type: text/plain; charset=UTF-8\nContent-transfer-encoding: 8bit\n\n", -1);
32
33 cprintf("%d Transmit user profile in plain text now.\n", SEND_LISTING);
34 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
35 StrBufAppendBufPlain(NewProfile, buf, -1, 0);
36 StrBufAppendBufPlain(NewProfile, HKEY("\n"), 0);
37 }
38
39 // we have read the new profile from the user , now save it
40 long old_msgnum = CC->user.msgnum_bio;
41 char userconfigroomname[ROOMNAMELEN];
42 CtdlMailboxName(userconfigroomname, sizeof userconfigroomname, &CC->user, USERCONFIGROOM);
43 long new_msgnum = quickie_message("Citadel", NULL, NULL, userconfigroomname, ChrPtr(NewProfile), FMT_RFC822, "Profile submitted with EBIO command");
44 FreeStrBuf(&NewProfile);
45 CtdlGetUserLock(&CC->user, CC->curr_user);
46 CC->user.msgnum_bio = new_msgnum;
47 CtdlPutUserLock(&CC->user);
48 if (old_msgnum > 0) {
49 syslog(LOG_DEBUG, "Deleting old message %ld from %s", old_msgnum, userconfigroomname);
50 CtdlDeleteMessages(userconfigroomname, &old_msgnum, 1, "");
51 }
52}
53
54
55// Command to read user bio (profile) in plain text.
56// This is deprecated , or at least it will be when its replacement is written :)
57// I want commands to get/set bio in full MIME wonderfulness.
58void cmd_rbio(char *cmdbuf) {
59 struct ctdluser ruser;
60 char buf[SIZ];
61
62 extract_token(buf, cmdbuf, 0, '|', sizeof buf);
63 if (CtdlGetUser(&ruser, buf) != 0) {
64 cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
65 return;
66 }
67
68 cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
69 ruser.fullname, ruser.usernum, ruser.axlevel,
70 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
71
72 struct CtdlMessage *msg = CtdlFetchMessage(ruser.msgnum_bio, 1);
73 if (msg != NULL) {
75 CM_Free(msg);
76 }
77 cprintf("000\n");
78}
79
80
81// Import function called by import_old_bio_files() for a single user
82void import_one_bio_file(char *username, long usernum, char *path) {
83 syslog(LOG_DEBUG, "Import legacy bio for %s, usernum=%ld, filename=%s", username, usernum, path);
84
85 FILE *fp = fopen(path, "r");
86 if (!fp) return;
87
88 fseek(fp, 0, SEEK_END);
89 long data_length = ftell(fp);
90
91 if (data_length >= 1) {
92 rewind(fp);
93 char *unencoded_data = malloc(data_length);
94 if (unencoded_data) {
95 fread(unencoded_data, data_length, 1, fp);
96 char *encoded_data = malloc((data_length * 2) + 100);
97 if (encoded_data) {
98 sprintf(encoded_data, "Content-type: text/plain; charset=UTF-8\nContent-transfer-encoding: base64\n\n");
99 CtdlEncodeBase64(&encoded_data[strlen(encoded_data)], unencoded_data, data_length, BASE64_YES_LINEBREAKS);
100
101 char userconfigroomname[ROOMNAMELEN];
102 struct ctdluser usbuf;
103
104 if (CtdlGetUser(&usbuf, username) == 0) { // no need to lock it , we are still initializing
105 long old_msgnum = usbuf.msgnum_bio;
106 CtdlMailboxName(userconfigroomname, sizeof userconfigroomname, &usbuf, USERCONFIGROOM);
107 long new_msgnum = quickie_message("Citadel", NULL, NULL, userconfigroomname, encoded_data, FMT_RFC822, "Profile imported from bio");
108 syslog(LOG_DEBUG, "Message %ld is now the profile for %s", new_msgnum, username);
109 usbuf.msgnum_bio = new_msgnum;
111 unlink(path); // delete the old file , it's in the database now
112 if (old_msgnum > 0) {
113 syslog(LOG_DEBUG, "Deleting old message %ld from %s", old_msgnum, userconfigroomname);
114 CtdlDeleteMessages(userconfigroomname, &old_msgnum, 1, "");
115 }
116 }
117 free(encoded_data);
118 }
119 free(unencoded_data);
120 }
121 }
122 fclose(fp);
123}
124
125
126// Look for old-format "bio" files and import them into the message base
128 DIR *filedir = NULL;
129 struct dirent *filedir_entry;
130 size_t d_namelen;
131 struct ctdluser usbuf;
132 long usernum = 0;
133 int d_type = 0;
134 struct stat s;
135 char path[PATH_MAX];
136
137 syslog(LOG_DEBUG, "Importing old style bio files into the message base");
138 filedir = opendir("bio");
139 if (filedir == NULL) {
140 return;
141 }
142 while ( (filedir_entry = readdir(filedir)) , (filedir_entry != NULL)) {
143#ifdef _DIRENT_HAVE_D_NAMLEN
144 d_namelen = filedir_entry->d_namlen;
145
146#else
147 d_namelen = strlen(filedir_entry->d_name);
148#endif
149
150#ifdef _DIRENT_HAVE_D_TYPE
151 d_type = filedir_entry->d_type;
152#else
153
154#ifndef DT_UNKNOWN
155#define DT_UNKNOWN 0
156#define DT_DIR 4
157#define DT_REG 8
158#define DT_LNK 10
159
160#define IFTODT(mode) (((mode) & 0170000) >> 12)
161#define DTTOIF(dirtype) ((dirtype) << 12)
162#endif
163 d_type = DT_UNKNOWN;
164#endif
165 if ((d_namelen == 1) &&
166 (filedir_entry->d_name[0] == '.'))
167 continue;
168
169 if ((d_namelen == 2) &&
170 (filedir_entry->d_name[0] == '.') &&
171 (filedir_entry->d_name[1] == '.'))
172 continue;
173
174 snprintf(path, PATH_MAX, "bio/%s", filedir_entry->d_name);
175 if (d_type == DT_UNKNOWN) {
176 if (lstat(path, &s) == 0) {
177 d_type = IFTODT(s.st_mode);
178 }
179 }
180 switch (d_type)
181 {
182 case DT_DIR:
183 break;
184 case DT_LNK:
185 case DT_REG:
186 usernum = atol(filedir_entry->d_name);
187 if (CtdlGetUserByNumber(&usbuf, usernum) == 0) {
188 import_one_bio_file(usbuf.fullname, usernum, path);
189 }
190 }
191 }
192 closedir(filedir);
193 rmdir("bio");
194}
195
196
197// Initialization function, called from modules_init.c
199 if (!threading) {
201 CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
202 CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
203 }
204 // return our module name for the log
205 return "bio";
206}
#define ROOMNAMELEN
Definition: citadel.h:51
#define CC
Definition: context.h:140
void CtdlPutUser(struct ctdluser *usbuf)
Definition: user_ops.c:107
void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
Definition: user_ops.c:305
int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
Definition: user_ops.c:398
int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
Definition: user_ops.c:95
int threading
Definition: modules_init.c:24
void CtdlPutUserLock(struct ctdluser *usbuf)
Definition: user_ops.c:121
int CtdlGetUser(struct ctdluser *usbuf, char *name)
Definition: user_ops.c:64
void CtdlRegisterProtoHook(void(*handler)(char *), char *cmd, char *desc)
#define LISTING_FOLLOWS
Definition: ipcdef.h:5
#define NOT_LOGGED_IN
Definition: ipcdef.h:17
#define ERROR
Definition: ipcdef.h:9
#define SEND_LISTING
Definition: ipcdef.h:8
#define NO_SUCH_USER
Definition: ipcdef.h:29
void CM_Free(struct CtdlMessage *msg)
Definition: msgbase.c:305
int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage, int mode, int headers_only, int do_proto, int crlf, int flags)
Definition: msgbase.c:1958
struct CtdlMessage * CtdlFetchMessage(long msgnum, int with_body)
Definition: msgbase.c:1128
int CtdlDeleteMessages(const char *room_name, long *dmsgnums, int num_dmsgnums, char *content_type)
Definition: msgbase.c:3229
long quickie_message(char *from, char *fromaddr, char *to, char *room, char *text, int format_type, char *subject)
Definition: msgbase.c:2906
#define HEADERS_NONE
Definition: msgbase.h:41
void * malloc(unsigned)
void free(void *)
#define DT_DIR
#define DT_UNKNOWN
void cmd_rbio(char *cmdbuf)
Definition: serv_bio.c:58
void import_one_bio_file(char *username, long usernum, char *path)
Definition: serv_bio.c:82
#define DT_REG
#define DT_LNK
char * ctdl_module_init_bio(void)
Definition: serv_bio.c:198
void cmd_ebio(char *cmdbuf)
Definition: serv_bio.c:21
void import_old_bio_files(void)
Definition: serv_bio.c:127
#define IFTODT(mode)
struct ctdluser usbuf
Definition: serv_migrate.c:496
#define FMT_RFC822
Definition: server.h:178
@ MT_CITADEL
Definition: server.h:166
long posted
Definition: citadel.h:75
long msgnum_bio
Definition: citadel.h:81
cit_uint8_t axlevel
Definition: citadel.h:76
char fullname[64]
Definition: citadel.h:80
time_t lastcall
Definition: citadel.h:78
long timescalled
Definition: citadel.h:74
long usernum
Definition: citadel.h:77
#define USERCONFIGROOM
Definition: sysconfig.h:64
#define SIZ
Definition: sysconfig.h:33
void cprintf(const char *format,...)
Definition: sysdep.c:369
int client_getln(char *buf, int bufsize)
Definition: sysdep.c:528
void unbuffer_output(void)
Definition: sysdep.c:268