sdplib.c

Go to the documentation of this file.
00001 
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 
00037 #include "sdplib.h"
00038 
00039 char* sdp_attr_get(sdp_message_t *sdp, char *attr_name) {
00040         osip_list_t *list;
00041         __node_t *node;
00042         sdp_attribute_t *attr;
00043         int size;
00044         int i;
00045 
00046         list = sdp->a_attributes;
00047         size = osip_list_size(list);
00048 
00049         if(size == 0) {
00050                 return NULL;
00051         }
00052 
00053         node = list->node;
00054         attr = (sdp_attribute_t*)node->element;
00055     
00056         for(i = 0; i < size; i++) {
00057                 
00058                 if(strcmp(attr_name, attr->a_att_field) == 0) {
00059                         return attr->a_att_value;       
00060                 }
00061                 if(i < size - 1) {
00062                         node = (__node_t*)node->next;                   
00063                         attr = (sdp_attribute_t*)node->element;
00064                 }
00065         }
00066         return NULL;
00067 }
00068 
00069 sf_t* sf_char2struct(char *src_filt) {
00070         sf_t *sf;
00071         char *buf;
00072         
00073         if(!(sf = (sf_t*)calloc(1, sizeof(sf_t)))) {
00074                 printf("Could not alloc memory for source filter structure!\n");
00075                 return NULL;
00076         }
00077 
00078         buf = strtok(src_filt, " ");
00079 
00080         sf->filter_mode = (char*)calloc(1, strlen(buf)+1);
00081         strcpy(sf->filter_mode, buf);
00082 
00083         buf = strtok(NULL, " ");
00084         
00085         sf->net_type = (char*)calloc(1, strlen(buf)+1);
00086         strcpy(sf->net_type, buf);
00087 
00088         buf = strtok(NULL, " ");
00089         
00090         sf->addr_type = (char*)calloc(1, strlen(buf)+1);
00091         strcpy(sf->addr_type, buf);
00092 
00093         buf = strtok(NULL, " ");
00094         
00095         sf->dest_addr = (char*)calloc(1, strlen(buf)+1);
00096         strcpy(sf->dest_addr, buf);
00097 
00098         buf = strtok(NULL, " ");
00099         
00100         sf->src_addr = (char*)calloc(1, strlen(buf)+1);
00101         strcpy(sf->src_addr, buf);
00102 
00103         return sf;
00104 }
00105 
00106 void sf_free(sf_t *sf) {
00107 
00108         if(sf == NULL) {
00109           return;
00110         }
00111         free(sf->filter_mode);
00112         free(sf->net_type);
00113         free(sf->addr_type);
00114         free(sf->dest_addr);
00115         free(sf->src_addr);
00116 }
00117 
00118 fec_dec_t* sdp_fec_dec_get(sdp_message_t *sdp) {
00119         osip_list_t *list;
00120         __node_t *node;
00121         sdp_attribute_t *attr;
00122         int size;
00123         int i;
00124         fec_dec_t *fec_dec = NULL;
00125         fec_dec_t *current = NULL;
00126         fec_dec_t *prev = NULL;
00127 
00128         list = sdp->a_attributes;
00129         size = osip_list_size(list);
00130 
00131         if(size == 0) {
00132           return NULL;
00133         }
00134 
00135         node = list->node;
00136         attr = (sdp_attribute_t*)node->element;
00137     
00138         for(i = 0; i < size; i++) {
00139                 
00140                 if(strcmp(attr->a_att_field, "FEC-declaration") == 0) {
00141 
00142                         current = fec_dec_char2struct(attr->a_att_value);
00143 
00144                         if(current == NULL) {
00145                                 fec_dec_free(fec_dec);
00146                                 return NULL;
00147                         }
00148 
00149                         if(prev == NULL) {
00150                                 fec_dec = current;
00151                                 prev = current;
00152                         }
00153                         else {
00154                                 prev->next = current;
00155                                 prev = current;
00156                         }
00157                 }
00158 
00159                 if(i < size - 1) {
00160                         node = (__node_t*)node->next;                   
00161                         attr = (sdp_attribute_t*)node->element;
00162                 }
00163         }
00164 
00165         return fec_dec;
00166 }
00167 
00168 fec_dec_t* fec_dec_char2struct(char *fec_dec) {
00169         fec_dec_t *fec_d;
00170         char *buf;
00171         
00172         if(!(fec_d = (fec_dec_t*)calloc(1, sizeof(fec_dec_t)))) {
00173                 printf("Could not alloc memory for FEC-declaration structure!\n");
00174                 return NULL;
00175         }
00176 
00177         buf = strtok(fec_dec, " ");
00178 
00179         fec_d->index = atoi(buf);
00180 
00181         buf = strtok(NULL, "=");
00182         buf = strtok(NULL, ";");
00183 
00184         fec_d->fec_enc_id = (short)atoi(buf);
00185 
00186         buf = strtok(NULL, "=");
00187         buf = strtok(NULL, " ");
00188 
00189         if(buf != NULL) {
00190                 fec_d->fec_inst_id = atoi(buf);
00191         }
00192         else {
00193                 fec_d->fec_inst_id = 0;
00194         }
00195 
00196         fec_d->next = NULL;
00197         
00198         return fec_d;
00199 }
00200 
00201 void fec_dec_free(fec_dec_t *fec_dec) {
00202 
00203         fec_dec_t *current;
00204         fec_dec_t *next;
00205 
00206         if(fec_dec == NULL) {
00207                 return;
00208         }
00209 
00210         current = fec_dec;
00211 
00212         while(current->next != NULL) {
00213                 next = current->next;
00214                 free(current);
00215                 current = next;
00216         }
00217 }

Generated on Fri Mar 9 20:08:53 2007 for MAD-FCL by  doxygen 1.5.0