common.c

Go to the documentation of this file.
00001 /*
00002   This file is part of FreeSDP
00003   Copyright (C) 2001,2002,2003,2004 Federico Montesino Pouzols <fedemp@suidzer0.org>
00004 
00005   FreeSDP is free software; you can redistribute it and/or modify it
00006   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   FreeSDP 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 
00030 #include "priv.h"
00031 #include <freesdp/common.h>
00032 
00033 fsdp_description_t*
00034 fsdp_description_new(void)
00035 {
00036   unsigned int i;
00037   fsdp_description_t *result = malloc(sizeof(fsdp_description_t));
00038   
00039   result->version = 0;
00040   result->o_username = result->o_session_id = 
00041     result->o_announcement_version = NULL; 
00042   result->o_network_type = FSDP_NETWORK_TYPE_UNDEFINED;
00043   result->o_address_type = FSDP_ADDRESS_TYPE_UNDEFINED;
00044   result->o_address = NULL;
00045   result->s_name = NULL;
00046   result->i_information = NULL;
00047   result->u_uri = NULL;
00048   result->emails = NULL;
00049   result->emails_count = 0;
00050   result->phones = NULL;
00051   result->phones_count = 0;
00052   /* At first, there is no session-level definition for these
00053      parameters */
00054   result->c_network_type = FSDP_NETWORK_TYPE_UNDEFINED;
00055   result->c_address_type = FSDP_ADDRESS_TYPE_UNDEFINED;
00056   result->c_address.address = NULL;
00057   /* there is no session-level definition for these parameters */
00058   result->bw_modifiers = NULL;
00059   result->bw_modifiers_count = 0;
00060   result->time_periods = NULL;
00061   result->time_periods_count = 0;
00062   result->timezone_adj = NULL;
00063   result->k_encryption_method = FSDP_ENCRYPTION_METHOD_UNDEFINED;
00064   result->k_encryption_content = NULL;
00065   /* Default/undefined values for attributes */
00066   for ( i = 0; i < (FSDP_LAST_SESSION_STR_ATT + 1); i++ )
00067     result->a_str_attributes[i] = NULL;
00068   result->a_type = FSDP_SESSION_TYPE_UNDEFINED;
00069   result->a_sendrecv_mode = FSDP_SENDRECV_UNDEFINED;
00070   result->a_sdplangs = result->a_langs = NULL;
00071   result->a_rtpmaps = NULL;
00072   result->unidentified_attributes = NULL;
00073   result->unidentified_attributes_count = 0;
00074   result->media_announcements = NULL;
00075   result->media_announcements_count = 0;
00076 
00077   return result;
00078 }
00079 
00080 void
00081 fsdp_description_delete(fsdp_description_t *dsc)
00082 {
00083   fsdp_description_recycle(dsc);
00084   free(dsc);
00085 }
00086 
00087 void fsdp_description_recycle(fsdp_description_t *dsc)
00088 {
00089   /* Recursively free all strings and arrays */
00090   unsigned int i, j;
00091 
00092   if ( NULL == dsc )
00093     return;
00094 
00095   free(dsc->o_username);
00096   free(dsc->o_session_id);
00097   free(dsc->o_announcement_version);
00098   free(dsc->o_address);
00099   free(dsc->s_name);
00100   free(dsc->i_information);
00101   free(dsc->u_uri);
00102 
00103   for ( i = 0; i < dsc->emails_count; i++ )
00104     free((char*)dsc->emails[i]);
00105   free(dsc->emails);
00106        
00107   for ( i = 0; i < dsc->phones_count; i++ )
00108     free((char*)dsc->phones[i]);
00109   free(dsc->phones);
00110 
00111   free(dsc->c_address.address);
00112   for ( i =0; i < dsc->bw_modifiers_count; i++) {    
00113     free(dsc->bw_modifiers[i].b_unknown_bw_modt);
00114   }
00115   free(dsc->bw_modifiers);
00116 
00117   for ( i = 0; i < dsc->time_periods_count; i++ ) {
00118     for ( j = 0; j < dsc->time_periods[i]->repeats_count; j++ ) {
00119       free(dsc->time_periods[i]->repeats[j]->offsets);
00120       free(dsc->time_periods[i]->repeats[j]);
00121     }
00122     free(dsc->time_periods[i]->repeats);
00123     free(dsc->time_periods[i]);
00124   }
00125   free(dsc->time_periods);
00126 
00127 
00128   free(dsc->timezone_adj);
00129   for ( i = 0; i < (FSDP_LAST_SESSION_STR_ATT + 1); i++ )
00130     free(dsc->a_str_attributes[i]);
00131   for ( i = 0; i < dsc->a_rtpmaps_count; i++ )
00132     free(dsc->a_rtpmaps[i]);
00133   free(dsc->a_rtpmaps);
00134   for ( i = 0; i < dsc->a_sdplangs_count; i++ )
00135     free(dsc->a_sdplangs[i]);
00136   free(dsc->a_sdplangs);
00137   for ( i = 0; i < dsc->a_langs_count; i++ )
00138     free(dsc->a_langs[i]);
00139   free(dsc->a_langs);
00140 
00141   for ( i = 0; i < dsc->media_announcements_count; i++ ) {
00142     for ( j = 0; j < dsc->media_announcements[i]->formats_count; j++ )
00143       free(dsc->media_announcements[i]->formats[j]);
00144     free(dsc->media_announcements[i]->formats);
00145     free(dsc->media_announcements[i]->i_title);
00146     /*    free((dsc->media_announcements[i]->c_address).address);*/
00147     for ( j = 0; j < dsc->media_announcements[i]->bw_modifiers_count; j ++ ) {
00148       if ( FSDP_BW_MOD_TYPE_UNKNOWN == 
00149         dsc->media_announcements[i]->bw_modifiers[j].b_mod_type )
00150      free(dsc->media_announcements[i]->bw_modifiers[j].b_unknown_bw_modt);
00151     }
00152     free(dsc->media_announcements[i]->bw_modifiers);
00153     free(dsc->media_announcements[i]->k_encryption_content);
00154     for ( j = 0; j < dsc->media_announcements[i]->a_rtpmaps_count; j++ ) {
00155       free(dsc->media_announcements[i]->a_rtpmaps[j]->pt);
00156       free(dsc->media_announcements[i]->a_rtpmaps[j]->encoding_name);
00157       free(dsc->media_announcements[i]->a_rtpmaps[j]->parameters);
00158       free(dsc->media_announcements[i]->a_rtpmaps[j]);
00159     }
00160     free(dsc->media_announcements[i]->a_rtpmaps);
00161     for ( j = 0; j < dsc->media_announcements[i]->a_sdplangs_count; j++ ) {
00162       free(dsc->media_announcements[i]->a_sdplangs[j]);
00163     }
00164     free(dsc->media_announcements[i]->a_sdplangs);
00165     for ( j = 0; j < dsc->media_announcements[i]->a_langs_count; j++ ) {
00166       free(dsc->media_announcements[i]->a_langs[j]);
00167     }
00168     free(dsc->media_announcements[i]->a_langs);
00169     for ( j = 0; j < dsc->media_announcements[i]->a_fmtps_count; j++ ) {
00170       free(dsc->media_announcements[i]->a_fmtps[j]);
00171     }
00172     free(dsc->media_announcements[i]->a_fmtps);
00173     for ( j = 0; 
00174        j < dsc->media_announcements[i]->unidentified_attributes_count; 
00175        j++ ) {
00176       free(dsc->media_announcements[i]->unidentified_attributes[j]);
00177     }
00178     free(dsc->media_announcements[i]->unidentified_attributes);
00179     free(dsc->media_announcements[i]);
00180   }
00181   free(dsc->media_announcements);   
00182 
00183   /* This prevents the user to make the library crash when incorrectly
00184      using recycled but not rebuilt descriptions */
00185   dsc->emails_count = 0;
00186   dsc->phones_count = 0;
00187   dsc->bw_modifiers_count = 0;
00188   dsc->time_periods_count = 0;
00189   dsc->media_announcements_count = 0;
00190 }

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