Debian Codegraph @

rxqueue.c

raw
1 /*
2 * The Regina Rexx Interpreter
3 * Copyright (C) 1992-1994 Anders Christensen <[email protected]>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #define NO_CTYPE_REPLACEMENT
21 #include "rexx.h"
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #else
26 # include "configur.h"
27 #endif
28
29 #ifdef WIN32
30 # if defined(_MSC_VER)
31 # if _MSC_VER >= 1100
32 /* Stupid MSC can't compile own headers without warning at least in VC 5.0 */
33 # pragma warning(disable: 4115 4201 4214 4514)
34 # endif
35 # include <windows.h>
36 # if _MSC_VER >= 1100
37 # pragma warning(default: 4115 4201 4214)
38 # endif
39 # else
40 # include <windows.h>
41 # endif
42 # include <io.h>
43 #else
44 # ifdef HAVE_SYS_SOCKET_H
45 # include <sys/socket.h>
46 # endif
47 # ifdef HAVE_NETINET_IN_H
48 # include <netinet/in.h>
49 # endif
50 # ifdef HAVE_SYS_SELECT_H
51 # include <sys/select.h>
52 # endif
53 # ifdef HAVE_NETDB_H
54 # include <netdb.h>
55 # endif
56 # ifdef HAVE_ARPA_INET_H
57 # include <arpa/inet.h>
58 # endif
59 # define closesocket(x) close(x)
60 #endif
61
62 #ifdef __LCC__
63 # include <winsock2.h>
64 #endif
65
66 #include <string.h>
67
68 #ifdef HAVE_UNISTD_H
69 #include <unistd.h>
70 #endif
71
72 #ifdef HAVE_ERRNO_H
73 #include <errno.h>
74 #endif
75
76 #ifdef HAVE_SIGNAL_H
77 #include <signal.h>
78 #endif
79
80 #ifdef HAVE_CTYPE_H
81 #include <ctype.h>
82 #endif
83
84 #include "extstack.h"
85 #ifndef HAVE_GETOPT_LONG
86 # include "mygetopt.h"
87 #endif
88
89 #define SUCCESS(a) ((a)&&(a)->value[0] == '0')
90
91 /*
92 * debugging is turned off. You can turn it on by the command line option "-D".
93 */
94 static int debug = 0 ;
95 #define DEBUGDUMP(x) { if ( debug ) \
96 {x;} \
97 }
98
99 static int fromtext = 0;
100
101 char *buff=NULL;
102 unsigned int bufflen=0;
103
104 static streng *session = NULL;
105
106 #if !defined(HAVE_STRERROR)
107 /*
108 * Sigh! This must probably be done this way, although it's incredibly
109 * backwards. Some versions of gcc comes with a complete set of ANSI C
110 * include files, which contains the definition of strerror(). However,
111 * that function does not exist in the default libraries of SunOS.
112 * To circumvent that problem, strerror() is #define'd to get_sys_errlist()
113 * in config.h, and here follows the definition of that function.
114 * Originally, strerror() was #defined to sys_errlist[x], but that does
115 * not work if string.h contains a declaration of the (non-existing)
116 * function strerror().
117 *
118 * So, this is a mismatch between the include files and the library, and
119 * it should not create problems for Regina. However, the _user_ will not
120 * encounter any problems until he compiles Regina, so we'll have to
121 * clean up after a buggy installation of the C compiler!
122 */
123 const char *get_sys_errlist( int num )
124 {
125 extern char *sys_errlist[] ;
126 return sys_errlist[num] ;
127 }
128 #endif
129
130 streng *Str_upper( streng *str )
131 {
132 int i;
133
134 for ( i = 0; i < PSTRENGLEN( str ); i++ )
135 {
136 if ( islower( str->value[i] ) )
137 str->value[i] = (char)toupper( str->value[i] );
138 }
139 return str;
140 }
141
142 int Str_cmp( const streng *first, const streng *second )
143 {
144 int lim;
145
146 lim = Str_len( first );
147 if ( lim != Str_len( second ) )
148 return 1;
149
150 return memcmp( first->value, second->value, lim );
151 }
152
153 int send_all( int sock, char *action )
154 {
155 /*
156 * Send everything in stdin to the socket. Each LF encountered
157 * results in a send.
158 * This code borrowed from rxstack.c in REXX/imc
159 */
160 int c,rc;
161 unsigned int len;
162 streng *result;
163
164 for ( ; ; )
165 {
166 if ( fromtext )
167 {
168 len = strlen( buff );
169 }
170 else
171 {
172 len = 0;
173 while ( ( c = getchar() ) != EOF )
174 {
175 if ( c == REGINA_EOL )
176 {
177 #if defined(DOS) || defined(OS2) || defined(WIN32)
178 if (len && ( buff[len-1] == REGINA_CR ) )
179 len--;
180 #endif
181 break;
182 }
183 if ( len >= bufflen
184 && (( buff = (char *)realloc( buff, bufflen <<= 1 ) ) == NULL ) )
185 {
186 showerror( ERR_STORAGE_EXHAUSTED, 0, ERR_STORAGE_EXHAUSTED_TMPL );
187 exit( ERR_STORAGE_EXHAUSTED );
188 }
189 buff[len++] = (char)c;
190 }
191 if ( (c == EOF || feof(stdin) )
192 && !len)
193 break;
194 }
195 DEBUGDUMP(printf("--- Queue %s from %s ---\n", action[0] == RXSTACK_QUEUE_FIFO ? "FIFO" : "LIFO", fromtext ? "text" : "stdin"););
196 rc = send_command_to_rxstack( NULL, sock, action, buff, len );
197 if ( rc != -1 )
198 {
199 result = read_result_from_rxstack( NULL, sock, RXSTACK_HEADER_SIZE );
200 DROPSTRENG( result );
201 }
202 if ( fromtext )
203 break;
204 }
205 return 0;
206 }
207
208 char *get_unspecified_queue( void )
209 {
210 char *rxq = getenv( "RXQUEUE" );
211
212 if ( rxq == NULL )
213 rxq = "SESSION";
214 return rxq;
215 }
216
217 char *force_remote( char *rxq )
218 {
219 char *h ;
220
221 if ( strchr(rxq, '@' ) == NULL )
222 {
223 if ( ( h = (char *)malloc( strlen( rxq ) + 2 ) ) != NULL )
224 {
225 strcpy( h, rxq ) ;
226 strcat( h, "@" ) ;
227 return h ;
228 }
229 }
230 return rxq ;
231 }
232
233 char *get_action( char *parm )
234 {
235 char *action=NULL;
236
237 if ( strcmp( parm, "/fifo" ) == 0 )
238 action = RXSTACK_QUEUE_FIFO_STR;
239 else if ( strcmp( parm, "/lifo" ) == 0 )
240 action = RXSTACK_QUEUE_LIFO_STR;
241 else if ( strcmp( parm, "/clear" ) == 0 )
242 action = RXSTACK_EMPTY_QUEUE_STR;
243 else if ( strcmp( parm, "/pull" ) == 0 )
244 action = RXSTACK_PULL_STR;
245 else if ( strcmp( parm, "/queued" ) == 0 )
246 action = RXSTACK_NUMBER_IN_QUEUE_STR;
247 else if ( strcmp( parm, "/delete" ) == 0 )
248 action = RXSTACK_DELETE_QUEUE_STR;
249 else if ( strcmp( parm, "/list" ) == 0 )
250 action = RXSTACK_SHOW_QUEUES_STR;
251 else
252 {
253 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INVALID_SWITCH, ERR_RXSTACK_INVALID_SWITCH_TMPL, "/fifo, /lifo, /clear, /queued, /pull, /list" );
254 /* not setting action will exit */
255 }
256 return action;
257 }
258
259 void junk_return_from_rxstack( int sock, streng *header )
260 {
261 int length;
262 streng *result;
263
264 length = get_length_from_header( NULL, header );
265 if ( length )
266 {
267 result = read_result_from_rxstack( NULL, sock, length );
268 if ( result )
269 DROPSTRENG( result );
270
271 }
272 }
273
274 /*
275 * Gives a short usage description on stderr and returns 1
276 */
277 static int usage( const char *argv0 )
278 {
279 fprintf( stdout, "\n%s: %s (%d bit). All rights reserved.\n", argv0, PARSE_VERSION_STRING, REGINA_BITS );
280 fprintf( stdout,"Regina is distributed under the terms of the GNU Library General Public License \n" );
281 fprintf( stdout,"and comes with NO WARRANTY. See the file COPYING-LIB for details.\n" );
282 fprintf( stdout,"\n%s [switches] [queue] [command]\n", argv0 );
283 fprintf( stdout,"where switches are:\n\n" );
284 fprintf( stdout," --help, -h show this message\n" );
285 fprintf( stdout," --version, -v display Regina version and exit\n" );
286 fprintf( stdout," --debug, -D turn on debugging\n" );
287 fprintf( stdout," --text, -t text to add to queue (ignores input on stdin)\n" );
288 fprintf( stdout,"\n[queue] is the optional queue name to be used\n");
289 fprintf( stdout,"\nand command is one of:\n\n" );
290 fprintf( stdout," /fifo add text into [queue] first-in-first-out\n" );
291 fprintf( stdout," /lifo add text into [queue] last-in-first-out\n" );
292 fprintf( stdout," /clear clears all lines in [queue]\n" );
293 fprintf( stdout," /delete delete queue\n" );
294 fprintf( stdout," /pull pulls all lines from [queue]\n" );
295 fprintf( stdout," /queued displays number of lines in [queue]\n" );
296 fprintf( stdout," /list displays list of queues held by rxstack\n" );
297 fflush( stdout );
298 return 1 ;
299 }
300
301 int cleanup( void )
302 {
303 #ifdef WIN32
304 WSACleanup();
305 #endif
306 if ( buff )
307 free( buff );
308 return 0;
309 }
310
311 int main( int argc, char *argv[])
312 {
313 int sock,rc=0,num,c;
314 char *action;
315 streng *queue=NULL,*server_name=NULL;
316 char *in_queue=NULL;
317 streng *result;
318 Queue q;
319 const char *argv0 = argv[ 0 ] ;
320 static struct my_getopt_option long_options[] =
321 {
322 {"help", no_argument, 0, 'h' },
323 {"debug", no_argument, 0, 'D' },
324 {"text", required_argument, 0, 't' },
325 {"version", no_argument, 0, 'v' },
326 {0, 0, 0, 0 }
327 };
328 #ifdef WIN32
329 WORD wsver = (WORD)MAKEWORD(1,1);
330 WSADATA wsaData;
331 #endif
332
333 #ifdef WIN32
334 if ( WSAStartup( wsver, &wsaData ) != 0 )
335 {
336 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_NO_WINSOCK, ERR_RXSTACK_NO_WINSOCK_TMPL, WSAGetLastError() );
337 exit(ERR_RXSTACK_NO_WINSOCK);
338 }
339 #endif
340 if ( getenv( "RXDEBUG" ) != NULL )
341 debug = 1 ;
342 while (1)
343 {
344 int option_index = 0;
345
346 c = my_getopt_long( argc, argv, "+hDt:v", long_options, &option_index );
347 if ( c == -1 )
348 break;
349
350 switch(c)
351 {
352 case 'h':
353 return usage( argv0 );
354 break;
355 case 'D': /* debug */
356 debug = 1;
357 putenv( "RXDEBUG=1" ) ;
358 break;
359 case 't': /* input from command line */
360 fromtext = 1;
361 buff = strdup( optarg );
362 break;
363 case 'v':
364 fprintf( stderr, "%s: %s (%d bit)\n", argv0, PARSE_VERSION_STRING, REGINA_BITS );
365 return 0;
366 default: /* unknown switch */
367 return usage( argv0 );
368 break;
369 }
370 }
371 num = argc - optind;
372
373 action = NULL;
374 /*
375 * Process the command line
376 */
377 if ( num == 0 )
378 {
379 /*
380 * "rxqueue"
381 */
382 action = RXSTACK_QUEUE_FIFO_STR;
383 in_queue = get_unspecified_queue();
384 }
385 else if ( num == 1 )
386 {
387 /*
388 * "rxqueue queue"
389 * or
390 * "rxqueue /switch"
391 */
392 if ( argv[optind][0] == '/' )
393 {
394 /*
395 * Only parameter is a switch
396 */
397 in_queue = get_unspecified_queue();
398 action = get_action( argv[optind] );
399 }
400 else
401 {
402 /*
403 * Only parameter is a queue name
404 */
405 in_queue = argv[optind];
406 action = RXSTACK_QUEUE_FIFO_STR;
407 }
408 }
409 else if ( num == 2 )
410 {
411 /*
412 * "rxqueue queue /switch"
413 */
414 in_queue = argv[optind];
415 if ( argv[optind+1][0] == '/' )
416 {
417 /*
418 * Parameter is a switch
419 */
420 action = get_action( argv[optind+1] );
421 }
422 }
423 else
424 {
425 /*
426 * ERROR
427 */
428 fprintf(stderr, "Invalid number of parameters\n");
429 return usage( argv0 );
430 }
431 /*
432 * Validate actions with -t or --text switches
433 */
434 if ( fromtext )
435 {
436 if ( action[0] == RXSTACK_EMPTY_QUEUE )
437 {
438 fprintf(stderr, "-t or --text switch invalid with /clear action.\n");
439 return usage( argv0 );
440 }
441 else if ( action[0] == RXSTACK_PULL )
442 {
443 fprintf(stderr, "-t or --text switch invalid with /pull action.\n");
444 return usage( argv0 );
445 }
446 else if ( action[0] == RXSTACK_NUMBER_IN_QUEUE )
447 {
448 fprintf(stderr, "-t or --text switch invalid with /queued action.\n");
449 return usage( argv0 );
450 }
451 else if ( action[0] == RXSTACK_DELETE_QUEUE )
452 {
453 fprintf(stderr, "-t or --text switch invalid with /delete action.\n");
454 return usage( argv0 );
455 }
456 else if ( action[0] == RXSTACK_SHOW_QUEUES )
457 {
458 fprintf(stderr, "-t or --text switch invalid with /list action.\n");
459 return usage( argv0 );
460 }
461 }
462 in_queue = force_remote( in_queue ) ;
463 if ( action )
464 {
465 queue = MAKESTRENG( strlen( in_queue ) );
466 if ( queue == NULL )
467 {
468 showerror( ERR_STORAGE_EXHAUSTED, 0, ERR_STORAGE_EXHAUSTED_TMPL );
469 exit(ERR_STORAGE_EXHAUSTED);
470 }
471 memcpy( PSTRENGVAL( queue ), in_queue, PSTRENGLEN( queue ) );
472 queue->len = strlen( in_queue ) ;
473 /*
474 * Parse the queue to determine server address
475 * and queue name
476 */
477 if ( parse_queue( NULL, queue, &q ) == 1 )
478 {
479 if ( PSTRENGLEN( queue ) == 0 )
480 {
481 DROPSTRENG( queue );
482 queue = MAKESTRENG( 7 );
483 if ( queue == NULL )
484 {
485 showerror( ERR_STORAGE_EXHAUSTED, 0, ERR_STORAGE_EXHAUSTED_TMPL );
486 exit(ERR_STORAGE_EXHAUSTED);
487 }
488 memcpy( PSTRENGVAL( queue ), "SESSION", 7 );
489 queue->len = 7 ;
490 }
491 DEBUGDUMP(printf( "queue: <%.*s> server: %.*s<%d> Port:%d\n", PSTRENGLEN( queue ), PSTRENGVAL( queue ), PSTRENGLEN( q.u.e.name ), PSTRENGVAL( q.u.e.name ), q.u.e.address, q.u.e.portno ););
492 sock = connect_to_rxstack( NULL, &q );
493 if ( sock < 0 )
494 {
495 cleanup();
496 exit(ERR_RXSTACK_CANT_CONNECT);
497 }
498 /*
499 * Now process the actual command
500 */
501 switch( action[0] )
502 {
503 case RXSTACK_QUEUE_FIFO:
504 case RXSTACK_QUEUE_LIFO:
505 DEBUGDUMP(printf("--- Queue %s ", action[0] == RXSTACK_QUEUE_FIFO ? "FIFO" : "LIFO"););
506 /*
507 * Allocate the initial buffer if input is from stdin
508 */
509 if ( fromtext == 0 )
510 {
511 if (( buff = (char *)malloc( bufflen = 256 ) ) == NULL )
512 {
513 showerror( ERR_STORAGE_EXHAUSTED, 0, ERR_STORAGE_EXHAUSTED_TMPL );
514 rc = ERR_STORAGE_EXHAUSTED;
515 break;
516 }
517 }
518 /*
519 * Set the current queue
520 */
521 DEBUGDUMP(printf("(Set Queue) ---\n"););
522 rc = send_command_to_rxstack( NULL, sock, RXSTACK_SET_QUEUE_STR, PSTRENGVAL( queue) , PSTRENGLEN( queue ) );
523 if ( rc == -1 )
524 {
525 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Setting default queue" );
526 rc = ERR_RXSTACK_INTERNAL;
527 break;
528 }
529 result = read_result_from_rxstack( NULL, sock, RXSTACK_HEADER_SIZE );
530 if ( !SUCCESS( result ) )
531 {
532 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Setting default queue" );
533 DROPSTRENG( result );
534 rc = ERR_RXSTACK_INTERNAL;
535 break;
536 }
537 /*
538 * Success. We need to throw away the returned queue name. We
539 * don't need it.
540 */
541 junk_return_from_rxstack( sock, result );
542 send_all( sock, action );
543 DROPSTRENG( result );
544 rc = 0;
545 break;
546 case RXSTACK_EMPTY_QUEUE:
547 DEBUGDUMP(printf("--- Empty Queue ---\n"););
548 rc = send_command_to_rxstack( NULL, sock, action, PSTRENGVAL( queue) , PSTRENGLEN( queue ) );
549 if ( rc == -1 )
550 {
551 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Emptying queue" );
552 rc = ERR_RXSTACK_INTERNAL;
553 break;
554 }
555 result = read_result_from_rxstack( NULL, sock, RXSTACK_HEADER_SIZE );
556 if ( !SUCCESS( result ) )
557 {
558 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Emptying queue" );
559 DROPSTRENG( result );
560 rc = ERR_RXSTACK_INTERNAL;
561 break;
562 }
563 DROPSTRENG( result );
564 rc = 0;
565 break;
566 case RXSTACK_NUMBER_IN_QUEUE:
567 /*
568 * Set the current queue
569 */
570 DEBUGDUMP(printf("--- Set Queue ---\n"););
571 rc = send_command_to_rxstack( NULL, sock, RXSTACK_SET_QUEUE_STR, PSTRENGVAL( queue ), PSTRENGLEN( queue ) );
572 if ( rc == -1 )
573 {
574 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Setting default queue" );
575 rc = ERR_RXSTACK_INTERNAL;
576 break;
577 }
578 /*
579 * Read the return response header
580 */
581 result = read_result_from_rxstack( NULL, sock, RXSTACK_HEADER_SIZE );
582 if ( !SUCCESS( result ) )
583 {
584 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Setting default queue" );
585 DROPSTRENG( result );
586 rc = ERR_RXSTACK_INTERNAL;
587 break;
588 }
589 /*
590 * Success. We need to throw away the returned queue name. We
591 * don't need it.
592 */
593 junk_return_from_rxstack( sock, result );
594 DROPSTRENG( result );
595 DEBUGDUMP(printf("--- Number in Queue ---\n"););
596 num = get_number_in_queue_from_rxstack( NULL, sock, &rc );
597 if ( rc == 0 )
598 printf("%d\n", num );
599 break;
600 case RXSTACK_DELETE_QUEUE:
601 /*
602 * Delete the specified queue
603 */
604 DEBUGDUMP(printf("--- Delete Queue ---\n"););
605 session = MAKESTRENG( 7 );
606 memcpy( PSTRENGVAL( session ), "SESSION", 7 );
607 session->len = 7;
608 if ( Str_cmp( session, queue ) == 0 )
609 {
610 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_ACTION_SESSION, ERR_RXSTACK_ACTION_SESSION_TMPL, "delete" );
611 rc = ERR_RXSTACK_INTERNAL;
612 break;
613 }
614 rc = send_command_to_rxstack( NULL, sock, action, PSTRENGVAL( queue) , PSTRENGLEN( queue ) );
615 if ( rc == -1 )
616 {
617 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Deleting queue" );
618 rc = ERR_RXSTACK_INTERNAL;
619 break;
620 }
621 result = read_result_from_rxstack( NULL, sock, RXSTACK_HEADER_SIZE );
622 if ( !SUCCESS( result ) )
623 {
624 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Deleting queue" );
625 DROPSTRENG( result );
626 rc = ERR_RXSTACK_INTERNAL;
627 break;
628 }
629 DROPSTRENG( result );
630 rc = 0;
631 break;
632 case RXSTACK_SHOW_QUEUES:
633 DEBUGDUMP(printf("----- Show Queues -----\n"););
634 num = get_queues_from_rxstack( NULL, sock, &rc, &result );
635 if ( rc == 0 )
636 {
637 printf( "%.*s\n", PSTRENGLEN( result ), PSTRENGVAL( result ) ) ;
638 }
639 DROPSTRENG( result );
640 break;
641 case RXSTACK_PULL:
642 /*
643 * Set the current queue
644 */
645 DEBUGDUMP(printf("--- Set Queue ---\n"););
646 rc = send_command_to_rxstack( NULL, sock, RXSTACK_SET_QUEUE_STR, PSTRENGVAL( queue ), PSTRENGLEN( queue ) );
647 if ( rc == -1 )
648 {
649 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Setting default queue" );
650 rc = ERR_RXSTACK_INTERNAL;
651 break;
652 }
653 result = read_result_from_rxstack( NULL, sock, RXSTACK_HEADER_SIZE );
654 if ( !SUCCESS( result ) )
655 {
656 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Setting default queue" );
657 DROPSTRENG( result );
658 rc = ERR_RXSTACK_INTERNAL;
659 break;
660 }
661 /*
662 * Success. We need to throw away the returned queue name. We
663 * don't need it.
664 */
665 junk_return_from_rxstack( sock, result );
666 DROPSTRENG( result );
667 /*
668 * Loop until the number of lines on the queue is zero
669 */
670 for ( ; ; )
671 {
672 DEBUGDUMP(printf("--- Pull ---\n"););
673 rc = get_line_from_rxstack( NULL, sock, &result, 0 );
674 if ( rc == 0 )
675 {
676 printf( "%.*s\n", PSTRENGLEN( result ), PSTRENGVAL( result ) ) ;
677 }
678 else if ( ( rc == 1 ) || ( rc == 4 ) )
679 {
680 /*
681 * Queue empty.
682 */
683 rc = 0;
684 break;
685 }
686 else
687 {
688 showerror( ERR_EXTERNAL_QUEUE, ERR_RXSTACK_INTERNAL, ERR_RXSTACK_INTERNAL_TMPL, rc, "Getting line from queue" );
689 rc = ERR_RXSTACK_INTERNAL;
690 break;
691 }
692 DROPSTRENG( result );
693 }
694 break;
695 }
696 /*
697 * Tell the server we want to disconnect
698 * Don't expect any return result.
699 */
700 DEBUGDUMP(printf("--- Exit ---\n"););
701 send_command_to_rxstack( NULL, sock, RXSTACK_EXIT_STR, NULL, 0 );
702 closesocket(sock);
703 }
704 else
705 {
706 DEBUGDUMP(printf( "queue: <%.*s>\n", PSTRENGLEN( queue ), PSTRENGVAL( queue ) ););
707 rc = 1;
708 }
709 }
710 DROPSTRENG( server_name );
711 DROPSTRENG( queue );
712 cleanup();
713 return rc;
714 }