parsedemo.c

A basic SDP descriptions parser based on FreeSDP.

00001 /*
00002   parsedemo - An example on how to use FreeSDP to parse SDP descriptions.
00003   Copyright (C) 2001,2002  Federico Montesino Pouzols <fedemp@altern.org>
00004   
00005   parsedemo is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009   
00010   parsedemo is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU General Public License for more details.
00014   
00015   You should have received a copy of the GNU General Public License
00016   along with this program; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #include <stdio.h>
00021 #include <freesdp/parser.h>
00022 
00023 fsdp_error_t
00024 do_parse(const char *, size_t);
00025 
00030 fsdp_error_t
00031 do_parse(const char *text, size_t len)
00032 {
00033   fsdp_description_t *dsc = NULL;
00034   fsdp_error_t result;
00035   unsigned int i = 0;
00036 
00037   /* Allocate a description object */
00038   dsc = fsdp_description_new();
00039 
00040   /* Parse */
00041   printf(" Starting to parse...\n");
00042   result = fsdp_parse(text,dsc);
00043   
00044   if ( result == FSDPE_OK )
00045     printf(" completed succesfully!\n");
00046   else 
00047     printf(" failed with error code %d: %s.\n",result,fsdp_strerror(result));
00048 
00049   /* Get properties */
00050   printf(" The owner of the session seems to be \"%s\".\n",
00051       fsdp_get_owner_username(dsc));
00052   printf(" The session is called \"%s\"\n",fsdp_get_name(dsc));
00053   printf(" and is described as \"%s\".\n",fsdp_get_information(dsc));
00054   printf(" It consists of %u media streams.\n",fsdp_get_media_count(dsc));
00055 
00056   for (i = 0; i < fsdp_get_media_count(dsc); i++ )
00057     printf(" the media announcement number %d has %d rtpmap attributes\n",
00058         i + 1,
00059         fsdp_get_media_rtpmap_count(fsdp_get_media(dsc,i)));
00060 
00061   printf(" the description has %d unknown session level attributes:\n",
00062       fsdp_get_unidentified_attributes_count(dsc));
00063 
00064   for (i = 0; i < fsdp_get_unidentified_attribute_count(dsc); i++ ) {
00065     printf("   #%d: %s\n",i+1,fsdp_get_unidentified_attribute(dsc,i));
00066   }
00067 
00068   /* Free the new fsdp_description_t object previously allocated */
00069   fsdp_description_delete(dsc);
00070   
00071   /* Return parse error code */
00072   return result;
00073 }
00074 
00075 int main(int argc, char *argv[])
00076 {
00077   const int MAX_SIZE = 5000;
00078   char text[MAX_SIZE], *filename = NULL;
00079   size_t size = MAX_SIZE;
00080   FILE *file = NULL;
00081   fsdp_error_t result;
00082 
00083   if ( argc == 2 ) {
00084     filename = argv[1];
00085   } else {
00086     filename = "rfc-example.sdp";
00087   }
00088 
00089   if ( (file = fopen(filename,"r")) ) {
00090     size = fread(text,1,size,file);
00091     /* Here is where FreeSDP works */
00092     result = do_parse(text,size);
00093     printf("  Parsed a %d octets long SDP description.\n  Result: %d\n",
00094         size,result);
00095     fclose(file);
00096   } else {
00097     printf("Could not open file.\n");
00098   }
00099   return 0;
00100 }

Generated on Wed May 3 13:49:06 2006 for FreeSDP by  doxygen 1.4.6