made json formatter a little smarter/better
[Evergreen.git] / OpenSRF / src / srfsh / srfsh.c
1 #include "srfsh.h"
2
3 int is_from_script = 0;
4 FILE* shell_writer = NULL;
5 FILE* shell_reader = NULL;
6
7 int main( int argc, char* argv[] ) {
8
9
10
11         /* --------------------------------------------- */
12         /* see if they have a .srfsh.xml in their home directory */
13         char* home = getenv("HOME");
14         int l = strlen(home) + 36;
15         char fbuf[l];
16         memset(fbuf, 0, l);
17         sprintf(fbuf,"%s/.srfsh.xml",home);
18
19         if(!access(fbuf, R_OK)) {
20                 if( ! osrf_system_bootstrap_client(fbuf, "srfsh") ) 
21                         fatal_handler( "Unable to bootstrap client for requests");
22
23         } else {
24                 fatal_handler( "No Config file found at %s", fbuf );
25         }
26
27         if(argc > 1) {
28                 /* for now.. the first arg is used as a script file for processing */
29                 int f;
30                 if( (f = open(argv[1], O_RDONLY)) == -1 )
31                         fatal_handler("Unable to open file %s for reading, exiting...", argv[1]);
32
33                 if(dup2(f, STDIN_FILENO) == -1)
34                         fatal_handler("Unable to duplicate STDIN, exiting...");
35
36                 close(f);
37                 is_from_script = 1;
38         }
39                 
40         /* --------------------------------------------- */
41         load_history();
42
43
44         client = osrf_system_get_transport_client();
45
46         /* open the shell handle */
47         shell_writer = popen( "bash", "w");
48         //shell_reader = popen( "bash", "r");
49
50         /* main process loop */
51         char* request;
52         while((request=readline(prompt))) {
53
54                 if( !strcmp(request, "exit") || !strcmp(request,"quit")) 
55                         break; 
56
57                 char* req_copy = strdup(request);
58
59                 parse_request( req_copy ); 
60                 if( request && strlen(request) > 1 ) {
61                         add_history(request);
62                 }
63
64                 free(request);
65                 free(req_copy);
66
67                 fflush(shell_writer);
68                 fflush(stderr);
69                 fflush(stdout);
70         }
71
72         if(history_file != NULL )
73                 write_history(history_file);
74         free(request);
75         client_disconnect( client );
76         client_free( client );  
77         config_reader_free();   
78         log_free();
79                 
80         return 0;
81 }
82
83 void sig_child_handler( int s ) {
84         child_dead = 1;
85 }
86
87 /*
88 void sig_int_handler( int s ) {
89         printf("\n");
90         caught_sigint = 1;
91         signal(SIGINT,sig_int_handler);
92 }
93 */
94
95 int load_history() {
96
97         char* home = getenv("HOME");
98         int l = strlen(home) + 24;
99         char fbuf[l];
100
101         memset(fbuf, 0, l);
102         sprintf(fbuf,"%s/.srfsh_history",home);
103         history_file = strdup(fbuf);
104
105         if(!access(history_file, W_OK | R_OK )) {
106                 history_length = 999;
107                 read_history(history_file);
108         }
109         return 1;
110 }
111
112
113 int parse_error( char* words[] ) {
114
115         if( ! words )
116                 return 0;
117
118
119         int i = 0;
120         char* current;
121         char buffer[256];
122         memset(buffer, 0, 256);
123         while( (current=words[i++]) ) {
124                 strcat(buffer, current);
125                 strcat(buffer, " ");
126         }
127         if( ! buffer || strlen(buffer) < 1 ) 
128                 printf("\n");
129
130         fprintf( stderr, "???: %s\n", buffer );
131         return 0;
132
133 }
134
135
136 int parse_request( char* request ) {
137
138         if( request == NULL )
139                 return 0;
140
141         int ret_val = 0;
142         int i = 0;
143         char* words[COMMAND_BUFSIZE]; 
144         memset(words,0,COMMAND_BUFSIZE);
145         char* req = request;
146
147         char* cur_tok = strtok( req, " " );
148
149         if( cur_tok == NULL )
150                 return 0;
151
152         while(cur_tok != NULL) {
153                 words[i++] = cur_tok;
154                 cur_tok = strtok( NULL, " " );
155         }
156
157
158         // not sure why (strtok?), but this is necessary
159         memset( words + i, 0, COMMAND_BUFSIZE - i );
160
161         /* pass off to the top level command */
162         if( !strcmp(words[0],"router") ) 
163                 ret_val = handle_router( words );
164
165         else if( !strcmp(words[0],"time") ) 
166                 ret_val = handle_time( words );
167
168         else if (!strcmp(words[0],"request"))
169                 ret_val = handle_request( words, 0 );
170
171         else if (!strcmp(words[0],"relay"))
172                 ret_val = handle_request( words, 1 );
173
174         else if (!strcmp(words[0],"help"))
175                 ret_val = print_help();
176
177         else if (!strcmp(words[0],"set"))
178                 ret_val = handle_set(words);
179
180         else if (!strcmp(words[0],"print"))
181                 ret_val = handle_print(words);
182
183         else if (!strcmp(words[0],"math_bench"))
184                 ret_val = handle_math(words);
185
186         else if (!strcmp(words[0],"introspect"))
187                 ret_val = handle_introspect(words);
188
189         else if (!strcmp(words[0],"login"))
190                 ret_val = handle_login(words);
191
192         else if (words[0][0] == '!')
193                 ret_val = handle_exec( words, 1 );
194
195         if(!ret_val) {
196                 #ifdef EXEC_DEFAULT
197                         return handle_exec( words, 0 );
198                 #else
199                         return parse_error( words );
200                 #endif
201         }
202
203         return 1;
204
205 }
206
207
208 int handle_introspect(char* words[]) {
209
210         if(words[1] && words[2]) {
211                 fprintf(stderr, "--> %s\n", words[1]);
212                 char buf[256];
213                 memset(buf,0,256);
214                 sprintf( buf, "request %s opensrf.system.method %s", words[1], words[2] );
215                 return parse_request( buf );
216
217         } else {
218         
219                 if(words[1]) {
220                         fprintf(stderr, "--> %s\n", words[1]);
221                         char buf[256];
222                         memset(buf,0,256);
223                         sprintf( buf, "request %s opensrf.system.method.all", words[1] );
224                         return parse_request( buf );
225                 }
226         }
227
228         return 0;
229 }
230
231
232 int handle_login( char* words[]) {
233
234         if( words[1] && words[2]) {
235
236                 char* username = words[1];
237                 char* password = words[2];
238
239                 char buf[256];
240                 memset(buf,0,256);
241
242                 char buf2[256];
243                 memset(buf2,0,256);
244
245                 sprintf( buf, 
246                                 "request open-ils.auth open-ils.auth.authenticate.init \"%s\"", username );
247                 parse_request(buf); 
248
249                 char* hash;
250                 if(last_result && last_result->_result_content) {
251                         object* r = last_result->_result_content;
252                         hash = r->string_data;
253                 } else return 0;
254
255
256                 char* pass_buf = md5sum(password);
257
258                 char both_buf[256];
259                 memset(both_buf,0,256);
260                 sprintf(both_buf,"%s%s",hash, pass_buf);
261
262                 char* mess_buf = md5sum(both_buf);
263
264                 sprintf( buf2,
265                                 "request open-ils.auth open-ils.auth.authenticate.complete \"%s\", \"%s\", \"opac\"", 
266                                 username, mess_buf );
267
268                 free(pass_buf);
269                 free(mess_buf);
270
271                 parse_request( buf2 );
272
273                 login_session = strdup(last_result->_result_content->string_data);
274
275                 printf("Login Session: %s\n", login_session );
276                 
277                 return 1;
278
279         }
280
281         return 0;
282 }
283
284 char* md5sum( char* text ) {
285
286         struct md5_ctx ctx;
287         unsigned char digest[16];
288
289         MD5_start (&ctx);
290
291         int i;
292         for ( i=0 ; i != strlen(text) ; i++ )
293                 MD5_feed (&ctx, text[i]);
294
295         MD5_stop (&ctx, digest);
296
297         char buf[16];
298         memset(buf,0,16);
299
300         char final[256];
301         memset(final,0,256);
302
303         for ( i=0 ; i<16 ; i++ ) {
304                 sprintf(buf, "%02x", digest[i]);
305                 strcat( final, buf );
306         }
307
308         return strdup(final);
309
310 }
311
312
313 int handle_set( char* words[]) {
314
315         char* variable;
316         if( (variable=words[1]) ) {
317
318                 char* val;
319                 if( (val=words[2]) ) {
320
321                         if(!strcmp(variable,"pretty_print")) {
322                                 if(!strcmp(val,"true")) {
323                                         pretty_print = 1;
324                                         printf("pretty_print = true\n");
325                                         return 1;
326                                 } 
327                                 if(!strcmp(val,"false")) {
328                                         pretty_print = 0;
329                                         printf("pretty_print = false\n");
330                                         return 1;
331                                 } 
332                         }
333
334                         if(!strcmp(variable,"raw_print")) {
335                                 if(!strcmp(val,"true")) {
336                                         raw_print = 1;
337                                         printf("raw_print = true\n");
338                                         return 1;
339                                 } 
340                                 if(!strcmp(val,"false")) {
341                                         raw_print = 0;
342                                         printf("raw_print = false\n");
343                                         return 1;
344                                 } 
345                         }
346
347                 }
348         }
349
350         return 0;
351 }
352
353
354 int handle_print( char* words[]) {
355
356         char* variable;
357         if( (variable=words[1]) ) {
358                 if(!strcmp(variable,"pretty_print")) {
359                         if(pretty_print) {
360                                 printf("pretty_print = true\n");
361                                 return 1;
362                         } else {
363                                 printf("pretty_print = false\n");
364                                 return 1;
365                         }
366                 }
367
368                 if(!strcmp(variable,"login")) {
369                         printf("login session = %s\n", login_session );
370                         return 1;
371                 }
372
373         }
374         return 0;
375 }
376
377 int handle_router( char* words[] ) {
378
379         if(!client)
380                 return 1;
381
382         int i;
383
384         if( words[1] ) { 
385                 if( !strcmp(words[1],"query") ) {
386                         
387                         if( words[2] && !strcmp(words[2],"servers") ) {
388                                 for(i=3; i < COMMAND_BUFSIZE - 3 && words[i]; i++ ) {   
389                                         router_query_servers( words[i] );
390                                 }
391                                 return 1;
392                         }
393                         return 0;
394                 }
395                 return 0;
396         }
397         return 0;
398 }
399
400
401 /* if new shell, spawn a new child and subshell to do the work,
402         otherwise pipe the request to the currently open (piped) shell */
403 int handle_exec(char* words[], int new_shell) {
404
405         if(!words[0]) return 0;
406
407         if( words[0] && words[0][0] == '!') {
408                 int len = strlen(words[0]);
409                 char command[len];
410                 memset(command,0,len);
411         
412                 int i; /* chop out the ! */
413                 for( i=1; i!= len; i++) {
414                         command[i-1] = words[0][i];
415                 }
416         
417                 free(words[0]);
418                 words[0] = strdup(command);
419         }
420
421         if(new_shell) {
422                 signal(SIGCHLD, sig_child_handler);
423
424                 if(fork()) {
425         
426                         waitpid(-1, 0, 0);
427                         if(child_dead) {
428                                 signal(SIGCHLD,sig_child_handler);
429                                 child_dead = 0;
430                         }
431         
432                 } else {
433                         execvp( words[0], words );
434                         exit(0);
435                 }
436
437         } else {
438
439
440                 growing_buffer* b = buffer_init(64);
441                 int i = 0;
442                 while(words[i]) 
443                         buffer_fadd( b, "%s ", words[i++] );
444         
445                 buffer_add( b, "\n");
446         
447                 //int reader;
448                 //int reader = dup2(STDOUT_FILENO, reader);
449                 //int reader = dup(STDOUT_FILENO);
450                 //close(STDOUT_FILENO);
451
452                 fprintf( shell_writer, b->buf );
453                 buffer_free(b);
454         
455                 fflush(shell_writer);
456                 usleep(1000);
457
458                 /*
459                 char c[4096];
460                 bzero(c, 4096);
461                 read( reader, c, 4095 );
462                 fprintf(stderr, "read %s", c);
463                 dup2(reader, STDOUT_FILENO);
464                 */
465
466         }
467
468         
469         return 1;
470 }
471
472
473 int handle_request( char* words[], int relay ) {
474
475         if(!client)
476                 return 1;
477
478         if(words[1]) {
479                 char* server = words[1];
480                 char* method = words[2];
481                 int i;
482                 growing_buffer* buffer = NULL;
483                 if(!relay) {
484                         buffer = buffer_init(128);
485                         buffer_add(buffer, "[");
486                         for(i = 3; words[i] != NULL; i++ ) {
487                                 /* removes trailing semicolon if user accidentally enters it */
488                                 if( words[i][strlen(words[i])-1] == ';' )
489                                         words[i][strlen(words[i])-1] = '\0';
490                                 buffer_add( buffer, words[i] );
491                                 buffer_add(buffer, " ");
492                         }
493                         buffer_add(buffer, "]");
494                 }
495
496                 return send_request( server, method, buffer, relay );
497         } 
498
499         return 0;
500 }
501
502 int send_request( char* server, 
503                 char* method, growing_buffer* buffer, int relay ) {
504         if( server == NULL || method == NULL )
505                 return 0;
506
507         object* params = NULL;
508         if( !relay ) {
509                 if( buffer != NULL && buffer->n_used > 0 ) 
510                         params = json_parse_string(buffer->buf);
511         } else {
512                 if(!last_result || ! last_result->_result_content) { 
513                         printf("We're not going to call 'relay' with no result params\n");
514                         return 1;
515                 }
516                 else {
517                         object* o = new_object(NULL);
518                         o->push(o, last_result->_result_content );
519                         params = o;
520                 }
521         }
522
523
524         if(buffer->n_used > 0 && params == NULL) {
525                 fprintf(stderr, "JSON error detected, not executing\n");
526                 return 1;
527         }
528
529         osrf_app_session* session = osrf_app_client_session_init(server);
530
531         if(!osrf_app_session_connect(session)) {
532                 warning_handler( "Unable to connect to remote service %s\n", server );
533                 return 1;
534         }
535
536         double start = get_timestamp_millis();
537         //int req_id = osrf_app_session_make_request( session, params, method, 1, NULL );
538         int req_id = osrf_app_session_make_req( session, params, method, 1, NULL );
539
540
541         osrf_message* omsg = osrf_app_session_request_recv( session, req_id, 60 );
542
543         if(!omsg) 
544                 printf("\nReceived no data from server\n");
545         
546         
547         signal(SIGPIPE, SIG_IGN);
548
549         FILE* less; 
550         if(!is_from_script) less = popen( "less -EX", "w");
551         else less = stdout;
552
553         if( less == NULL ) { less = stdout; }
554
555         growing_buffer* resp_buffer = buffer_init(4096);
556
557         while(omsg) {
558
559                 if(raw_print) {
560
561                         if(omsg->_result_content) {
562         
563                                 osrf_message_free(last_result);
564                                 last_result = omsg;
565         
566                                 char* content;
567         
568                                 if( pretty_print && omsg->_result_content ) {
569                                         char* j = object_to_json(omsg->_result_content);
570                                         //content = json_printer(j); 
571                                         content = json_string_format(j);
572                                         free(j);
573                                 } else
574                                         content = object_get_string(omsg->_result_content);
575         
576                                 printf( "\nReceived Data: %s\n", content ); 
577                                 free(content);
578         
579                         } else {
580
581                                 char code[16];
582                                 memset(code, 0, 16);
583                                 sprintf( code, "%d", omsg->status_code );
584                                 buffer_add( resp_buffer, code );
585
586                                 printf( "\nReceived Exception:\nName: %s\nStatus: %s\nStatus: %s\n", 
587                                                 omsg->status_name, omsg->status_text, code );
588
589                                 fflush(stdout);
590                         }
591
592                 } else {
593
594                         if(omsg->_result_content) {
595         
596                                 osrf_message_free(last_result);
597                                 last_result = omsg;
598         
599                                 char* content;
600         
601                                 if( pretty_print && omsg->_result_content ) {
602                                         char* j = object_to_json(omsg->_result_content);
603                                         //content = json_printer(j); 
604                                         content = json_string_format(j);
605                                         free(j);
606                                 } else
607                                         content = object_get_string(omsg->_result_content);
608         
609                                 buffer_add( resp_buffer, "\nReceived Data: " ); 
610                                 buffer_add( resp_buffer, content );
611                                 buffer_add( resp_buffer, "\n" );
612                                 free(content);
613         
614                         } else {
615         
616                                 buffer_add( resp_buffer, "\nReceived Exception:\nName: " );
617                                 buffer_add( resp_buffer, omsg->status_name );
618                                 buffer_add( resp_buffer, "\nStatus: " );
619                                 buffer_add( resp_buffer, omsg->status_text );
620                                 buffer_add( resp_buffer, "\nStatus: " );
621                                 char code[16];
622                                 memset(code, 0, 16);
623                                 sprintf( code, "%d", omsg->status_code );
624                                 buffer_add( resp_buffer, code );
625                         }
626                 }
627
628
629                 omsg = osrf_app_session_request_recv( session, req_id, 5 );
630
631         }
632
633         double end = get_timestamp_millis();
634
635         fprintf( less, resp_buffer->buf );
636         buffer_free( resp_buffer );
637         fprintf( less, "\n------------------------------------\n");
638         if( osrf_app_session_request_complete( session, req_id ))
639                 fprintf(less, "Request Completed Successfully\n");
640
641
642         fprintf(less, "Request Time in seconds: %.3f\n", end - start );
643         fprintf(less, "------------------------------------\n");
644
645         pclose(less); 
646
647         osrf_app_session_request_finish( session, req_id );
648         osrf_app_session_disconnect( session );
649         osrf_app_session_destroy( session );
650
651
652         return 1;
653
654
655 }
656
657 int handle_time( char* words[] ) {
658
659         if( ! words[1] ) {
660
661                 char buf[36];
662                 memset(buf,0,36);
663                 get_timestamp(buf);
664                 printf( "%s\n", buf );
665                 return 1;
666         }
667
668         if( words[1] ) {
669                 time_t epoch = (time_t)atoi( words[1] );
670                 char* localtime = strdup( ctime( &epoch ) );
671                 printf( "%s => %s", words[1], localtime );
672                 free(localtime);
673                 return 1;
674         }
675
676         return 0;
677
678 }
679
680                 
681
682 int router_query_servers( char* router_server ) {
683
684         if( ! router_server || strlen(router_server) == 0 ) 
685                 return 0;
686
687         char rbuf[256];
688         memset(rbuf,0,256);
689         sprintf(rbuf,"router@%s/router", router_server );
690                 
691         transport_message* send = 
692                 message_init( "servers", NULL, NULL, rbuf, NULL );
693         message_set_router_info( send, NULL, NULL, NULL, "query", 0 );
694
695         client_send_message( client, send );
696         message_free( send );
697
698         transport_message* recv = client_recv( client, -1 );
699         if( recv == NULL ) {
700                 fprintf(stderr, "NULL message received from router\n");
701                 return 1;
702         }
703         
704         printf( 
705                         "---------------------------------------------------------------------------------\n"
706                         "Received from 'server' query on %s\n"
707                         "---------------------------------------------------------------------------------\n"
708                         "original reg time | latest reg time | last used time | class | server\n"
709                         "---------------------------------------------------------------------------------\n"
710                         "%s"
711                         "---------------------------------------------------------------------------------\n"
712                         , router_server, recv->body );
713
714         message_free( recv );
715         
716         return 1;
717 }
718                 
719 int print_help() {
720
721         printf(
722                         "---------------------------------------------------------------------------------\n"
723                         "Commands:\n"
724                         "---------------------------------------------------------------------------------\n"
725                         "help                   - Display this message\n"
726                         "!<command> [args] - Forks and runs the given command in the shell\n"
727                         "time                   - Prints the current time\n"                                    
728                         "time <timestamp>       - Formats seconds since epoch into readable format\n"   
729                         "set <variable> <value> - set a srfsh variable (e.g. set pretty_print true )\n"
730                         "print <variable>               - Displays the value of a srfsh variable\n"
731                         "---------------------------------------------------------------------------------\n"
732
733                         "router query servers <server1 [, server2, ...]>\n"
734                         "       - Returns stats on connected services\n"
735                         "\n"
736                         "\n"
737                         "request <service> <method> [ <json formatted string of params> ]\n"
738                         "       - Anything passed in will be wrapped in a json array,\n"
739                         "               so add commas if there is more than one param\n"
740                         "\n"
741                         "\n"
742                         "relay <service> <method>\n"
743                         "       - Performs the requested query using the last received result as the param\n"
744                         "\n"
745                         "\n"
746                         "math_bench <num_batches> [0|1|2]\n"
747                         "       - 0 means don't reconnect, 1 means reconnect after each batch of 4, and\n"
748                         "                2 means reconnect after every request\n"
749                         "\n"
750                         "introspect <service>\n"
751                         "       - prints the API for the service\n"
752                         "\n"
753                         "\n"
754                         "---------------------------------------------------------------------------------\n"
755                         " Commands for Open-ILS\n"
756                         "---------------------------------------------------------------------------------\n"
757                         "login <username> <password>\n"
758                         "       -       Logs into the 'server' and displays the session id\n"
759                         "       - To view the session id later, enter: print login\n"
760                         "---------------------------------------------------------------------------------\n"
761                         "\n"
762                         "\n"
763                         "Note: long output is piped through 'less'.  To search in 'less', type: /<search>\n"
764                         "---------------------------------------------------------------------------------\n"
765                         "\n"
766                         );
767
768         return 1;
769 }
770
771
772
773 char* tabs(int count) {
774         growing_buffer* buf = buffer_init(24);
775         int i;
776         for(i=0;i!=count;i++)
777                 buffer_add(buf, "  ");
778
779         char* final = buffer_data( buf );
780         buffer_free( buf );
781         return final;
782 }
783
784 int handle_math( char* words[] ) {
785         if( words[1] && words[2] ) 
786                 return do_math( atoi(words[1]), atoi(words[2]) );
787         return 0;
788 }
789
790
791 int do_math( int count, int style ) {
792
793         osrf_app_session* session = osrf_app_client_session_init(  "opensrf.math" );
794
795         object* params = json_parse_string("[]");
796         params->push(params,new_object("1"));
797         params->push(params,new_object("2"));
798
799         char* methods[] = { "add", "sub", "mult", "div" };
800         char* answers[] = { "3", "-1", "2", "0.500000" };
801
802         float times[ count * 4 ];
803         memset(times,0,count*4);
804
805         int k;
806         for(k=0;k!=100;k++) {
807                 if(!(k%10)) 
808                         fprintf(stderr,"|");
809                 else
810                         fprintf(stderr,".");
811         }
812
813         fprintf(stderr,"\n\n");
814
815         int running = 0;
816         int i;
817         for(i=0; i!= count; i++) {
818
819                 int j;
820                 for(j=0; j != 4; j++) {
821
822                         ++running;
823                         struct timeb t1;
824                         struct timeb t2;
825
826                         ftime(&t1);
827                         //int req_id = osrf_app_session_make_request( session, params, methods[j], 1, NULL );
828                         int req_id = osrf_app_session_make_req( session, params, methods[j], 1, NULL );
829
830                         osrf_message* omsg = osrf_app_session_request_recv( session, req_id, 5 );
831
832
833                         ftime(&t2);
834
835                         double start    = ( (int)t1.time        + ( ((float)t1.millitm) / 1000 ) );
836                         double end              = ( (int)t2.time        + ( ((float)t2.millitm) / 1000 ) );
837
838                         times[(4*i) + j] = end - start;
839
840                         if(omsg) {
841         
842                                 if(omsg->_result_content) {
843                                         char* jsn = object_to_json(omsg->_result_content);
844                                         if(!strcmp(jsn, answers[j]))
845                                                 fprintf(stderr, "+");
846                                         else
847                                                 fprintf(stderr, "\n![%s] - should be %s\n", jsn, answers[j] );
848                                         free(jsn);
849                                 }
850
851
852                                 osrf_message_free(omsg);
853                 
854                         } else { fprintf( stderr, "\nempty message for tt: %d\n", req_id ); }
855
856                         osrf_app_session_request_finish( session, req_id );
857
858                         if(style == 2)
859                                 osrf_app_session_disconnect( session );
860
861                         if(!(running%100))
862                                 fprintf(stderr,"\n");
863                 }
864
865                 if(style==1)
866                         osrf_app_session_disconnect( session );
867         }
868
869         osrf_app_session_destroy( session );
870         free_object(params);
871
872         int c;
873         float total = 0;
874         for(c=0; c!= count*4; c++) 
875                 total += times[c];
876
877         float avg = total / (count*4); 
878         fprintf(stderr, "\n      Average round trip time: %f\n", avg );
879
880         return 1;
881 }