]> git.sesse.net Git - vlc/blob - modules/stream_out/rtsp.c
Factorize aggregate and non-aggregate RTSP code paths
[vlc] / modules / stream_out / rtsp.c
1 /*****************************************************************************
2  * rtsp.c: RTSP support for RTP stream output module
3  *****************************************************************************
4  * Copyright (C) 2003-2004 the VideoLAN team
5  * Copyright © 2007 Rémi Denis-Courmont
6  *
7  * $Id: rtp.c 21407 2007-08-22 20:10:41Z courmisch $
8  *
9  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <vlc/vlc.h>
30 #include <vlc_sout.h>
31
32 #include <vlc_httpd.h>
33 #include <vlc_url.h>
34 #include <vlc_network.h>
35 #include <vlc_rand.h>
36 #include <assert.h>
37 #include <errno.h>
38 #include <stdlib.h>
39
40 #include "rtp.h"
41
42 typedef struct rtsp_session_t rtsp_session_t;
43
44 struct rtsp_stream_t
45 {
46     vlc_mutex_t     lock;
47     sout_stream_t  *owner;
48     httpd_host_t   *host;
49     httpd_url_t    *url;
50     char           *psz_path;
51     unsigned        port;
52
53     int             sessionc;
54     rtsp_session_t **sessionv;
55 };
56
57
58 static int  RtspCallback( httpd_callback_sys_t *p_args,
59                           httpd_client_t *cl, httpd_message_t *answer,
60                           const httpd_message_t *query );
61 static int  RtspCallbackId( httpd_callback_sys_t *p_args,
62                             httpd_client_t *cl, httpd_message_t *answer,
63                             const httpd_message_t *query );
64 static void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session );
65
66 rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url )
67 {
68     rtsp_stream_t *rtsp = malloc( sizeof( *rtsp ) );
69
70     if( rtsp == NULL || ( url->i_port > 99999 ) )
71         return NULL;
72
73     rtsp->owner = p_stream;
74     rtsp->sessionc = 0;
75     rtsp->sessionv = NULL;
76     vlc_mutex_init( p_stream, &rtsp->lock );
77
78     msg_Dbg( p_stream, "rtsp setup: %s : %d / %s\n",
79              url->psz_host, url->i_port, url->psz_path );
80
81     rtsp->port = (url->i_port > 0) ? url->i_port : 554;
82     if( url->psz_path != NULL )
83         rtsp->psz_path = strdup( url->psz_path + 1 );
84     else
85         rtsp->psz_path = NULL;
86
87 #if 0
88     if( asprintf( &rtsp->psz_control, "rtsp://%s:%d%s",
89                   url->psz_host,  url->i_port > 0 ? url->i_port : 554,
90                   rtsp->psz_path ) == -1 )
91     {
92         rtsp->psz_control = NULL;
93         goto error;
94     }
95 #endif
96
97     rtsp->host = httpd_HostNew( VLC_OBJECT(p_stream), url->psz_host,
98                                 rtsp->port );
99     if( rtsp->host == NULL )
100         goto error;
101
102     rtsp->url = httpd_UrlNewUnique( rtsp->host,
103                                     url->psz_path ? url->psz_path : "/", NULL,
104                                     NULL, NULL );
105     if( rtsp->url == NULL )
106         goto error;
107
108     httpd_UrlCatch( rtsp->url, HTTPD_MSG_DESCRIBE, RtspCallback, (void*)rtsp );
109     httpd_UrlCatch( rtsp->url, HTTPD_MSG_SETUP,    RtspCallback, (void*)rtsp );
110     httpd_UrlCatch( rtsp->url, HTTPD_MSG_PLAY,     RtspCallback, (void*)rtsp );
111     httpd_UrlCatch( rtsp->url, HTTPD_MSG_PAUSE,    RtspCallback, (void*)rtsp );
112     httpd_UrlCatch( rtsp->url, HTTPD_MSG_GETPARAMETER, RtspCallback,
113                     (void*)rtsp );
114     httpd_UrlCatch( rtsp->url, HTTPD_MSG_TEARDOWN, RtspCallback, (void*)rtsp );
115     return rtsp;
116
117 error:
118     RtspUnsetup( rtsp );
119     return NULL;
120 }
121
122
123 void RtspUnsetup( rtsp_stream_t *rtsp )
124 {
125     while( rtsp->sessionc > 0 )
126         RtspClientDel( rtsp, rtsp->sessionv[0] );
127
128     if( rtsp->url )
129         httpd_UrlDelete( rtsp->url );
130
131     if( rtsp->host )
132         httpd_HostDelete( rtsp->host );
133
134     vlc_mutex_destroy( &rtsp->lock );
135 }
136
137
138 struct rtsp_stream_id_t
139 {
140     rtsp_stream_t    *stream;
141     sout_stream_id_t *sout_id;
142     httpd_url_t      *url;
143     const char       *dst;
144     int               ttl;
145     unsigned          loport, hiport;
146 };
147
148
149 typedef struct rtsp_strack_t rtsp_strack_t;
150
151 /* For unicast streaming */
152 struct rtsp_session_t
153 {
154     rtsp_stream_t *stream;
155     uint64_t       id;
156
157     /* output (id-access) */
158     int            trackc;
159     rtsp_strack_t *trackv;
160 };
161
162
163 /* Unicast session track */
164 struct rtsp_strack_t
165 {
166     sout_stream_id_t  *id;
167     sout_access_out_t *access;
168     vlc_bool_t         playing;
169 };
170
171
172 rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
173                              unsigned num,
174                              /* Multicast stuff - TODO: cleanup */
175                              const char *dst, int ttl,
176                              unsigned loport, unsigned hiport )
177 {
178     char urlbuf[sizeof( "//trackID=123" ) + strlen( rtsp->psz_path )];
179     rtsp_stream_id_t *id = malloc( sizeof( *id ) );
180     httpd_url_t *url;
181
182     if( id == NULL )
183         return NULL;
184
185     id->stream = rtsp;
186     id->sout_id = sid;
187     /* TODO: can we assume that this need not be strdup'd? */
188     id->dst = dst;
189     if( id->dst != NULL )
190     {
191         id->ttl = ttl;
192         id->loport = loport;
193         id->hiport = hiport;
194     }
195
196     snprintf( urlbuf, sizeof( urlbuf ), "/%s/trackID=%u", rtsp->psz_path,
197               num );
198     msg_Dbg( rtsp->owner, "RTSP: adding %s\n", urlbuf );
199     url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL );
200
201     if( url == NULL )
202     {
203         free( id );
204         return NULL;
205     }
206
207     httpd_UrlCatch( url, HTTPD_MSG_DESCRIBE, RtspCallbackId, (void *)id );
208     httpd_UrlCatch( url, HTTPD_MSG_SETUP,    RtspCallbackId, (void *)id );
209     httpd_UrlCatch( url, HTTPD_MSG_PLAY,     RtspCallbackId, (void *)id );
210     httpd_UrlCatch( url, HTTPD_MSG_PAUSE,    RtspCallbackId, (void *)id );
211     httpd_UrlCatch( url, HTTPD_MSG_GETPARAMETER, RtspCallbackId, (void *)id );
212     httpd_UrlCatch( url, HTTPD_MSG_TEARDOWN, RtspCallbackId, (void *)id );
213
214     return id;
215 }
216
217
218 void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id )
219 {
220     vlc_mutex_lock( &rtsp->lock );
221     for( int i = 0; i < rtsp->sessionc; i++ )
222     {
223         rtsp_session_t *ses = rtsp->sessionv[i];
224
225         for( int j = 0; j < ses->trackc; j++ )
226         {
227             if( ses->trackv[j].id == id->sout_id )
228             {
229                 rtsp_strack_t *tr = ses->trackv + j;
230                 sout_AccessOutDelete( tr->access );
231                 REMOVE_ELEM( ses->trackv, ses->trackc, j );
232                 /* FIXME: are we supposed to notify the client? */
233             }
234         }
235     }
236
237     vlc_mutex_unlock( &rtsp->lock );
238     httpd_UrlDelete( id->url );
239     free( id );
240 }
241
242
243 /** rtsp must be locked */
244 static
245 rtsp_session_t *RtspClientNew( rtsp_stream_t *rtsp )
246 {
247     rtsp_session_t *s = malloc( sizeof( *s ) );
248     if( s == NULL )
249         return NULL;
250
251     s->stream = rtsp;
252     vlc_rand_bytes (&s->id, sizeof (s->id));
253     s->trackc = 0;
254     s->trackv = NULL;
255
256     TAB_APPEND( rtsp->sessionc, rtsp->sessionv, s );
257
258     return s;
259 }
260
261
262 /** rtsp must be locked */
263 static
264 rtsp_session_t *RtspClientGet( rtsp_stream_t *rtsp, const char *name )
265 {
266     char *end;
267     uint64_t id;
268     int i;
269
270     if( name == NULL )
271         return NULL;
272
273     errno = 0;
274     id = strtoull( name, &end, 0x10 );
275     if( errno || *end )
276         return NULL;
277
278     /* FIXME: use a hash/dictionary */
279     for( i = 0; i < rtsp->sessionc; i++ )
280     {
281         if( rtsp->sessionv[i]->id == id )
282             return rtsp->sessionv[i];
283     }
284     return NULL;
285 }
286
287
288 /** rtsp must be locked */
289 static
290 void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session )
291 {
292     int i;
293     TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session );
294
295     for( i = 0; i < session->trackc; i++ )
296     {
297         rtp_del_sink( session->trackv[i].id, session->trackv[i].access );
298         sout_AccessOutDelete( session->trackv[i].access );
299     }
300
301     free( session->trackv );
302     free( session );
303 }
304
305
306 /** Finds the next transport choice */
307 static inline const char *transport_next( const char *str )
308 {
309     /* Looks for comma */
310     str = strchr( str, ',' );
311     if( str == NULL )
312         return NULL; /* No more transport options */
313
314     str++; /* skips comma */
315     while( strchr( "\r\n\t ", *str ) )
316         str++;
317
318     return (*str) ? str : NULL;
319 }
320
321
322 /** Finds the next transport parameter */
323 static inline const char *parameter_next( const char *str )
324 {
325     while( strchr( ",;", *str ) == NULL )
326         str++;
327
328     return (*str == ';') ? (str + 1) : NULL;
329 }
330
331
332 /** RTSP requests handler
333  * @param id selected track for non-aggregate URLs,
334  *           NULL for aggregate URLs
335  */
336 static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
337                         httpd_client_t *cl,
338                         httpd_message_t *answer,
339                         const httpd_message_t *query )
340 {
341     sout_stream_t *p_stream = id->stream->owner;
342     char psz_sesbuf[17];
343     const char *psz_session = NULL, *psz;
344
345     if( answer == NULL || query == NULL )
346         return VLC_SUCCESS;
347
348     /* */
349     answer->i_proto = HTTPD_PROTO_RTSP;
350     answer->i_version= query->i_version;
351     answer->i_type   = HTTPD_MSG_ANSWER;
352     answer->i_body = 0;
353     answer->p_body = NULL;
354
355     if( httpd_MsgGet( query, "Require" ) != NULL )
356     {
357         answer->i_status = 551;
358         httpd_MsgAdd( answer, "Unsupported", "%s",
359                       httpd_MsgGet( query, "Require" ) );
360     }
361     else
362     switch( query->i_type )
363     {
364         case HTTPD_MSG_DESCRIBE:
365         {   /* Aggregate-only */
366             if( id != NULL )
367             {
368                 answer->i_status = 460;
369                 break;
370             }
371
372             char ip[NI_MAXNUMERICHOST], *ptr;
373             char control[sizeof("rtsp://[]:12345/") + sizeof( ip )
374                             + strlen( rtsp->psz_path )];
375
376             /* Build self-referential URL */
377             httpd_ServerIP( cl, ip );
378             ptr = strchr( ip, '%' );
379             if( ptr != NULL )
380                 *ptr = '\0';
381
382             if( strchr( ip, ':' ) != NULL )
383                 sprintf( control, "rtsp://[%s]:%u/%s", ip, rtsp->port,
384                          ( rtsp->psz_path != NULL ) ? rtsp->psz_path : "" );
385             else
386                 sprintf( control, "rtsp://%s:%u/%s", ip, rtsp->port,
387                          ( rtsp->psz_path != NULL ) ? rtsp->psz_path : "" );
388
389             ptr = SDPGenerate( rtsp->owner, control );
390
391             answer->i_status = 200;
392             httpd_MsgAdd( answer, "Content-Type",  "%s", "application/sdp" );
393             httpd_MsgAdd( answer, "Content-Base",  "%s", control );
394             answer->p_body = (uint8_t *)ptr;
395             answer->i_body = strlen( ptr );
396             break;
397         }
398
399         case HTTPD_MSG_SETUP:
400             /* Non-aggregate-only */
401             if( id == NULL )
402             {
403                 answer->i_status = 459;
404                 break;
405             }
406
407             psz_session = httpd_MsgGet( query, "Session" );
408             answer->i_status = 461;
409
410             for( const char *tpt = httpd_MsgGet( query, "Transport" );
411                  tpt != NULL;
412                  tpt = transport_next( tpt ) )
413             {
414                 vlc_bool_t b_multicast = VLC_TRUE, b_unsupp = VLC_FALSE;
415                 unsigned loport = 5004, hiport = 5005; /* from RFC3551 */
416
417                 /* Check transport protocol. */
418                 /* Currently, we only support RTP/AVP over UDP */
419                 if( strncmp( tpt, "RTP/AVP", 7 ) )
420                     continue;
421                 tpt += 7;
422                 if( strncmp( tpt, "/UDP", 4 ) == 0 )
423                     tpt += 4;
424                 if( strchr( ";,", *tpt ) == NULL )
425                     continue;
426
427                 /* Parse transport options */
428                 for( const char *opt = parameter_next( tpt );
429                      opt != NULL;
430                      opt = parameter_next( opt ) )
431                 {
432                     if( strncmp( opt, "multicast", 9 ) == 0)
433                         b_multicast = VLC_TRUE;
434                     else
435                     if( strncmp( opt, "unicast", 7 ) == 0 )
436                         b_multicast = VLC_FALSE;
437                     else
438                     if( sscanf( opt, "client_port=%u-%u", &loport, &hiport )
439                                 == 2 )
440                         ;
441                     else
442                     if( strncmp( opt, "mode=", 5 ) == 0 )
443                     {
444                         if( strncasecmp( opt + 5, "play", 4 )
445                          && strncasecmp( opt + 5, "\"PLAY\"", 6 ) )
446                         {
447                             /* Not playing?! */
448                             b_unsupp = VLC_TRUE;
449                             break;
450                         }
451                     }
452                     else
453                     if( strncmp( opt,"destination=", 12 ) == 0 )
454                     {
455                         answer->i_status = 403;
456                         b_unsupp = VLC_TRUE;
457                     }
458                     else
459                     {
460                     /*
461                      * Every other option is unsupported:
462                      *
463                      * "source" and "append" are invalid (server-only);
464                      * "ssrc" also (as clarified per RFC2326bis).
465                      *
466                      * For multicast, "port", "layers", "ttl" are set by the
467                      * stream output configuration.
468                      *
469                      * For unicast, we want to decide "server_port" values.
470                      *
471                      * "interleaved" is not implemented.
472                      */
473                         b_unsupp = VLC_TRUE;
474                         break;
475                     }
476                 }
477
478                 if( b_unsupp )
479                     continue;
480
481                 if( b_multicast )
482                 {
483                     const char *dst = id->dst;
484                     if( dst == NULL )
485                         continue;
486
487                     if( psz_session == NULL )
488                     {
489                         /* Create a dummy session ID */
490                         snprintf( psz_sesbuf, sizeof( psz_sesbuf ), "%d",
491                                   rand() );
492                         psz_session = psz_sesbuf;
493                     }
494                     answer->i_status = 200;
495
496                     httpd_MsgAdd( answer, "Transport",
497                                   "RTP/AVP/UDP;destination=%s;port=%u-%u;"
498                                   "ttl=%d;mode=play",
499                                   dst, id->loport, id->hiport,
500                                   ( id->ttl > 0 ) ? id->ttl : 1 );
501                 }
502                 else
503                 {
504                     char ip[NI_MAXNUMERICHOST], url[NI_MAXNUMERICHOST + 8];
505                     static const char access[] = "udp{raw,rtcp}";
506                     rtsp_session_t *ses = NULL;
507                     rtsp_strack_t track = { id->sout_id, NULL, VLC_FALSE };
508
509                     if( httpd_ClientIP( cl, ip ) == NULL )
510                     {
511                         answer->i_status = 500;
512                         continue;
513                     }
514
515                     snprintf( url, sizeof( url ),
516                               ( strchr( ip, ':' ) != NULL )
517                                   ? "[%s]:%d" : "%s:%d",
518                               ip, loport );
519
520                     track.access = sout_AccessOutNew( p_stream->p_sout,
521                                                       access, url );
522                     if( track.access == NULL )
523                     {
524                         msg_Err( p_stream,
525                                  "cannot create access output for %s://%s",
526                                  access, url );
527                         answer->i_status = 500;
528                         continue;
529                     }
530
531                     char *src = var_GetNonEmptyString( track.access,
532                                                        "src-addr" );
533                     int sport = var_GetInteger( track.access, "src-port" );
534
535                     vlc_mutex_lock( &rtsp->lock );
536                     if( psz_session == NULL )
537                     {
538                         ses = RtspClientNew( rtsp );
539                         snprintf( psz_sesbuf, sizeof( psz_sesbuf ), I64Fx,
540                                   ses->id );
541                         psz_session = psz_sesbuf;
542                     }
543                     else
544                     {
545                         /* FIXME: we probably need to remove an access out,
546                          * if there is already one for the same ID */
547                         ses = RtspClientGet( rtsp, psz_session );
548                         if( ses == NULL )
549                         {
550                             answer->i_status = 454;
551                             vlc_mutex_unlock( &rtsp->lock );
552                             continue;
553                         }
554                     }
555
556                     INSERT_ELEM( ses->trackv, ses->trackc, ses->trackc,
557                                  track );
558                     vlc_mutex_unlock( &rtsp->lock );
559
560                     httpd_ServerIP( cl, ip );
561
562                     if( ( src != NULL ) && strcmp( src, ip ) )
563                     {
564                         /* Specify source IP if it is different from the RTSP
565                          * control connection server address */
566                         char *ptr = strchr( src, '%' );
567                         if( ptr != NULL ) *ptr = '\0'; /* remove scope ID */
568
569                         httpd_MsgAdd( answer, "Transport",
570                                       "RTP/AVP/UDP;unicast;source=%s;"
571                                       "client_port=%u-%u;server_port=%u-%u;"
572                                       "mode=play",
573                                       src, loport, loport + 1, sport,
574                                       sport + 1 );
575                     }
576                     else
577                     {
578                         httpd_MsgAdd( answer, "Transport",
579                                       "RTP/AVP/UDP;unicast;"
580                                       "client_port=%u-%u;server_port=%u-%u;"
581                                       "mode=play",
582                                       loport, loport + 1, sport, sport + 1 );
583                     }
584
585                     answer->i_status = 200;
586                     free( src );
587                 }
588                 break;
589             }
590             break;
591
592         case HTTPD_MSG_PLAY:
593         {
594             rtsp_session_t *ses;
595             answer->i_status = 200;
596
597             psz_session = httpd_MsgGet( query, "Session" );
598             if( httpd_MsgGet( query, "Range" ) != NULL )
599             {
600                 answer->i_status = 456; /* cannot seek */
601                 break;
602             }
603
604             vlc_mutex_lock( &rtsp->lock );
605             ses = RtspClientGet( rtsp, psz_session );
606             if( ses != NULL )
607             {
608                 for( int i = 0; i < ses->trackc; i++ )
609                 {
610                     rtsp_strack_t *tr = ses->trackv + i;
611                     if( !tr->playing
612                      && ( ( id == NULL ) || ( tr->id == id->sout_id ) ) )
613                     {
614                         tr->playing = VLC_TRUE;
615                         rtp_add_sink( tr->id, tr->access );
616                     }
617                 }
618             }
619             vlc_mutex_unlock( &rtsp->lock );
620
621             if( httpd_MsgGet( query, "Scale" ) != NULL )
622                 httpd_MsgAdd( answer, "Scale", "1." );
623             break;
624         }
625
626         case HTTPD_MSG_PAUSE:
627             answer->i_status = 405;
628             httpd_MsgAdd( answer, "Allow",
629                           "%s, TEARDOWN, PLAY, GET_PARAMETER",
630                           ( id != NULL ) ? "SETUP" : "DESCRIBE" );
631             break;
632
633         case HTTPD_MSG_GETPARAMETER:
634             if( query->i_body > 0 )
635             {
636                 answer->i_status = 451;
637                 break;
638             }
639
640             psz_session = httpd_MsgGet( query, "Session" );
641             answer->i_status = 200;
642             break;
643
644         case HTTPD_MSG_TEARDOWN:
645         {
646             rtsp_session_t *ses;
647
648             answer->i_status = 200;
649
650             psz_session = httpd_MsgGet( query, "Session" );
651
652             vlc_mutex_lock( &rtsp->lock );
653             ses = RtspClientGet( rtsp, psz_session );
654             if( ses != NULL )
655             {
656                 if( id == NULL ) /* Delete the entire session */
657                     RtspClientDel( rtsp, ses );
658                 else /* Delete one track from the session */
659                 for( int i = 0; i < ses->trackc; i++ )
660                 {
661                     if( ses->trackv[i].id == id->sout_id )
662                     {
663                         rtp_del_sink( id->sout_id, ses->trackv[i].access );
664                         sout_AccessOutDelete( ses->trackv[i].access );
665                         REMOVE_ELEM( ses->trackv, ses->trackc, i );
666                     }
667                 }
668             }
669             vlc_mutex_unlock( &rtsp->lock );
670             break;
671         }
672
673         default:
674             return VLC_EGENERIC;
675     }
676
677     httpd_MsgAdd( answer, "Server", "%s", PACKAGE_STRING );
678     if( psz_session )
679         httpd_MsgAdd( answer, "Session", "%s"/*;timeout=5*/, psz_session );
680
681     httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
682     httpd_MsgAdd( answer, "Cache-Control", "no-cache" );
683
684     psz = httpd_MsgGet( query, "Cseq" );
685     if( psz != NULL )
686         httpd_MsgAdd( answer, "Cseq", "%s", psz );
687     psz = httpd_MsgGet( query, "Timestamp" );
688     if( psz != NULL )
689         httpd_MsgAdd( answer, "Timestamp", "%s", psz );
690
691     return VLC_SUCCESS;
692 }
693
694
695 /** Aggregate RTSP callback */
696 static int RtspCallback( httpd_callback_sys_t *p_args,
697                          httpd_client_t *cl,
698                          httpd_message_t *answer,
699                          const httpd_message_t *query )
700 {
701     return RtspHandler( (rtsp_stream_t *)p_args, NULL, cl, answer, query );
702 }
703
704
705 /** Non-aggregate RTSP callback */
706 static int RtspCallbackId( httpd_callback_sys_t *p_args,
707                            httpd_client_t *cl,
708                            httpd_message_t *answer,
709                            const httpd_message_t *query )
710 {
711     rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args;
712     return RtspHandler( id->stream, id, cl, answer, query );
713 }