Revert "Remove ENABLE_NLS definition. Either we HAVE_USELOCALE or we don't translate...
[citadel.git] / webcit / setup.c
1 /*
2  * WebCit setup utility
3  * 
4  * (This is basically just an install wizard.  It's not required.)
5  */
6
7 #include "sysdep.h"
8 #include "webcit.h"
9 #include "webserver.h"
10
11
12 #define UI_TEXT         0       /* Default setup type -- text only */
13 #define UI_DIALOG       2       /* Use the 'dialog' program */
14 #define UI_SILENT       3       /* Silent running, for use in scripts */
15
16 int setup_type;
17 char setup_directory[SIZ];
18 int using_web_installer = 0;
19 char suggested_url[SIZ];
20
21 /* some copies... 
22 int syslog(int loglevel, const char *format, ...){return 0;} */
23 void wc_printf(const char *format,...){}
24
25 void RegisterNS(const char *NSName, long len, 
26                 int nMinArgs, 
27                 int nMaxArgs, 
28                 WCHandlerFunc HandlerFunc,
29                 WCPreevalFunc PreEvalFunc,
30                 int ContextRequired){}
31 void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F){}
32 pthread_key_t MyConKey;
33
34 #ifdef ENABLE_NLS
35
36 #ifdef HAVE_USELOCALE 
37 int localeoffset = 1;
38 #else
39 int localeoffset = 0;
40 #endif
41
42 #endif
43 /*
44  * Delete an entry from /etc/inittab
45  */
46 void delete_init_entry(char *which_entry)
47 {
48         char *inittab = NULL;
49         FILE *fp;
50         char buf[SIZ];
51         char entry[SIZ];
52         char levels[SIZ];
53         char state[SIZ];
54         char prog[SIZ];
55
56         inittab = strdup("");
57         if (inittab == NULL) return;
58
59         fp = fopen("/etc/inittab", "r");
60         if (fp == NULL) return;
61
62         while(fgets(buf, sizeof buf, fp) != NULL) {
63
64                 if (num_tokens(buf, ':') == 4) {
65                         extract_token(entry, buf, 0, ':', sizeof entry);
66                         extract_token(levels, buf, 1, ':', sizeof levels);
67                         extract_token(state, buf, 2, ':', sizeof state);
68                         extract_token(prog, buf, 3, ':', sizeof prog); /* includes 0x0a LF */
69
70                         if (!strcmp(entry, which_entry)) {
71                                 strcpy(state, "off");   /* disable it */
72                         }
73                 }
74
75                 inittab = realloc(inittab, strlen(inittab) + strlen(buf) + 2);
76                 if (inittab == NULL) {
77                         fclose(fp);
78                         return;
79                 }
80                 
81                 strcat(inittab, buf);
82         }
83         fclose(fp);
84         fp = fopen("/etc/inittab", "w");
85         if (fp != NULL) {
86                 fwrite(inittab, strlen(inittab), 1, fp);
87                 fclose(fp);
88                 kill(1, SIGHUP);        /* Tell init to re-read /etc/inittab */
89         }
90         free(inittab);
91 }
92
93
94
95
96 /* 
97  * Remove any /etc/inittab entries for webcit, because we don't
98  * start it that way anymore.
99  */
100 void delete_the_old_way(void) {
101         FILE *infp;
102         char buf[1024];
103         char looking_for[1024];
104         int have_entry = 0;
105         char entry[1024];
106         char prog[1024];
107         char init_entry[1024];
108
109
110         strcpy(init_entry, "");
111
112         /* Determine the fully qualified path name of webcit */
113         snprintf(looking_for, sizeof looking_for, "%s/webcit ", setup_directory);
114
115         /* Pound through /etc/inittab line by line.  Set have_entry to 1 if
116          * an entry is found which we believe starts webcit.
117          */
118         infp = fopen("/etc/inittab", "r");
119         if (infp == NULL) {
120                 return;
121         } else {
122                 while (fgets(buf, sizeof buf, infp) != NULL) {
123                         buf[strlen(buf) - 1] = 0;
124                         extract_token(entry, buf, 0, ':', sizeof entry);
125                         extract_token(prog, buf, 3, ':', sizeof prog);
126                         if (!strncasecmp(prog, looking_for,
127                            strlen(looking_for))) {
128                                 ++have_entry;
129                                 strcpy(init_entry, entry);
130                         }
131                 }
132                 fclose(infp);
133         }
134
135         /* Bail out if there's nothing to do. */
136         if (!have_entry) return;
137
138         delete_init_entry(init_entry);
139 }
140
141
142
143 void cleanup(int exitcode)
144 {
145         exit(exitcode);
146 }
147
148
149
150 void title(char *text)
151 {
152         if (setup_type == UI_TEXT) {
153                 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n<%s>\n", text);
154         }
155 }
156
157
158
159
160 int yesno(char *question, int default_value)
161 {
162         int i = 0;
163         int answer = 0;
164         char buf[SIZ] = "";
165
166         switch (setup_type) {
167
168         case UI_TEXT:
169                 do {
170                         printf("%s\nYes/No [%s] --> ",
171                                 question,
172                                 ( default_value ? "Yes" : "No" )
173                         );
174                         if (fgets(buf, sizeof buf, stdin))
175                         {
176                                 answer = tolower(buf[0]);
177                                 if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
178                                         answer = default_value;
179                                 else if (answer == 'y')
180                                         answer = 1;
181                                 else if (answer == 'n')
182                                         answer = 0;
183                         }
184
185                 } while ((answer < 0) || (answer > 1));
186                 break;
187
188         case UI_DIALOG:
189                 sprintf(buf, "exec %s %s --yesno '%s' 15 75",
190                         getenv("CTDL_DIALOG"),
191                         ( default_value ? "" : "--defaultno" ),
192                         question);
193                 i = system(buf);
194                 if (i == 0) {
195                         answer = 1;
196                 }
197                 else {
198                         answer = 0;
199                 }
200                 break;
201
202         }
203         return (answer);
204 }
205
206
207
208
209 void set_value(char *prompt, char str[])
210 {
211         char buf[SIZ] = "";
212         char dialog_result[PATH_MAX];
213         char setupmsg[SIZ];
214         FILE *fp;
215
216         strcpy(setupmsg, "");
217
218         switch (setup_type) {
219         case UI_TEXT:
220                 title("WebCit setup");
221                 printf("\n%s\n", prompt);
222                 printf("This is currently set to:\n%s\n", str);
223                 printf("Enter new value or press return to leave unchanged:\n");
224                 if (fgets(buf, sizeof buf, stdin)) {
225                         buf[strlen(buf) - 1] = 0;
226                 }
227                 if (strlen(buf) != 0)
228                         strcpy(str, buf);
229                 break;
230         case UI_DIALOG:
231                 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
232                 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
233                         getenv("CTDL_DIALOG"),
234                         prompt,
235                         str,
236                         dialog_result);
237                 system(buf);
238                 fp = fopen(dialog_result, "r");
239                 if (fp != NULL) {
240                         if (fgets(str, sizeof buf, fp)){
241                                 if (str[strlen(str)-1] == 10) {
242                                         str[strlen(str)-1] = 0;
243                                 }
244                         }
245                         fclose(fp);
246                         unlink(dialog_result);
247                 }
248                 break;
249
250         }
251 }
252
253
254 extern const char *AvailLang[];
255 int GetLocalePrefs(void)
256 {
257         int nLocales;
258         StrBuf *Buf;
259         char buf[SIZ];
260         char dialog_result[PATH_MAX];
261         FILE *fp;
262         int i = 0;
263         int offs = 0;
264
265         nLocales = 0; 
266         while (!IsEmptyStr(AvailLang[nLocales]))
267                 nLocales++;
268
269         Buf = NewStrBuf();
270
271         StrBufAppendBufPlain(Buf, HKEY("Select the locale webcit should use : \n"), 0);
272 #ifdef HAVE_USELOCALE 
273         StrBufAppendBufPlain(Buf, HKEY(" 0 Let the user select it at the login prompt (default)\n"), 0);
274         offs ++;
275 #endif
276         for (i = 0; i < nLocales; i++) {
277                 StrBufAppendPrintf(Buf, " %ld: %s\n", i + offs, AvailLang[i]);
278
279         }
280
281         switch (setup_type) {
282         case UI_TEXT:
283                 title("WebCit setup");
284                 printf("\n%s\n", ChrPtr(Buf));
285                 printf("This is currently set to:\n%ld\n", 0L);
286                 printf("Enter new value or press return to leave unchanged:\n");
287                 if (fgets(buf, sizeof buf, stdin))
288                         return atoi(buf);
289                 break;
290
291         case UI_DIALOG:
292                 CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
293                 sprintf(buf, "exec %s --inputbox '%s' 19 72 '%ld' 2>%s",
294                         getenv("CTDL_DIALOG"),
295                         ChrPtr(Buf),
296                         0L,
297                         dialog_result);
298                 system(buf);
299                 fp = fopen(dialog_result, "r");
300                 if (fp != NULL) {
301                         char *str = &buf[0];
302                         if (fgets(str, sizeof buf, fp)){
303                                 if (str[strlen(str)-1] == 10) {
304                                         str[strlen(str)-1] = 0;
305                                 }
306                         }
307                         fclose(fp);
308                         unlink(dialog_result);
309                         return atoi(buf);
310                 }
311                 break;
312
313         }
314         return 0;
315 }
316
317 void important_message(char *title, char *msgtext)
318 {
319         char buf[SIZ];
320
321         switch (setup_type) {
322
323         case UI_TEXT:
324                 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
325                 printf("       %s \n\n%s\n\n", title, msgtext);
326                 printf("Press return to continue...");
327                 if (fgets(buf, sizeof buf, stdin));
328                 break;
329
330         case UI_DIALOG:
331                 sprintf(buf, "exec %s --msgbox '%s' 19 72",
332                         getenv("CTDL_DIALOG"),
333                         msgtext);
334                 system(buf);
335                 break;
336         }
337 }
338
339
340 void display_error(char *error_message)
341 {
342         important_message("Error", error_message);
343 }
344
345 void progress(char *text, long int curr, long int cmax)
346 {
347         static long dots_printed = 0L;
348         long a = 0;
349         char buf[SIZ];
350         static FILE *fp = NULL;
351
352         switch (setup_type) {
353
354         case UI_TEXT:
355                 if (curr == 0) {
356                         printf("%s\n", text);
357                         printf("..........................");
358                         printf("..........................");
359                         printf("..........................\r");
360                         fflush(stdout);
361                         dots_printed = 0;
362                 } else if (curr == cmax) {
363                         printf("\r%79s\n", "");
364                 } else {
365                         a = (curr * 100) / cmax;
366                         a = a * 78;
367                         a = a / 100;
368                         while (dots_printed < a) {
369                                 printf("*");
370                                 ++dots_printed;
371                                 fflush(stdout);
372                         }
373                 }
374                 break;
375
376         case UI_DIALOG:
377                 if (curr == 0) {
378                         sprintf(buf, "exec %s --gauge '%s' 7 72 0",
379                                 getenv("CTDL_DIALOG"),
380                                 text);
381                         fp = popen(buf, "w");
382                         if (fp != NULL) {
383                                 fprintf(fp, "0\n");
384                                 fflush(fp);
385                         }
386                 } 
387                 else if (curr == cmax) {
388                         if (fp != NULL) {
389                                 fprintf(fp, "100\n");
390                                 pclose(fp);
391                                 fp = NULL;
392                         }
393                 }
394                 else {
395                         a = (curr * 100) / cmax;
396                         if (fp != NULL) {
397                                 fprintf(fp, "%ld\n", a);
398                                 fflush(fp);
399                         }
400                 }
401                 break;
402         }
403 }
404
405
406
407
408 /*
409  * install_init_scripts()  -- Create and deploy SysV init scripts.
410  *
411  */
412 void install_init_scripts(void)
413 {
414 #ifdef ENABLE_NLS
415         int localechoice;
416 #endif
417         char question[1024];
418         char buf[256];
419         char http_port[128];
420 #ifdef HAVE_OPENSSL
421         char https_port[128];
422 #endif
423         char hostname[128];
424         char portname[128];
425         char command[SIZ];
426         struct utsname my_utsname;
427         struct stat etcinitd;
428         FILE *fp;
429         char *initfile = "/etc/init.d/webcit";
430
431         fp = fopen(initfile, "r");
432         if (fp != NULL) {
433                 if (yesno("WebCit already appears to be configured to start at boot.\n"
434                           "Would you like to keep your boot configuration as is?\n", 1) == 1) {
435                         return;
436                 }
437                 fclose(fp);
438                 
439         }
440
441         /* Otherwise, prompt the user to create an entry. */
442         snprintf(question, sizeof question,
443                  "Would you like to automatically start WebCit at boot?"
444                 );
445         if (yesno(question, 1) == 0)
446                 return;
447
448
449 #ifdef ENABLE_NLS
450
451         localechoice = GetLocalePrefs();
452
453 #endif
454         /* Defaults */
455         sprintf(http_port, "2000");
456 #ifdef HAVE_OPENSSL
457         sprintf(https_port, "443");
458 #endif
459         sprintf(hostname, "uds");
460         sprintf(portname, "/usr/local/citadel");
461
462         /* This is a very hackish way of learning the port numbers used
463          * in a previous install, if we are upgrading: read them out of
464          * the existing init script.
465          */
466         if ((stat("/etc/init.d/", &etcinitd) == -1) && 
467             (errno == ENOENT))
468         {
469                 if ((stat("/etc/rc.d/init.d/", &etcinitd) == -1) &&
470                     (errno == ENOENT))
471                         initfile = WEBCITDIR"/webcit.init";
472                 else
473                         initfile = "/etc/rc.d/init.d/webcit";
474         }
475
476         fp = fopen(initfile, "r");
477         if (fp != NULL) {
478                 while (fgets(buf, sizeof buf, fp) != NULL) {
479                         if (strlen(buf) > 0) {
480                                 buf[strlen(buf)-1] = 0; /* strip trailing cr */
481                         }
482                         if (!strncasecmp(buf, "HTTP_PORT=", 10)) {
483                                 safestrncpy(http_port, &buf[10], sizeof http_port);
484                         }
485 #ifdef HAVE_OPENSSL
486                         if (!strncasecmp(buf, "HTTPS_PORT=", 11)) {
487                                 safestrncpy(https_port, &buf[11], sizeof https_port);
488                         }
489 #endif
490                         if (!strncasecmp(buf, "CTDL_HOSTNAME=", 14)) {
491                                 safestrncpy(hostname, &buf[14], sizeof hostname);
492                         }
493                         if (!strncasecmp(buf, "CTDL_PORTNAME=", 14)) {
494                                 safestrncpy(portname, &buf[14], sizeof portname);
495                         }
496                 }
497                 fclose(fp);
498         }
499
500         /* Now ask for the port numbers */
501         snprintf(question, sizeof question,
502                  "On which port do you want WebCit to listen for HTTP "
503                  "requests?\n\nYou can use the standard port (80) if you are "
504                  "not running another\nweb server (such as Apache), otherwise "
505                  "select another port.");
506         set_value(question, http_port);
507         uname(&my_utsname);
508         sprintf(suggested_url, "http://%s:%s/", my_utsname.nodename, http_port);
509
510 #ifdef HAVE_OPENSSL
511         snprintf(question, sizeof question,
512                  "On which port do you want WebCit to listen for HTTPS "
513                  "requests?\n\nYou can use the standard port (443) if you are "
514                  "not running another\nweb server (such as Apache), otherwise "
515                  "select another port.");
516         set_value(question, https_port);
517 #endif
518
519         /* Find out where Citadel is. */
520         if ( (using_web_installer) && (getenv("CITADEL") != NULL) ) {
521                 strcpy(hostname, "uds");
522                 strcpy(portname, getenv("CITADEL"));
523         }
524         else {
525                 snprintf(question, sizeof question,
526                          "Is the Citadel service running on the same host as WebCit?");
527                 if (yesno(question, ((!strcasecmp(hostname, "uds")) ? 1 : 0))) {
528                         strcpy(hostname, "uds");
529                         if (atoi(portname) != 0) strcpy(portname, "/usr/local/citadel");
530                         set_value("In what directory is Citadel installed?", portname);
531                 }
532                 else {
533                         if (!strcasecmp(hostname, "uds")) strcpy(hostname, "127.0.0.1");
534                         if (atoi(portname) == 0) strcpy(portname, "504");
535                         set_value("Enter the host name or IP address of your "
536                                   "Citadel server.", hostname);
537                         set_value("Enter the port number on which Citadel is "
538                                   "running (usually 504)", portname);
539                 }
540         }
541
542
543         fp = fopen(initfile, "w");
544
545         fprintf(fp,     "#!/bin/sh\n"
546                 "\n"
547                 "# uncomment this to create coredumps as described in\n"
548                 "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
549                 "# ulimit -c unlimited\n"
550                         "WEBCIT_DIR=%s\n", setup_directory);
551         fprintf(fp,     "HTTP_PORT=%s\n", http_port);
552 #ifdef HAVE_OPENSSL
553         fprintf(fp,     "HTTPS_PORT=%s\n", https_port);
554 #endif
555         fprintf(fp,     "CTDL_HOSTNAME=%s\n", hostname);
556         fprintf(fp,     "CTDL_PORTNAME=%s\n", portname);
557
558 #ifdef ENABLE_NLS
559         
560         if (localechoice == 0) {
561 #ifdef HAVE_USELOCALE 
562                 fprintf(fp, "unset LANG\n");
563 #else
564                 fprintf(fp, "export WEBCIT_LANG=c\n");
565 #endif
566         }
567         else {
568                 fprintf(fp, "export WEBCIT_LANG=%s\n", AvailLang[localechoice - localeoffset]);
569
570         }
571 #else
572         fprintf(fp,     "# your system doesn't support locales\n");
573 #endif
574         fprintf(fp,     "\n"
575                         "\n"
576                         "case \"$1\" in\n"
577                         "\n"
578                         "start)         echo -n \"Starting WebCit... \"\n"
579                         "               if   $WEBCIT_DIR/webcit "
580                                                         "-D/var/run/webcit.pid "
581                                                         "-p$HTTP_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
582                         "               then\n"
583                         "                       echo \"ok\"\n"
584                         "               else\n"
585                         "                       echo \"failed\"\n"
586                         "               fi\n");
587 #ifdef HAVE_OPENSSL
588         fprintf(fp,     "               echo -n \"Starting WebCit SSL... \"\n"
589                         "               if  $WEBCIT_DIR/webcit "
590                                                         "-D/var/run/webcit-ssl.pid "
591                                                         "-s -p$HTTPS_PORT $CTDL_HOSTNAME $CTDL_PORTNAME\n"
592                         "               then\n"
593                         "                       echo \"ok\"\n"
594                         "               else\n"
595                         "                       echo \"failed\"\n"
596                         "               fi\n");
597 #endif
598         fprintf(fp,     "               ;;\n"
599                         "stop)          echo -n \"Stopping WebCit... \"\n"
600                         "               if kill `cat /var/run/webcit.pid 2>/dev/null` 2>/dev/null\n"
601                         "               then\n"
602                         "                       echo \"ok\"\n"
603                         "               else\n"
604                         "                       echo \"failed\"\n"
605                         "               fi\n"
606                         "               rm -f /var/run/webcit.pid 2>/dev/null\n");
607 #ifdef HAVE_OPENSSL
608         fprintf(fp,     "               echo -n \"Stopping WebCit SSL... \"\n"
609                         "               if kill `cat /var/run/webcit-ssl.pid 2>/dev/null` 2>/dev/null\n"
610                         "               then\n"
611                         "                       echo \"ok\"\n"
612                         "               else\n"
613                         "                       echo \"failed\"\n"
614                         "               fi\n"
615                         "               rm -f /var/run/webcit-ssl.pid 2>/dev/null\n");
616 #endif
617         fprintf(fp,     "               ;;\n"
618                         "restart)       $0 stop\n"
619                         "               $0 start\n"
620                         "               ;;\n"
621                         "*)             echo \"Usage: $0 {start|stop|restart}\"\n"
622                         "               exit 1\n"
623                         "               ;;\n"
624                         "esac\n"
625         );
626
627         fclose(fp);
628         chmod(initfile, 0755);
629
630         /* Set up the run levels. */
631         system("/bin/rm -f /etc/rc?.d/[SK]??webcit 2>/dev/null");
632         snprintf(command, sizeof(command), "for x in 2 3 4 5 ; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/S84webcit ; done 2>/dev/null", initfile);
633         system(command);
634         snprintf(command, sizeof(command), "for x in 0 6 S; do [ -d /etc/rc$x.d ] && ln -s %s /etc/rc$x.d/K15webcit ; done 2>/dev/null", initfile);
635         system(command);
636
637 }
638
639
640
641
642 /*
643  * Figure out what type of user interface we're going to use
644  */
645 int discover_ui(void)
646 {
647
648         /* Use "dialog" if we have it */
649         if (getenv("CTDL_DIALOG") != NULL) {
650                 return UI_DIALOG;
651         }
652                 
653         return UI_TEXT;
654 }
655
656
657
658
659
660 int main(int argc, char *argv[])
661 {
662         int a;
663         char aaa[256];
664         int info_only = 0;
665
666         strcpy(suggested_url, "http://<your_host_name>:<port>/");
667
668         /* set an invalid setup type */
669         setup_type = (-1);
670
671         /* Check to see if we're running the web installer */
672         if (getenv("CITADEL_INSTALLER") != NULL) {
673                 using_web_installer = 1;
674         }
675
676         /* parse command line args */
677         for (a = 0; a < argc; ++a) {
678                 if (!strncmp(argv[a], "-u", 2)) {
679                         strcpy(aaa, argv[a]);
680                         strcpy(aaa, &aaa[2]);
681                         setup_type = atoi(aaa);
682                 }
683                 if (!strcmp(argv[a], "-i")) {
684                         info_only = 1;
685                 }
686                 if (!strcmp(argv[a], "-q")) {
687                         setup_type = UI_SILENT;
688                 }
689         }
690
691
692         /* If a setup type was not specified, try to determine automatically
693          * the best one to use out of all available types.
694          */
695         if (setup_type < 0) {
696                 setup_type = discover_ui();
697         }
698         if (info_only == 1) {
699                 important_message("WebCit Setup", "Welcome to WebCit setup");
700                 cleanup(0);
701         }
702
703         /* Get started in a valid setup directory. */
704         strcpy(setup_directory, WEBCITDIR);
705         if ( (using_web_installer) && (getenv("WEBCIT") != NULL) ) {
706                 strcpy(setup_directory, getenv("WEBCIT"));
707         }
708         else {
709                 set_value("In what directory is WebCit installed?",
710                         setup_directory);
711         }
712         if (chdir(setup_directory) != 0) {
713                 important_message("WebCit Setup",
714                           "The directory you specified does not exist.");
715                 cleanup(errno);
716         }
717
718         /*
719          * We used to start WebCit by putting it directly into /etc/inittab.
720          * Since some systems are moving away from init, we can't do this anymore.
721          */
722         progress("Removing obsolete /etc/inittab entries...", 0, 1);
723         delete_the_old_way();
724         progress("Removing obsolete /etc/inittab entries...", 1, 1);
725
726         /* Now begin. */
727         switch (setup_type) {
728
729         case UI_TEXT:
730                 printf("\n\n\n"
731                         "               *** WebCit setup program ***\n\n");
732                 break;
733
734         }
735
736         /* 
737          * If we're running on SysV, install init scripts.
738          */
739         if (!access("/var/run", W_OK)) {
740                 install_init_scripts();
741
742                 if (!access("/etc/init.d/webcit", X_OK)) {
743                         system("/etc/init.d/webcit stop");
744                         system("/etc/init.d/webcit start");
745                 }
746
747                 sprintf(aaa,
748                         "Setup is finished.  You may now log in.\n"
749                         "Point your web browser at %s\n", suggested_url
750                 );
751                 important_message("Setup finished", aaa);
752         }
753
754         else {
755                 important_message("Setup finished",
756                         "Setup is finished.  You may now start the server.");
757         }
758
759         cleanup(0);
760         return 0;
761 }