Modified the behavior of ForEachUser() to do the two phase load/perform cycle
[citadel.git] / citadel / modules / migrate / serv_migrate.c
1 /*
2  * This module dumps and/or loads the Citadel database in XML format.
3  *
4  * Copyright (c) 1987-2019 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 /*
16  * Explanation of <progress> tags:
17  *
18  * 0%              nothing
19  * 2%              finished exporting configuration
20  * 7%              finished exporting users
21  * 12%             finished exporting openids
22  * 17%             finished exporting rooms
23  * 18%             finished exporting floors
24  * 25%             finished exporting visits
25  * 100%            finished exporting messages
26  */
27
28 #include "sysdep.h"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <stdio.h>
32 #include <fcntl.h>
33 #include <signal.h>
34 #include <pwd.h>
35 #include <errno.h>
36 #include <sys/types.h>
37
38 #if TIME_WITH_SYS_TIME
39 # include <sys/time.h>
40 # include <time.h>
41 #else
42 # if HAVE_SYS_TIME_H
43 #  include <sys/time.h>
44 # else
45 #  include <time.h>
46 # endif
47 #endif
48
49 #include <sys/wait.h>
50 #include <string.h>
51 #include <ctype.h>
52 #include <limits.h>
53 #include <expat.h>
54 #include <libcitadel.h>
55 #include "citadel.h"
56 #include "server.h"
57 #include "citserver.h"
58 #include "support.h"
59 #include "config.h"
60 #include "database.h"
61 #include "msgbase.h"
62 #include "user_ops.h"
63 #include "euidindex.h"
64 #include "ctdl_module.h"
65
66 #define END_OF_MESSAGE  "---eom---dbd---"
67
68 char migr_tempfilename1[PATH_MAX];
69 char migr_tempfilename2[PATH_MAX];
70 FILE *migr_global_message_list;
71 int total_msgs = 0;
72 char *ikey = NULL;                      // If we're importing a config key we store it here.
73
74
75 /******************************************************************************
76  *        Code which implements the export appears in this section            *
77  ******************************************************************************/
78
79 /*
80  * Output a string to the client with these characters escaped:  & < > " '
81  */
82 void xml_strout(char *str) {
83
84         char *c = str;
85
86         if (str == NULL) {
87                 return;
88         }
89
90         while (*c != 0) {
91                 if (*c == '\"') {
92                         client_write(HKEY("&quot;"));
93                 }
94                 else if (*c == '\'') {
95                         client_write(HKEY("&apos;"));
96                 }
97                 else if (*c == '<') {
98                         client_write(HKEY("&lt;"));
99                 }
100                 else if (*c == '>') {
101                         client_write(HKEY("&gt;"));
102                 }
103                 else if (*c == '&') {
104                         client_write(HKEY("&amp;"));
105                 }
106                 else {
107                         client_write(c, 1);
108                 }
109                 ++c;
110         }
111 }
112
113
114 /*
115  * Export a user record as XML
116  */
117 void migr_export_users_backend(char *username, void *data) {
118
119         struct ctdluser u;
120         if (CtdlGetUser(&u, username) != 0) {
121                 return;
122         }
123
124         client_write(HKEY("<user>\n"));
125         cprintf("<u_version>%d</u_version>\n", u.version);
126         cprintf("<u_uid>%ld</u_uid>\n", (long)u.uid);
127         client_write(HKEY("<u_password>"));     xml_strout(u.password);         client_write(HKEY("</u_password>\n"));
128         cprintf("<u_flags>%u</u_flags>\n", u.flags);
129         cprintf("<u_timescalled>%ld</u_timescalled>\n", u.timescalled);
130         cprintf("<u_posted>%ld</u_posted>\n", u.posted);
131         cprintf("<u_axlevel>%d</u_axlevel>\n", u.axlevel);
132         cprintf("<u_usernum>%ld</u_usernum>\n", u.usernum);
133         cprintf("<u_lastcall>%ld</u_lastcall>\n", (long)u.lastcall);
134         cprintf("<u_USuserpurge>%d</u_USuserpurge>\n", u.USuserpurge);
135         client_write(HKEY("<u_fullname>"));     xml_strout(u.fullname);         client_write(HKEY("</u_fullname>\n"));
136         cprintf("<u_msgnum_bio>%ld</u_msgnum_bio>\n", u.msgnum_bio);
137         cprintf("<u_msgnum_pic>%ld</u_msgnum_pic>\n", u.msgnum_pic);
138         client_write(HKEY("</user>\n"));
139 }
140
141
142 void migr_export_users(void) {
143         ForEachUser(migr_export_users_backend, NULL);
144 }
145
146
147 void migr_export_room_msg(long msgnum, void *userdata) {
148         cprintf("%ld\n", msgnum);
149         fprintf(migr_global_message_list, "%ld\n", msgnum);
150 }
151
152
153 void migr_export_rooms_backend(struct ctdlroom *buf, void *data) {
154         client_write(HKEY("<room>\n"));
155         client_write(HKEY("<QRname>")); xml_strout(buf->QRname);        client_write(HKEY("</QRname>\n"));
156         client_write(HKEY("<QRpasswd>"));       xml_strout(buf->QRpasswd);      client_write(HKEY("</QRpasswd>\n"));
157         cprintf("<QRroomaide>%ld</QRroomaide>\n", buf->QRroomaide);
158         cprintf("<QRhighest>%ld</QRhighest>\n", buf->QRhighest);
159         cprintf("<QRgen>%ld</QRgen>\n", (long)buf->QRgen);
160         cprintf("<QRflags>%u</QRflags>\n", buf->QRflags);
161         if (buf->QRflags & QR_DIRECTORY) {
162                 client_write(HKEY("<QRdirname>"));
163                 xml_strout(buf->QRdirname);
164                 client_write(HKEY("</QRdirname>\n"));
165         }
166         cprintf("<QRfloor>%d</QRfloor>\n", buf->QRfloor);
167         cprintf("<QRmtime>%ld</QRmtime>\n", (long)buf->QRmtime);
168         cprintf("<QRexpire_mode>%d</QRexpire_mode>\n", buf->QRep.expire_mode);
169         cprintf("<QRexpire_value>%d</QRexpire_value>\n", buf->QRep.expire_value);
170         cprintf("<QRnumber>%ld</QRnumber>\n", buf->QRnumber);
171         cprintf("<QRorder>%d</QRorder>\n", buf->QRorder);
172         cprintf("<QRflags2>%u</QRflags2>\n", buf->QRflags2);
173         cprintf("<QRdefaultview>%d</QRdefaultview>\n", buf->QRdefaultview);
174         cprintf("<msgnum_info>%ld</msgnum_info>\n", buf->msgnum_info);
175         cprintf("<msgnum_pic>%ld</msgnum_pic>\n", buf->msgnum_pic);
176         client_write(HKEY("</room>\n"));
177
178         /* message list goes inside this tag */
179
180         CtdlGetRoom(&CC->room, buf->QRname);
181         client_write(HKEY("<room_messages>"));
182         client_write(HKEY("<FRname>")); xml_strout(CC->room.QRname);    client_write(HKEY("</FRname>\n"));
183         client_write(HKEY("<FRmsglist>"));
184         CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, migr_export_room_msg, NULL);
185         client_write(HKEY("</FRmsglist>\n"));
186         client_write(HKEY("</room_messages>\n"));
187
188
189 }
190
191
192 void migr_export_rooms(void) {
193         char cmd[SIZ];
194         migr_global_message_list = fopen(migr_tempfilename1, "w");
195         if (migr_global_message_list != NULL) {
196                 CtdlForEachRoom(migr_export_rooms_backend, NULL);
197                 fclose(migr_global_message_list);
198         }
199
200         /*
201          * Process the 'global' message list.  (Sort it and remove dups.
202          * Dups are ok because a message may be in more than one room, but
203          * this will be handled by exporting the reference count, not by
204          * exporting the message multiple times.)
205          */
206         snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
207         if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d", errno);
208         snprintf(cmd, sizeof cmd, "uniq <%s >%s", migr_tempfilename2, migr_tempfilename1);
209         if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d", errno);
210
211
212         snprintf(cmd, sizeof cmd, "wc -l %s", migr_tempfilename1);
213         FILE *fp = popen(cmd, "r");
214         if (fp) {
215                 fgets(cmd, sizeof cmd, fp);
216                 pclose(fp);
217                 total_msgs = atoi(cmd);
218         }
219         else {
220                 total_msgs = 1; // any nonzero just to keep it from barfing
221         }
222         syslog(LOG_DEBUG, "Total messages to be exported: %d", total_msgs);
223 }
224
225
226 void migr_export_floors(void) {
227         struct floor qfbuf, *buf;
228         int i;
229
230         for (i=0; i < MAXFLOORS; ++i) {
231                 client_write(HKEY("<floor>\n"));
232                 cprintf("<f_num>%d</f_num>\n", i);
233                 CtdlGetFloor(&qfbuf, i);
234                 buf = &qfbuf;
235                 cprintf("<f_flags>%u</f_flags>\n", buf->f_flags);
236                 client_write(HKEY("<f_name>")); xml_strout(buf->f_name); client_write(HKEY("</f_name>\n"));
237                 cprintf("<f_ref_count>%d</f_ref_count>\n", buf->f_ref_count);
238                 cprintf("<f_ep_expire_mode>%d</f_ep_expire_mode>\n", buf->f_ep.expire_mode);
239                 cprintf("<f_ep_expire_value>%d</f_ep_expire_value>\n", buf->f_ep.expire_value);
240                 client_write(HKEY("</floor>\n"));
241         }
242 }
243
244
245 /*
246  * Return nonzero if the supplied string contains only characters which are valid in a sequence set.
247  */
248 int is_sequence_set(char *s) {
249         if (!s) return(0);
250
251         char *c = s;
252         char ch;
253         while (ch = *c++, ch) {
254                 if (!strchr("0123456789*,:", ch)) {
255                         return(0);
256                 }
257         }
258         return(1);
259 }
260
261
262 /* 
263  *  Traverse the visits file...
264  */
265 void migr_export_visits(void) {
266         visit vbuf;
267         struct cdbdata *cdbv;
268
269         cdb_rewind(CDB_VISIT);
270
271         while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) {
272                 memset(&vbuf, 0, sizeof(visit));
273                 memcpy(&vbuf, cdbv->ptr,
274                        ((cdbv->len > sizeof(visit)) ?
275                         sizeof(visit) : cdbv->len));
276                 cdb_free(cdbv);
277
278                 client_write(HKEY("<visit>\n"));
279                 cprintf("<v_roomnum>%ld</v_roomnum>\n", vbuf.v_roomnum);
280                 cprintf("<v_roomgen>%ld</v_roomgen>\n", vbuf.v_roomgen);
281                 cprintf("<v_usernum>%ld</v_usernum>\n", vbuf.v_usernum);
282
283                 client_write(HKEY("<v_seen>"));
284                 if ( (!IsEmptyStr(vbuf.v_seen)) && (is_sequence_set(vbuf.v_seen)) ) {
285                         xml_strout(vbuf.v_seen);
286                 }
287                 else {
288                         cprintf("%ld", vbuf.v_lastseen);
289                 }
290                 client_write(HKEY("</v_seen>"));
291
292                 if ( (!IsEmptyStr(vbuf.v_answered)) && (is_sequence_set(vbuf.v_answered)) ) {
293                         client_write(HKEY("<v_answered>"));
294                         xml_strout(vbuf.v_answered);
295                         client_write(HKEY("</v_answered>\n"));
296                 }
297
298                 cprintf("<v_flags>%u</v_flags>\n", vbuf.v_flags);
299                 cprintf("<v_view>%d</v_view>\n", vbuf.v_view);
300                 client_write(HKEY("</visit>\n"));
301         }
302 }
303
304
305 void migr_export_message(long msgnum) {
306         struct MetaData smi;
307         struct CtdlMessage *msg;
308         struct ser_ret smr;
309
310         /* We can use a static buffer here because there will never be more than
311          * one of this operation happening at any given time, and it's really best
312          * to just keep it allocated once instead of torturing malloc/free.
313          * Call this function with msgnum "-1" to free the buffer when finished.
314          */
315         static int encoded_alloc = 0;
316         static char *encoded_msg = NULL;
317
318         if (msgnum < 0) {
319                 if ((encoded_alloc == 0) && (encoded_msg != NULL)) {
320                         free(encoded_msg);
321                         encoded_alloc = 0;
322                         encoded_msg = NULL;
323                 }
324                 return;
325         }
326
327         /* Ok, here we go ... */
328
329         msg = CtdlFetchMessage(msgnum, 1, 0);
330         if (msg == NULL) return;        /* fail silently */
331
332         client_write(HKEY("<message>\n"));
333         GetMetaData(&smi, msgnum);
334         cprintf("<msg_msgnum>%ld</msg_msgnum>\n", msgnum);
335         cprintf("<msg_meta_refcount>%d</msg_meta_refcount>\n", smi.meta_refcount);
336         cprintf("<msg_meta_rfc822_length>%ld</msg_meta_rfc822_length>\n", smi.meta_rfc822_length);
337         client_write(HKEY("<msg_meta_content_type>")); xml_strout(smi.meta_content_type); client_write(HKEY("</msg_meta_content_type>\n"));
338
339         client_write(HKEY("<msg_text>"));
340         CtdlSerializeMessage(&smr, msg);
341         CM_Free(msg);
342
343         /* Predict the buffer size we need.  Expand the buffer if necessary. */
344         int encoded_len = smr.len * 15 / 10 ;
345         if (encoded_len > encoded_alloc) {
346                 encoded_alloc = encoded_len;
347                 encoded_msg = realloc(encoded_msg, encoded_alloc);
348         }
349
350         if (encoded_msg == NULL) {
351                 /* Questionable hack that hopes it'll work next time and we only lose one message */
352                 encoded_alloc = 0;
353         }
354         else {
355                 /* Once we do the encoding we know the exact size */
356                 encoded_len = CtdlEncodeBase64(encoded_msg, (char *)smr.ser, smr.len, 1);
357                 client_write(encoded_msg, encoded_len);
358         }
359
360         free(smr.ser);
361
362         client_write(HKEY("</msg_text>\n"));
363         client_write(HKEY("</message>\n"));
364 }
365
366
367 void migr_export_openids(void) {
368         struct cdbdata *cdboi;
369         long usernum;
370         char url[512];
371
372         cdb_rewind(CDB_EXTAUTH);
373         while (cdboi = cdb_next_item(CDB_EXTAUTH), cdboi != NULL) {
374                 if (cdboi->len > sizeof(long)) {
375                         client_write(HKEY("<openid>\n"));
376                         memcpy(&usernum, cdboi->ptr, sizeof(long));
377                         snprintf(url, sizeof url, "%s", (cdboi->ptr)+sizeof(long) );
378                         client_write(HKEY("<oid_url>"));
379                         xml_strout(url);
380                         client_write(HKEY("</oid_url>\n"));
381                         cprintf("<oid_usernum>%ld</oid_usernum>\n", usernum);
382                         client_write(HKEY("</openid>\n"));
383                 }
384                 cdb_free(cdboi);
385         }
386 }
387
388
389 void migr_export_configs(void) {
390         struct cdbdata *cdbcfg;
391         int keylen = 0;
392         char *key = NULL;
393         char *value = NULL;
394
395         cdb_rewind(CDB_CONFIG);
396         while (cdbcfg = cdb_next_item(CDB_CONFIG), cdbcfg != NULL) {
397
398                 keylen = strlen(cdbcfg->ptr);
399                 key = cdbcfg->ptr;
400                 value = cdbcfg->ptr + keylen + 1;
401
402                 client_write("<config key=\"", 13);
403                 xml_strout(key);
404                 client_write("\">", 2);
405                 xml_strout(value);
406                 client_write("</config>\n", 10);
407                 cdb_free(cdbcfg);
408         }
409 }
410
411
412 void migr_export_messages(void) {
413         char buf[SIZ];
414         long msgnum;
415         int count = 0;
416         int progress = 0;
417         int prev_progress = 0;
418         CitContext *Ctx;
419
420         Ctx = CC;
421         migr_global_message_list = fopen(migr_tempfilename1, "r");
422         if (migr_global_message_list != NULL) {
423                 syslog(LOG_INFO, "Opened %s", migr_tempfilename1);
424                 while ((Ctx->kill_me == 0) && 
425                        (fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) {
426                         msgnum = atol(buf);
427                         if (msgnum > 0L) {
428                                 migr_export_message(msgnum);
429                                 ++count;
430                         }
431                         progress = (count * 74 / total_msgs) + 25 ;
432                         if ((progress > prev_progress) && (progress < 100)) {
433                                 cprintf("<progress>%d</progress>\n", progress);
434                         }
435                         prev_progress = progress;
436                 }
437                 fclose(migr_global_message_list);
438         }
439         if (Ctx->kill_me == 0) {
440                 syslog(LOG_INFO, "Exported %d messages.", count);
441         }
442         else {
443                 syslog(LOG_ERR, "Export aborted due to client disconnect!");
444         }
445
446         migr_export_message(-1L);       /* This frees the encoding buffer */
447 }
448
449
450 void migr_do_export(void) {
451         CitContext *Ctx;
452
453         Ctx = CC;
454         cprintf("%d Exporting all Citadel databases.\n", LISTING_FOLLOWS);
455         Ctx->dont_term = 1;
456
457         client_write(HKEY("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"));
458         client_write(HKEY("<citadel_migrate_data>\n"));
459         cprintf("<version>%d</version>\n", REV_LEVEL);
460         cprintf("<progress>%d</progress>\n", 0);
461
462         /* export the configuration database */
463         migr_export_configs();
464         cprintf("<progress>%d</progress>\n", 2);
465         
466         if (Ctx->kill_me == 0)  migr_export_users();
467         cprintf("<progress>%d</progress>\n", 7);
468         if (Ctx->kill_me == 0)  migr_export_openids();
469         cprintf("<progress>%d</progress>\n", 12);
470         if (Ctx->kill_me == 0)  migr_export_rooms();
471         cprintf("<progress>%d</progress>\n", 17);
472         if (Ctx->kill_me == 0)  migr_export_floors();
473         cprintf("<progress>%d</progress>\n", 18);
474         if (Ctx->kill_me == 0)  migr_export_visits();
475         cprintf("<progress>%d</progress>\n", 25);
476         if (Ctx->kill_me == 0)  migr_export_messages();
477         client_write(HKEY("</citadel_migrate_data>\n"));
478         cprintf("<progress>%d</progress>\n", 100);
479         client_write(HKEY("000\n"));
480         Ctx->dont_term = 0;
481 }
482
483
484 /******************************************************************************
485  *                              Import code                                   *
486  *    Here's the code that implements the import side.  It's going to end up  *
487  *        being one big loop with lots of global variables.  I don't care.    *
488  * You wouldn't run multiple concurrent imports anyway.  If this offends your *
489  * delicate sensibilities  then go rewrite it in Ruby on Rails or something.  *
490  ******************************************************************************/
491
492
493 int citadel_migrate_data = 0;           /* Are we inside a <citadel_migrate_data> tag pair? */
494 StrBuf *migr_chardata = NULL;
495 StrBuf *migr_MsgData = NULL;
496 struct ctdluser usbuf;
497 struct ctdlroom qrbuf;
498 char openid_url[512];
499 long openid_usernum = 0;
500 char FRname[ROOMNAMELEN];
501 struct floor flbuf;
502 int floornum = 0;
503 visit vbuf;
504 struct MetaData smi;
505 long import_msgnum = 0;
506
507 /*
508  * This callback stores up the data which appears in between tags.
509  */
510 void migr_xml_chardata(void *data, const XML_Char *s, int len)
511 {
512         StrBufAppendBufPlain(migr_chardata, s, len, 0);
513 }
514
515
516 void migr_xml_start(void *data, const char *el, const char **attr) {
517         int i;
518
519         /*** GENERAL STUFF ***/
520
521         /* Reset chardata_len to zero and init buffer */
522         FlushStrBuf(migr_chardata);
523         FlushStrBuf(migr_MsgData);
524
525         if (!strcasecmp(el, "citadel_migrate_data")) {
526                 ++citadel_migrate_data;
527
528                 /* As soon as it looks like the input data is a genuine Citadel XML export,
529                  * whack the existing database on disk to make room for the new one.
530                  */
531                 if (citadel_migrate_data == 1) {
532                         for (i = 0; i < MAXCDB; ++i) {
533                                 cdb_trunc(i);
534                         }
535                 }
536                 return;
537         }
538
539         if (citadel_migrate_data != 1) {
540                 syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected.  Warning: ODD-DATA!", el);
541                 return;
542         }
543
544         /* When we begin receiving XML for one of these record types, clear out the associated
545          * buffer so we don't accidentally carry over any data from a previous record.
546          */
547         if (!strcasecmp(el, "user"))                    memset(&usbuf, 0, sizeof (struct ctdluser));
548         else if (!strcasecmp(el, "openid"))             memset(openid_url, 0, sizeof openid_url);
549         else if (!strcasecmp(el, "room"))               memset(&qrbuf, 0, sizeof (struct ctdlroom));
550         else if (!strcasecmp(el, "room_messages"))      memset(FRname, 0, sizeof FRname);
551         else if (!strcasecmp(el, "floor"))              memset(&flbuf, 0, sizeof (struct floor));
552         else if (!strcasecmp(el, "visit"))              memset(&vbuf, 0, sizeof (visit));
553
554         else if (!strcasecmp(el, "message")) {
555                 memset(&smi, 0, sizeof (struct MetaData));
556                 import_msgnum = 0;
557         }
558         else if (!strcasecmp(el, "config")) {
559                 if (ikey != NULL) {
560                         free(ikey);
561                         ikey = NULL;
562                 }
563                 while (*attr) {
564                         if (!strcasecmp(attr[0], "key")) {
565                                 ikey = strdup(attr[1]);
566                         }
567                         attr += 2;
568                 }
569         }
570
571 }
572
573
574 int migr_userrecord(void *data, const char *el)
575 {
576         if (!strcasecmp(el, "u_version"))                       usbuf.version = atoi(ChrPtr(migr_chardata));
577         else if (!strcasecmp(el, "u_uid"))                      usbuf.uid = atol(ChrPtr(migr_chardata));
578         else if (!strcasecmp(el, "u_password"))                 safestrncpy(usbuf.password, ChrPtr(migr_chardata), sizeof usbuf.password);
579         else if (!strcasecmp(el, "u_flags"))                    usbuf.flags = atoi(ChrPtr(migr_chardata));
580         else if (!strcasecmp(el, "u_timescalled"))              usbuf.timescalled = atol(ChrPtr(migr_chardata));
581         else if (!strcasecmp(el, "u_posted"))                   usbuf.posted = atol(ChrPtr(migr_chardata));
582         else if (!strcasecmp(el, "u_axlevel"))                  usbuf.axlevel = atoi(ChrPtr(migr_chardata));
583         else if (!strcasecmp(el, "u_usernum"))                  usbuf.usernum = atol(ChrPtr(migr_chardata));
584         else if (!strcasecmp(el, "u_lastcall"))                 usbuf.lastcall = atol(ChrPtr(migr_chardata));
585         else if (!strcasecmp(el, "u_USuserpurge"))              usbuf.USuserpurge = atoi(ChrPtr(migr_chardata));
586         else if (!strcasecmp(el, "u_fullname"))                 safestrncpy(usbuf.fullname, ChrPtr(migr_chardata), sizeof usbuf.fullname);
587         else if (!strcasecmp(el, "u_msgnum_bio"))               usbuf.msgnum_bio = atol(ChrPtr(migr_chardata));
588         else if (!strcasecmp(el, "u_msgnum_pic"))               usbuf.msgnum_pic = atol(ChrPtr(migr_chardata));
589         else return 0;
590         return 1;
591 }
592
593
594 int migr_roomrecord(void *data, const char *el)
595 {
596         if (!strcasecmp(el, "QRname"))                          safestrncpy(qrbuf.QRname, ChrPtr(migr_chardata), sizeof qrbuf.QRname);
597         else if (!strcasecmp(el, "QRpasswd"))                   safestrncpy(qrbuf.QRpasswd, ChrPtr(migr_chardata), sizeof qrbuf.QRpasswd);
598         else if (!strcasecmp(el, "QRroomaide"))                 qrbuf.QRroomaide = atol(ChrPtr(migr_chardata));
599         else if (!strcasecmp(el, "QRhighest"))                  qrbuf.QRhighest = atol(ChrPtr(migr_chardata));
600         else if (!strcasecmp(el, "QRgen"))                      qrbuf.QRgen = atol(ChrPtr(migr_chardata));
601         else if (!strcasecmp(el, "QRflags"))                    qrbuf.QRflags = atoi(ChrPtr(migr_chardata));
602         else if (!strcasecmp(el, "QRdirname"))                  safestrncpy(qrbuf.QRdirname, ChrPtr(migr_chardata), sizeof qrbuf.QRdirname);
603         else if (!strcasecmp(el, "QRfloor"))                    qrbuf.QRfloor = atoi(ChrPtr(migr_chardata));
604         else if (!strcasecmp(el, "QRmtime"))                    qrbuf.QRmtime = atol(ChrPtr(migr_chardata));
605         else if (!strcasecmp(el, "QRexpire_mode"))              qrbuf.QRep.expire_mode = atoi(ChrPtr(migr_chardata));
606         else if (!strcasecmp(el, "QRexpire_value"))             qrbuf.QRep.expire_value = atoi(ChrPtr(migr_chardata));
607         else if (!strcasecmp(el, "QRnumber"))                   qrbuf.QRnumber = atol(ChrPtr(migr_chardata));
608         else if (!strcasecmp(el, "QRorder"))                    qrbuf.QRorder = atoi(ChrPtr(migr_chardata));
609         else if (!strcasecmp(el, "QRflags2"))                   qrbuf.QRflags2 = atoi(ChrPtr(migr_chardata));
610         else if (!strcasecmp(el, "QRdefaultview"))              qrbuf.QRdefaultview = atoi(ChrPtr(migr_chardata));
611         else if (!strcasecmp(el, "msgnum_info"))                qrbuf.msgnum_info = atol(ChrPtr(migr_chardata));
612         else if (!strcasecmp(el, "msgnum_pic"))                 qrbuf.msgnum_pic = atol(ChrPtr(migr_chardata));
613         else return 0;
614         return 1;
615 }
616
617
618 int migr_floorrecord(void *data, const char *el)
619 {
620         if (!strcasecmp(el, "f_num"))                           floornum = atoi(ChrPtr(migr_chardata));
621         else if (!strcasecmp(el, "f_flags"))                    flbuf.f_flags = atoi(ChrPtr(migr_chardata));
622         else if (!strcasecmp(el, "f_name"))                     safestrncpy(flbuf.f_name, ChrPtr(migr_chardata), sizeof flbuf.f_name);
623         else if (!strcasecmp(el, "f_ref_count"))                flbuf.f_ref_count = atoi(ChrPtr(migr_chardata));
624         else if (!strcasecmp(el, "f_ep_expire_mode"))           flbuf.f_ep.expire_mode = atoi(ChrPtr(migr_chardata));
625         else if (!strcasecmp(el, "f_ep_expire_value"))          flbuf.f_ep.expire_value = atoi(ChrPtr(migr_chardata));
626         else return 0;
627         return 1;
628 }
629
630
631 int migr_visitrecord(void *data, const char *el)
632 {
633         if (!strcasecmp(el, "v_roomnum"))                       vbuf.v_roomnum = atol(ChrPtr(migr_chardata));
634         else if (!strcasecmp(el, "v_roomgen"))                  vbuf.v_roomgen = atol(ChrPtr(migr_chardata));
635         else if (!strcasecmp(el, "v_usernum"))                  vbuf.v_usernum = atol(ChrPtr(migr_chardata));
636
637         else if (!strcasecmp(el, "v_seen")) {
638                 int is_textual_seen = 0;
639                 int i;
640                 int max = StrLength(migr_chardata);
641
642                 vbuf.v_lastseen = atol(ChrPtr(migr_chardata));
643                 is_textual_seen = 0;
644                 for (i=0; i < max; ++i) 
645                         if (!isdigit(ChrPtr(migr_chardata)[i]))
646                                 is_textual_seen = 1;
647                 if (is_textual_seen)
648                         safestrncpy(vbuf.v_seen, ChrPtr(migr_chardata), sizeof vbuf.v_seen);
649         }
650
651         else if (!strcasecmp(el, "v_answered"))                 safestrncpy(vbuf.v_answered, ChrPtr(migr_chardata), sizeof vbuf.v_answered);
652         else if (!strcasecmp(el, "v_flags"))                    vbuf.v_flags = atoi(ChrPtr(migr_chardata));
653         else if (!strcasecmp(el, "v_view"))                     vbuf.v_view = atoi(ChrPtr(migr_chardata));
654         else return 0;
655         return 1;
656 }
657
658
659 void migr_xml_end(void *data, const char *el)
660 {
661         const char *ptr;
662         int msgcount = 0;
663         long msgnum = 0L;
664         long *msglist = NULL;
665         int msglist_alloc = 0;
666         /*** GENERAL STUFF ***/
667
668         if (!strcasecmp(el, "citadel_migrate_data")) {
669                 --citadel_migrate_data;
670                 return;
671         }
672
673         if (citadel_migrate_data != 1) {
674                 syslog(LOG_ALERT, "Out-of-sequence tag <%s> detected.  Warning: ODD-DATA!", el);
675                 return;
676         }
677
678         // syslog(LOG_DEBUG, "END TAG: <%s> DATA: <%s>\n", el, (migr_chardata_len ? migr_chardata : ""));
679
680         /*** CONFIG ***/
681
682         if (!strcasecmp(el, "config"))
683         {
684                 syslog(LOG_DEBUG, "Imported config key=%s", ikey);
685
686                 if (ikey != NULL) {
687                         CtdlSetConfigStr(ikey, (char *)ChrPtr(migr_chardata));
688                         free(ikey);
689                         ikey = NULL;
690                 }
691                 else {
692                         syslog(LOG_INFO, "Closed a <config> tag but no key name was supplied.");
693                 }
694         }
695
696         /*** USER ***/
697         else if ((!strncasecmp(el, HKEY("u_"))) && 
698                  migr_userrecord(data, el))
699                 ; /* Nothing to do anymore */
700         else if (!strcasecmp(el, "user")) {
701                 CtdlPutUser(&usbuf);
702                 syslog(LOG_INFO, "Imported user: %s", usbuf.fullname);
703         }
704
705         /*** OPENID ***/
706
707         else if (!strcasecmp(el, "oid_url"))                    safestrncpy(openid_url, ChrPtr(migr_chardata), sizeof openid_url);
708         else if (!strcasecmp(el, "oid_usernum"))                openid_usernum = atol(ChrPtr(migr_chardata));
709
710         else if (!strcasecmp(el, "openid")) {                   /* see serv_openid_rp.c for a description of the record format */
711                 char *oid_data;
712                 int oid_data_len;
713                 oid_data_len = sizeof(long) + strlen(openid_url) + 1;
714                 oid_data = malloc(oid_data_len);
715                 memcpy(oid_data, &openid_usernum, sizeof(long));
716                 memcpy(&oid_data[sizeof(long)], openid_url, strlen(openid_url) + 1);
717                 cdb_store(CDB_EXTAUTH, openid_url, strlen(openid_url), oid_data, oid_data_len);
718                 free(oid_data);
719                 syslog(LOG_INFO, "Imported OpenID: %s (%ld)", openid_url, openid_usernum);
720         }
721
722         /*** ROOM ***/
723         else if ((!strncasecmp(el, HKEY("QR"))) && 
724                  migr_roomrecord(data, el))
725                 ; /* Nothing to do anymore */
726         else if (!strcasecmp(el, "room")) {
727                 CtdlPutRoom(&qrbuf);
728                 syslog(LOG_INFO, "Imported room: %s", qrbuf.QRname);
729         }
730
731         /*** ROOM MESSAGE POINTERS ***/
732
733         else if (!strcasecmp(el, "FRname"))                     safestrncpy(FRname, ChrPtr(migr_chardata), sizeof FRname);
734
735         else if (!strcasecmp(el, "FRmsglist")) {
736                 if (!IsEmptyStr(FRname)) {
737                         msgcount = 0;
738                         msglist_alloc = 1000;
739                         msglist = malloc(sizeof(long) * msglist_alloc);
740
741                         syslog(LOG_DEBUG, "Message list for: %s", FRname);
742
743                         ptr = ChrPtr(migr_chardata);
744                         while (*ptr != 0) {
745                                 while ((*ptr != 0) && (!isdigit(*ptr))) {
746                                         ++ptr;
747                                 }
748                                 if ((*ptr != 0) && (isdigit(*ptr))) {
749                                         msgnum = atol(ptr);
750                                         if (msgnum > 0L) {
751                                                 if (msgcount >= msglist_alloc) {
752                                                         msglist_alloc *= 2;
753                                                         msglist = realloc(msglist, sizeof(long) * msglist_alloc);
754                                                 }
755                                                 msglist[msgcount++] = msgnum;
756                                                 }
757                                         }
758                                         while ((*ptr != 0) && (isdigit(*ptr))) {
759                                                 ++ptr;
760                                         }
761                                 }
762                         }
763                         if (msgcount > 0) {
764                                 CtdlSaveMsgPointersInRoom(FRname, msglist, msgcount, 0, NULL, 1);
765                         }
766                         free(msglist);
767                         msglist = NULL;
768                         msglist_alloc = 0;
769                         syslog(LOG_DEBUG, "Imported %d messages.", msgcount);
770                         if (server_shutting_down) {
771                                 return;
772                 }
773         }
774
775         /*** FLOORS ***/
776         else if ((!strncasecmp(el, HKEY("f_"))) && 
777                  migr_floorrecord(data, el))
778                 ; /* Nothing to do anymore */
779
780         else if (!strcasecmp(el, "floor")) {
781                 CtdlPutFloor(&flbuf, floornum);
782                 syslog(LOG_INFO, "Imported floor #%d (%s)", floornum, flbuf.f_name);
783         }
784
785         /*** VISITS ***/
786         else if ((!strncasecmp(el, HKEY("v_"))) && migr_visitrecord(data, el)) {
787                 ; /* Nothing to do anymore */
788         }
789         else if (!strcasecmp(el, "visit")) {
790                 put_visit(&vbuf);
791                 syslog(LOG_INFO, "Imported visit: %ld/%ld/%ld", vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
792         }
793
794         /*** MESSAGES ***/
795         
796         else if (!strcasecmp(el, "msg_msgnum"))                 smi.meta_msgnum = import_msgnum = atol(ChrPtr(migr_chardata));
797         else if (!strcasecmp(el, "msg_meta_refcount"))          smi.meta_refcount = atoi(ChrPtr(migr_chardata));
798         else if (!strcasecmp(el, "msg_meta_rfc822_length"))     smi.meta_rfc822_length = atoi(ChrPtr(migr_chardata));
799         else if (!strcasecmp(el, "msg_meta_content_type"))      safestrncpy(smi.meta_content_type, ChrPtr(migr_chardata), sizeof smi.meta_content_type);
800
801         else if (!strcasecmp(el, "msg_text"))
802         {
803                 long rc;
804                 struct CtdlMessage *msg;
805
806                 FlushStrBuf(migr_MsgData);
807                 StrBufDecodeBase64To(migr_chardata, migr_MsgData);
808
809                 msg = CtdlDeserializeMessage(import_msgnum, -1,
810                                              ChrPtr(migr_MsgData), 
811                                              StrLength(migr_MsgData));
812                 if (msg != NULL) {
813                         rc = CtdlSaveThisMessage(msg, import_msgnum, 0);
814                         if (rc == 0) {
815                                 PutMetaData(&smi);
816                         }
817                         CM_Free(msg);
818                 }
819                 else {
820                         rc = -1;
821                 }
822
823                 syslog(LOG_INFO,
824                        "%s message #%ld, size=%d, refcount=%d, bodylength=%ld, content-type: %s",
825                        (rc!= 0)?"failed to import ":"Imported ",
826                        import_msgnum,
827                        StrLength(migr_MsgData),
828                        smi.meta_refcount,
829                        smi.meta_rfc822_length,
830                        smi.meta_content_type
831                 );
832                 memset(&smi, 0, sizeof(smi));
833         }
834
835         /*** MORE GENERAL STUFF ***/
836
837         FlushStrBuf(migr_chardata);
838 }
839
840
841 /*
842  * Import begins here
843  */
844 void migr_do_import(void) {
845         StrBuf *Buf;
846         XML_Parser xp;
847         int Finished = 0;
848         
849         unbuffer_output();
850         migr_chardata = NewStrBufPlain(NULL, SIZ * 20);
851         migr_MsgData = NewStrBufPlain(NULL, SIZ * 20);
852         Buf = NewStrBufPlain(NULL, SIZ);
853         xp = XML_ParserCreate(NULL);
854         if (!xp) {
855                 cprintf("%d Failed to create XML parser instance\n", ERROR+INTERNAL_ERROR);
856                 return;
857         }
858         XML_SetElementHandler(xp, migr_xml_start, migr_xml_end);
859         XML_SetCharacterDataHandler(xp, migr_xml_chardata);
860
861         CC->dont_term = 1;
862
863         cprintf("%d sock it to me\n", SEND_LISTING);
864         unbuffer_output();
865
866         client_set_inbound_buf(SIZ * 10);
867
868         while (!Finished && client_read_random_blob(Buf, -1) >= 0) {
869                 if ((StrLength(Buf) > 4) && !strcmp(ChrPtr(Buf) + StrLength(Buf) - 4, "000\n")) {
870                         Finished = 1;
871                         StrBufCutAt(Buf, StrLength(Buf) - 4, NULL);
872                 }
873                 if (server_shutting_down)
874                         break;  // Should we break or return?
875                 
876                 if (StrLength(Buf) == 0)
877                         continue;
878
879                 XML_Parse(xp, ChrPtr(Buf), StrLength(Buf), 0);
880                 FlushStrBuf(Buf);
881         }
882
883         XML_Parse(xp, "", 0, 1);
884         XML_ParserFree(xp);
885         FreeStrBuf(&Buf);
886         FreeStrBuf(&migr_chardata);
887         FreeStrBuf(&migr_MsgData);
888         rebuild_euid_index();
889         rebuild_usersbynumber();
890         CtdlSetConfigInt("MM_fulltext_wordbreaker", -1);        // Set an invalid wordbreaker to force re-indexing
891         CC->dont_term = 0;
892 }
893
894
895 /******************************************************************************
896  *                         Dispatcher, Common code                            *
897  ******************************************************************************/
898 /*
899  * Dump out the pathnames of directories which can be copied "as is"
900  */
901 void migr_do_listdirs(void) {
902         cprintf("%d Don't forget these:\n", LISTING_FOLLOWS);
903         cprintf("files|%s\n",           ctdl_file_dir);
904         cprintf("messages|%s\n",        ctdl_message_dir);
905         cprintf("keys|%s\n",            ctdl_key_dir);
906         cprintf("000\n");
907 }
908
909
910 /******************************************************************************
911  *                    Repair database integrity                               *
912  ******************************************************************************/
913
914 StrBuf *PlainMessageBuf = NULL;
915 HashList *UsedMessageIDS = NULL;
916
917 int migr_restore_message_metadata(long msgnum, int refcount)
918 {
919         CitContext *CCC = MyContext();
920         struct MetaData smi;
921         struct CtdlMessage *msg;
922         char *mptr = NULL;
923
924         /* We can use a static buffer here because there will never be more than
925          * one of this operation happening at any given time, and it's really best
926          * to just keep it allocated once instead of torturing malloc/free.
927          * Call this function with msgnum "-1" to free the buffer when finished.
928          */
929         static int encoded_alloc = 0;
930         static char *encoded_msg = NULL;
931
932         if (msgnum < 0) {
933                 if ((encoded_alloc == 0) && (encoded_msg != NULL)) {
934                         free(encoded_msg);
935                         encoded_alloc = 0;
936                         encoded_msg = NULL;
937                         // todo FreeStrBuf(&PlainMessageBuf); PlainMessageBuf = NULL;
938                 }
939                 return 0;
940         }
941
942         if (PlainMessageBuf == NULL) {
943                 PlainMessageBuf = NewStrBufPlain(NULL, 10*SIZ);
944         }
945
946         /* Ok, here we go ... */
947
948         msg = CtdlFetchMessage(msgnum, 1, 0);
949         if (msg == NULL) {
950                 return 1;
951         }
952
953         GetMetaData(&smi, msgnum);
954         smi.meta_msgnum = msgnum;
955         smi.meta_refcount = refcount;
956         
957         /* restore the content type from the message body: */
958         mptr = bmstrcasestr(msg->cm_fields[eMesageText], "Content-type:");
959         if (mptr != NULL) {
960                 char *aptr;
961                 safestrncpy(smi.meta_content_type, &mptr[13], sizeof smi.meta_content_type);
962                 striplt(smi.meta_content_type);
963                 aptr = smi.meta_content_type;
964                 while (!IsEmptyStr(aptr)) {
965                         if ((*aptr == ';')
966                             || (*aptr == ' ')
967                             || (*aptr == 13)
968                             || (*aptr == 10)) {
969                                 memset(aptr, 0, sizeof(smi.meta_content_type) - (aptr - smi.meta_content_type));
970                         }
971                         else aptr++;
972                 }
973         }
974
975         CCC->redirect_buffer = PlainMessageBuf;
976         CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1, QP_EADDR);
977         smi.meta_rfc822_length = StrLength(CCC->redirect_buffer);
978         CCC->redirect_buffer = NULL;
979
980         syslog(LOG_INFO,
981                "Setting message #%ld meta data to: refcount=%d, bodylength=%ld, content-type: %s",
982                smi.meta_msgnum,
983                smi.meta_refcount,
984                smi.meta_rfc822_length,
985                smi.meta_content_type
986         );
987
988         PutMetaData(&smi);
989
990         CM_Free(msg);
991
992         return 0;
993 }
994
995
996 void migr_check_room_msg(long msgnum, void *userdata) {
997         fprintf(migr_global_message_list, "%ld %s\n", msgnum, CC->room.QRname);
998 }
999
1000
1001 void migr_check_rooms_backend(struct ctdlroom *buf, void *data) {
1002
1003         /* message list goes inside this tag */
1004
1005         CtdlGetRoom(&CC->room, buf->QRname);
1006         CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, migr_check_room_msg, NULL);
1007 }
1008
1009
1010 void RemoveMessagesFromRooms(StrBuf *RoomNameVec, long msgnum) {
1011         struct MetaData smi;
1012         const char *Pos = NULL;
1013         StrBuf *oneRoom = NewStrBuf();
1014
1015         syslog(LOG_INFO, "removing message pointer %ld from these rooms: %s", msgnum, ChrPtr(RoomNameVec));
1016
1017         while (Pos != StrBufNOTNULL){
1018                 StrBufExtract_NextToken(oneRoom, RoomNameVec, &Pos, '|');
1019                 CtdlDeleteMessages(ChrPtr(oneRoom), &msgnum, 1, "");
1020         };
1021         GetMetaData(&smi, msgnum);
1022         AdjRefCount(msgnum, -smi.meta_refcount);
1023 }
1024
1025
1026 void migr_do_restore_meta(void) {
1027         char buf[SIZ];
1028         int failGetMessage;
1029         long msgnum = 0;
1030         int lastnum = 0;
1031         int refcount = 0;
1032         CitContext *Ctx;
1033         char *prn;
1034         StrBuf *RoomNames;
1035         char cmd[SIZ];
1036
1037         migr_global_message_list = fopen(migr_tempfilename1, "w");
1038         if (migr_global_message_list != NULL) {
1039                 CtdlForEachRoom(migr_check_rooms_backend, NULL);
1040                 fclose(migr_global_message_list);
1041         }
1042
1043         /*
1044          * Process the 'global' message list.  (Sort it and remove dups.
1045          * Dups are ok because a message may be in more than one room, but
1046          * this will be handled by exporting the reference count, not by
1047          * exporting the message multiple times.)
1048          */
1049         snprintf(cmd, sizeof cmd, "sort -n <%s >%s", migr_tempfilename1, migr_tempfilename2);
1050         if (system(cmd) != 0) syslog(LOG_ALERT, "Error %d", errno);
1051
1052         RoomNames = NewStrBuf();
1053         Ctx = CC;
1054         migr_global_message_list = fopen(migr_tempfilename2, "r");
1055         if (migr_global_message_list != NULL) {
1056                 syslog(LOG_INFO, "Opened %s", migr_tempfilename1);
1057                 while ((Ctx->kill_me == 0) && 
1058                        (fgets(buf, sizeof(buf), migr_global_message_list) != NULL)) {
1059                         msgnum = atol(buf);
1060                         if (msgnum == 0L) 
1061                                 continue;
1062                         if (lastnum == 0) {
1063                                 lastnum = msgnum;
1064                         }
1065                         prn = strchr(buf, ' ');
1066                         if (lastnum != msgnum) {
1067                                 failGetMessage = migr_restore_message_metadata(lastnum, refcount);
1068                                 if (failGetMessage) {
1069                                         RemoveMessagesFromRooms(RoomNames, lastnum);
1070                                 }
1071                                 refcount = 1;
1072                                 lastnum = msgnum;
1073                                 if (prn != NULL) {
1074                                         StrBufPlain(RoomNames, prn + 1, -1);
1075                                 }
1076                                 StrBufTrim(RoomNames);
1077                         }
1078                         else {
1079                                 if (prn != NULL) {
1080                                         if (StrLength(RoomNames) > 0) {
1081                                                 StrBufAppendBufPlain(RoomNames, HKEY("|"), 0);
1082                                         }
1083                                         StrBufAppendBufPlain(RoomNames, prn, -1, 1);
1084                                         StrBufTrim(RoomNames);
1085                                 }
1086                                 refcount ++;
1087                         }
1088                         lastnum = msgnum;
1089                 }
1090                 failGetMessage = migr_restore_message_metadata(msgnum, refcount);
1091                 if (failGetMessage) {
1092                         RemoveMessagesFromRooms(RoomNames, lastnum);
1093                 }
1094                 fclose(migr_global_message_list);
1095         }
1096
1097         migr_restore_message_metadata(-1L, -1); /* This frees the encoding buffer */
1098         cprintf("%d system analysis completed", CIT_OK);
1099         Ctx->kill_me = 1;
1100 }
1101
1102
1103 /******************************************************************************
1104  *                         Dispatcher, Common code                            *
1105  ******************************************************************************/
1106 void cmd_migr(char *cmdbuf) {
1107         char cmd[32];
1108         
1109         if (CtdlAccessCheck(ac_internal)) return;
1110         
1111         if (CtdlTrySingleUser()) {
1112                 CtdlDisableHouseKeeping();
1113                 CtdlMakeTempFileName(migr_tempfilename1, sizeof migr_tempfilename1);
1114                 CtdlMakeTempFileName(migr_tempfilename2, sizeof migr_tempfilename2);
1115
1116                 extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
1117                 if (!strcasecmp(cmd, "export")) {
1118                         migr_do_export();
1119                 }
1120                 else if (!strcasecmp(cmd, "import")) {
1121                         migr_do_import();
1122                 }
1123                 else if (!strcasecmp(cmd, "listdirs")) {
1124                         migr_do_listdirs();
1125                 }
1126                 else if (!strcasecmp(cmd, "restoremeta")) {
1127                         migr_do_restore_meta();
1128                 }
1129                 else {
1130                         cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
1131                 }
1132
1133                 unlink(migr_tempfilename1);
1134                 unlink(migr_tempfilename2);
1135
1136                 CtdlEnableHouseKeeping();
1137                 CtdlEndSingleUser();
1138         }
1139         else {
1140                 cprintf("%d The migrator is already running.\n", ERROR + RESOURCE_BUSY);
1141         }
1142 }
1143
1144
1145 /******************************************************************************
1146  *                              Module Hook                                  *
1147  ******************************************************************************/
1148
1149 CTDL_MODULE_INIT(migrate)
1150 {
1151         if (!threading)
1152         {
1153                 CtdlRegisterProtoHook(cmd_migr, "MIGR", "Across-the-wire migration");
1154         }
1155         
1156         /* return our module name for the log */
1157         return "migrate";
1158 }