fdt.c

Go to the documentation of this file.
00001 
00033 #include <stdlib.h>
00034 #include <stdio.h>
00035 #include <string.h>
00036 #include <errno.h>
00037 #include <assert.h>
00038 
00039 #ifdef _MSC_VER
00040 #include <windows.h>
00041 #else
00042 #include <pthread.h>
00043 #endif
00044 
00045 #include <expat.h>
00046 
00047 #include "../alclib/fec.h"
00048 
00049 #include "fdt.h"
00050 #include "mad_utf8.h"
00051         
00052 fdt_t *fdt;                             
00053 file_t *file;                   
00054 file_t *prev;                   
00055 BOOL is_first_toi;              
00061 #ifdef _MSC_VER
00062 RTL_CRITICAL_SECTION global_variables_semaphore;
00063 #else
00064 pthread_mutex_t global_variables_semaphore = PTHREAD_MUTEX_INITIALIZER;
00065 #endif
00066 
00072 void lock_fdt(void) {
00073 #ifdef _MSC_VER
00074         EnterCriticalSection(&global_variables_semaphore);
00075 #else
00076         pthread_mutex_lock(&global_variables_semaphore);
00077 #endif
00078 }
00079 
00085 void unlock_fdt(void) {
00086 #ifdef _MSC_VER
00087         LeaveCriticalSection(&global_variables_semaphore);
00088 #else
00089         pthread_mutex_unlock(&global_variables_semaphore);
00090 #endif
00091 }
00092 
00103 int copy_file_info(file_t *src, file_t *dest) {
00104 
00105         int updated = 0;
00106 
00107         /* Copy only if particular field is not present in destination, so file description can be only
00108         complemented not modified */
00109 
00110         if(src->toi != 0) {
00111                 if(dest->toi == 0) {
00112                         dest->toi = src->toi;
00113                         updated = 1;
00114                 }
00115         }
00116 
00117         if(src->expires != 0) {
00118                 if(dest->expires == 0) {
00119                         dest->expires = src->expires;
00120                         updated = 1;
00121                 }
00122         }
00123 
00124         if(src->transfer_len != 0) {
00125                 if(dest->transfer_len == 0) {
00126                         dest->transfer_len = src->transfer_len;
00127                         updated = 1;
00128                 }
00129         }
00130 
00131         if(src->content_len != 0) {
00132                 if(dest->content_len == 0) {
00133                         dest->content_len = src->content_len;
00134                         updated = 1;
00135                 }
00136         }
00137 
00138         if(src->fec_enc_id != -1) {
00139                 if(dest->fec_enc_id == -1) {
00140                         dest->fec_enc_id = src->fec_enc_id;
00141                         updated = 1;
00142                 }
00143         }
00144 
00145         if(src->fec_inst_id != -1) {
00146                 if(dest->fec_inst_id == -1) {
00147                         dest->fec_inst_id = src->fec_inst_id;
00148                         updated = 1;
00149                 }
00150         }
00151 
00152         if(src->max_sb_len != 0) {
00153                 if(dest->max_sb_len == 0) {
00154                         dest->max_sb_len = src->max_sb_len;
00155                         updated = 1;
00156                 }
00157         }
00158 
00159         if(src->es_len != 0) {
00160                 if(dest->es_len == 0) {
00161                         dest->es_len = src->es_len;
00162                         updated = 1;
00163                 }
00164         }
00165 
00166         if(src->max_nb_of_es != 0) {
00167                 if(dest->max_nb_of_es == 0) {
00168                         dest->max_nb_of_es = src->max_nb_of_es;
00169                         updated = 1;
00170                 }
00171         }
00172 
00173         if(src->location != NULL) {
00174 
00175                 if(dest->location == NULL) {
00176 
00177                         if(!(dest->location  = (char*)calloc((strlen(src->location) + 1), sizeof(char)))) {
00178                                 printf("Could not alloc memory for file->location!\n");
00179                                 return -1;
00180                         }
00181 
00182                         memcpy(dest->location, src->location, strlen(src->location));
00183                         updated = 1;
00184                 }
00185         }
00186 
00187         if(src->type != NULL) {
00188 
00189                 if(dest->type == NULL) {
00190 
00191                         if(!(dest->type  = (char*)calloc((strlen(src->type) + 1), sizeof(char)))) {
00192                                 printf("Could not alloc memory for file->type!\n");
00193                                 return -1;
00194                         }
00195 
00196                         memcpy(dest->type, src->type, strlen(src->type));
00197                         updated = 1;
00198                 }
00199         }
00200 
00201         if(src->md5 != NULL) {
00202 
00203                 if(dest->md5 == NULL) {
00204 
00205                         if(!(dest->md5 = (char*)calloc((strlen(src->md5) + 1), sizeof(char)))) {
00206                                 printf("Could not alloc memory for file->md5!\n");
00207                                 return -1;
00208                         }
00209 
00210                         memcpy(dest->md5, src->md5, strlen(src->md5));
00211                         updated = 1;
00212                 }
00213         }
00214 
00215         if(src->encoding != NULL) {
00216 
00217                 if(dest->encoding == NULL) {
00218 
00219                         if(!(dest->encoding = (char*)calloc((strlen(src->encoding) + 1), sizeof(char)))) {
00220                                 printf("Could not alloc memory for file->encoding!\n");
00221                                 return -1;
00222                         }
00223 
00224                         memcpy(dest->encoding, src->encoding, strlen(src->encoding));
00225                         updated = 1;
00226                 }
00227         }
00228 
00229         return updated;
00230 }
00231 
00241 static void startElement_FDT(void *userData, const char *name, const char **atts) {
00242 
00243 #ifndef _MSC_VER
00244         char *ep;
00245 #endif
00246 
00247         char *mbstr;
00248 
00249         while(*atts != NULL) {
00250                 if(!strcmp(name, "File")) {
00251 
00252                         if(file == NULL) {
00253                                 if(!(file = (file_t*)calloc(1, sizeof(file_t)))) {
00254                                         printf("Could not alloc memory for mad_fdt file!\n");
00255                                         return;
00256                                 }
00257 
00258                                 /* initialise file parameters */
00259                                 file->prev = NULL;
00260                                 file->next = NULL;
00261                                 file->toi = 0;
00262                                 file->status = 0;
00263                                 file->transfer_len = 0;
00264                                 file->content_len = 0;
00265                                 file->location = NULL;
00266                                 file->md5 = NULL;
00267                                 file->type = NULL;
00268                                 file->encoding = NULL;
00269 
00270                                 file->expires = fdt->expires;
00271 
00272                                 file->fec_enc_id = fdt->fec_enc_id;
00273                                 file->fec_inst_id = fdt->fec_inst_id;
00274                                 file->finite_field = fdt->finite_field;
00275                                 file->nb_of_es_per_group = fdt->nb_of_es_per_group;
00276                                 file->max_sb_len = fdt->max_sb_len;
00277                                 file->es_len = fdt->es_len;
00278                                 file->max_nb_of_es = fdt->max_nb_of_es;
00279 
00280                                 fdt->nb_of_files++;
00281                         }
00282 
00283                         if(!strcmp(*atts, "TOI")) {
00284 
00285 #ifdef _MSC_VER    
00286                                 file->toi = _atoi64(*(++atts));
00287 
00288                                 if(file->toi > (unsigned long long)0xFFFFFFFFFFFFFFFF) {
00289                                         printf("TOI too big for unsigned long long (64 bits)\n");
00290                                         fflush(stdout);
00291                                         return;
00292                                 }
00293 #else               
00294                                 file->toi = strtoull(*(++atts), &ep, 10);
00295 
00296                                 if(*(atts) == '\0' || *ep != '\0') {
00297                                         printf("TOI not a number\n");
00298                                         fflush(stdout);
00299                                         return;
00300                                 }
00301 
00302                                 if(errno == ERANGE && file->toi == 0xFFFFFFFFFFFFFFFFULL) {
00303                                         printf("TOI too big for unsigned long long (64 bits)\n");
00304                                         fflush(stdout);
00305                                         return;
00306                                 }
00307 #endif
00308 
00309                                 if(is_first_toi) {
00310                                         fdt->file_list = file;
00311                                         is_first_toi = FALSE;
00312                                 }
00313                                 else {
00314                                         prev->next = file;
00315                                         file->prev = prev;
00316                                 }
00317 
00318                                 prev = file;
00319                         }
00320                         else if(!strcmp(*atts, "Content-Location")) {
00321 
00322                                 atts++;
00323 
00324                                 if(!(mbstr = (char*)calloc((strlen(*atts)+ 1), sizeof(char)))) {
00325                                         printf("Could not alloc memory for mbstr!\n");
00326                                         return;
00327                                 }
00328 
00329                                 x_utf8s_to_iso_8859_1s(mbstr, *atts, strlen(*atts));
00330 
00331                                 if(!(file->location = (char*)calloc((size_t)(strlen(mbstr) + 1), sizeof(char)))) {
00332                                         printf("Could not alloc memory for file->location!\n");
00333                                         return;
00334                                 }
00335 
00336                                 memcpy(file->location, mbstr, strlen(mbstr));
00337                                 free(mbstr);
00338 
00339                         }
00340                         else if(!strcmp(*atts, "Content-Length")) {
00341 
00342 #ifdef _MSC_VER     
00343                                 file->content_len = _atoi64(*(++atts));
00344 
00345                                 if(file->content_len > (unsigned long long)0xFFFFFFFFFFFFFFFF) {
00346                                         printf("Content-Length too big for unsigned long long (64 bits)\n");
00347                                         fflush(stdout);
00348                                         return;
00349                                 }
00350 #else               
00351                                 file->content_len = strtoull(*(++atts), &ep, 10);
00352 
00353                                 if(*(atts) == '\0' || *ep != '\0') {
00354                                         printf("Content-Length not a number\n");
00355                                         fflush(stdout);
00356                                         return;
00357                                 }
00358 
00359                                 if(errno == ERANGE && file->content_len == 0xFFFFFFFFFFFFFFFFULL) {
00360                                         printf("Content-Length too big for unsigned long long (64 bits)\n");
00361                                         fflush(stdout);
00362                                         return;
00363                                 }       
00364 #endif
00365                                 if(file->transfer_len == 0) {
00366                                         file->transfer_len = file->content_len;
00367                                 }
00368                         }
00369                         else if(!strcmp(*atts, "Transfer-Length")) {
00370 
00371 #ifdef _MSC_VER                   
00372                                 file->transfer_len = _atoi64(*(++atts));
00373 
00374                                 if(file->transfer_len > (unsigned long long)0xFFFFFFFFFFFFFFFF) {
00375                                         printf("Transfer-Length too big for unsigned long long (64 bits)\n");
00376                                         fflush(stdout);
00377                                         return;
00378                                 }
00379 #else
00380                                 file->transfer_len = strtoull(*(++atts), &ep, 10);
00381 
00382                                 if(*(atts) == '\0' || *ep != '\0') {
00383                                         printf("Transfer-Length not a number\n");
00384                                         fflush(stdout);
00385                                         return;
00386                                 }
00387 
00388                                 if(errno == ERANGE && file->transfer_len == 0xFFFFFFFFFFFFFFFFULL) {
00389                                         printf("Transfer-Length too big for unsigned long long (64 bits)\n");
00390                                         fflush(stdout);
00391                                         return;
00392                                 }
00393 #endif 
00394 
00395 #ifdef _MSC_VER
00396                                 if(file->transfer_len > (unsigned long long)0xFFFFFFFFFFFF) {
00397                                         printf("Transfer-Length too big (max=%I64u)\n", (unsigned long long)0xFFFFFFFFFFFF);
00398 #else
00399                                 if(file->transfer_len > 0xFFFFFFFFFFFFULL) {
00400                                         printf("Transfer-Length too big (max=%llu)\n", 0xFFFFFFFFFFFFULL);
00401 #endif
00402                                         fflush(stdout);
00403                                         return;
00404                                 }
00405                         }
00406                         else if(!strcmp(*atts, "Content-Type")) {
00407 
00408                                 atts++;
00409 
00410                                 if(!(file->type = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {
00411                                         printf("Could not alloc memory for file->type!\n");
00412                                         return;
00413                                 }
00414 
00415                                 memcpy(file->type, *atts, strlen(*atts));
00416                         }
00417                         else if(!strcmp(*atts, "Content-Encoding")) {
00418 
00419                                 atts++;
00420 
00421                                 if(!(file->encoding = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {
00422                                         printf("Could not alloc memory for file->encoding!\n");
00423                                         return;
00424                                 }
00425 
00426                                 memcpy(file->encoding, *atts, strlen(*atts));
00427                         }
00428                         else if(!strcmp(*atts, "Content-MD5")) {
00429 
00430                                 atts++;
00431 
00432                                 if(!(file->md5 = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {
00433                                         printf("Could not alloc memory for file->md5!\n");
00434                                         return;
00435                                 }
00436 
00437                                 memcpy(file->md5, *atts, strlen(*atts));
00438                         }
00439                         else if(!strcmp(*atts, "FEC-OTI-FEC-Encoding-ID")) {
00440                                 file->fec_enc_id = (unsigned char)atoi(*(++atts));
00441                         }
00442                         else if(!strcmp(*atts, "FEC-OTI-FEC-Instance-ID")) {
00443                                 file->fec_inst_id = (unsigned short)atoi(*(++atts));
00444                         }
00445                         else if(!strcmp(*atts, "FEC-OTI-Maximum-Source-Block-Length")) {
00446                                 file->max_sb_len = (unsigned int)atoi(*(++atts));
00447                         }
00448                         else if(!strcmp(*atts, "FEC-OTI-Encoding-Symbol-Length")) {
00449                                 file->es_len = (unsigned short)atoi(*(++atts));
00450                         }
00451                         else if(!strcmp(*atts, "FEC-OTI-Max-Number-of-Encoding-Symbols")) {
00452                                 file->max_nb_of_es = (unsigned short)atoi(*(++atts));
00453                         }
00454                         else if(!strcmp(*atts, "FEC-OTI-Number-of-Encoding-Symbols-per-Group")) {
00455                                 file->nb_of_es_per_group = (unsigned char)atoi(*(++atts));
00456                         }
00457                         else if(!strcmp(*atts, "FEC-OTI-Finite-Field-Parameter")) {
00458                                 file->finite_field = (unsigned char)atoi(*(++atts));
00459                         }
00460                         else {                    
00461                                 atts++;
00462                         }
00463 
00464                         atts++;
00465 
00466                         /* copy common parameters from FDT to File when we are leaving File element */
00467 
00468                         if(*atts == NULL) {
00469 
00470                                 if(file->type == NULL && fdt->type != NULL) {
00471                                         if(!(file->type = (char*)calloc((strlen(fdt->type) + 1), sizeof(char)))) {
00472                                                 printf("Could not alloc memory for file->type!\n");
00473                                                 return;
00474                                         }
00475                                         memcpy(file->type, fdt->type, strlen(fdt->type));
00476                                 }
00477                                 if(file->encoding == NULL && fdt->encoding != NULL) {
00478                                         if(!(file->encoding = (char*)calloc((strlen(fdt->encoding) + 1), sizeof(char)))) {
00479                                                 printf("Could not alloc memory for file->encoding!\n");
00480                                                 return;
00481                                         }
00482                                         memcpy(file->encoding, fdt->encoding, strlen(fdt->encoding));
00483                                 }
00484                         }
00485 
00486                 }
00487                 else if(!strcmp(name, "FDT-Instance")) {
00488 
00489                         if(!strcmp(*atts, "Expires")) {  
00490 #ifdef _MSC_VER
00491                                 fdt->expires = _atoi64(*(++atts));
00492 
00493                                 if(fdt->expires > (unsigned long long)0xFFFFFFFFFFFFFFFF) {
00494                                         printf("Expires too big for unsigned long long (64 bits)\n");
00495                                         fflush(stdout);
00496                                         return;
00497                                 }
00498 #else
00499                                 /*fdt->expires = atoll(*(++atts));*/
00500 
00501                                 fdt->expires = strtoull(*(++atts), &ep, 10);
00502 
00503                                 if(*(atts) == '\0' || *ep != '\0') {
00504                                         printf("Expires not a number\n");
00505                                         fflush(stdout);
00506                                         return;
00507                                 }
00508 
00509                                 if(errno == ERANGE && fdt->expires == 0xFFFFFFFFFFFFFFFFULL) {
00510                                         printf("Expires too big for unsigned long long (64 bits)\n");
00511                                         fflush(stdout);
00512                                         return;
00513                                 }
00514 #endif
00515                         }
00516                         else if(!strcmp(*atts, "Complete")) {
00517                                 if(!strcmp("true", *(++atts))) {
00518                                         fdt->complete = TRUE;
00519                                 }
00520                                 else {
00521                                         fdt->complete = FALSE;
00522                                 }
00523                         }
00524                         else if(!strcmp(*atts, "FEC-OTI-FEC-Encoding-ID")) {
00525                                 fdt->fec_enc_id = (unsigned char)atoi(*(++atts));
00526                         }
00527                         else if(!strcmp(*atts, "FEC-OTI-FEC-Instance-ID")) {
00528                                 fdt->fec_inst_id = (unsigned short)atoi(*(++atts));
00529                         }
00530                         else if(!strcmp(*atts, "FEC-OTI-Maximum-Source-Block-Length")) {
00531                                 fdt->max_sb_len = (unsigned int)atoi(*(++atts));
00532                         }
00533                         else if(!strcmp(*atts, "FEC-OTI-Encoding-Symbol-Length")) {
00534                                 fdt->es_len = (unsigned short)atoi(*(++atts));
00535                         }
00536                         else if(!strcmp(*atts, "FEC-OTI-Max-Number-of-Encoding-Symbols")) {
00537                                 fdt->max_nb_of_es = (unsigned short)atoi(*(++atts));
00538                         }
00539                         else if(!strcmp(*atts, "FEC-OTI-Number-of-Encoding-Symbols-per-Group")) {
00540                                 fdt->nb_of_es_per_group = (unsigned char)atoi(*(++atts));
00541                         }
00542                         else if(!strcmp(*atts, "FEC-OTI-Finite-Field-Parameter")) {
00543                                 fdt->finite_field = (unsigned char)atoi(*(++atts));
00544                         }
00545                         else if(!strcmp(*atts, "Content-Type")) {
00546                                 atts++;
00547 
00548                                 if(!(fdt->type = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {
00549                                         printf("Could not alloc memory for fdt->type!\n");
00550                                         return;
00551                                 }
00552 
00553                                 memcpy(fdt->type, *atts, strlen(*atts));
00554                         }
00555                         else if(!strcmp(*atts, "Content-Encoding")) {
00556                                 atts++;
00557 
00558                                 if(!(fdt->encoding = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {
00559                                         printf("Could not alloc memory for fdt->encoding!\n");
00560                                         return;
00561                                 }
00562 
00563                                 memcpy(fdt->encoding, *atts, strlen(*atts));
00564                         }
00565                         else {
00566                                 atts++;
00567                         }
00568                         atts++;
00569                 }
00570                 else {
00571                         atts += 2;
00572                 }
00573         }
00574 
00575         file = NULL;
00576 }
00577 
00578 void initialize_fdt_parser(void) {
00579 #ifdef _MSC_VER
00580   InitializeCriticalSection(&global_variables_semaphore);
00581 #else
00582 #endif
00583 }
00584 
00585 void release_fdt_parser(void) {
00586 #ifdef _MSC_VER
00587   DeleteCriticalSection(&global_variables_semaphore);
00588 #else
00589 #endif
00590 }
00591 
00592 fdt_t* decode_fdt_payload(char *fdt_payload) {
00593 
00594         XML_Parser parser;
00595         size_t len;
00596 
00597         lock_fdt();
00598 
00599         parser = XML_ParserCreate(NULL);
00600         /* parser = XML_ParserCreate("iso-8859-1"); */
00601 
00602         len = strlen(fdt_payload);
00603         fdt = NULL;
00604 
00605         if(!(fdt = (fdt_t*)calloc(1, sizeof(fdt_t)))) {
00606                 printf("Could not alloc memory for fdt!\n");
00607                 XML_ParserFree(parser);
00608                 unlock_fdt();
00609                 return NULL;
00610         }
00611 
00612         /* initialise fdt parameters */
00613 
00614         fdt->expires = 0;
00615         fdt->complete = FALSE;
00616         fdt->fec_enc_id = -1;
00617         fdt->fec_inst_id = -1;
00618         fdt->finite_field = GF_BITS;
00619         fdt->nb_of_es_per_group = 1;
00620         fdt->max_sb_len = 0;
00621         fdt->es_len = 0;
00622         fdt->max_nb_of_es = 0;
00623         fdt->nb_of_files = 0;
00624         fdt->type = NULL;
00625         fdt->encoding = NULL;
00626         fdt->file_list = NULL;  
00627 
00628         file = NULL;
00629         prev = NULL;
00630         is_first_toi = TRUE;
00631 
00632         XML_SetStartElementHandler(parser, startElement_FDT);
00633 
00634         if(XML_Parse(parser, fdt_payload, len, 1) == XML_STATUS_ERROR) {
00635                 fprintf(stderr, "%s at line %d\n",
00636                         XML_ErrorString(XML_GetErrorCode(parser)),
00637                         XML_GetCurrentLineNumber(parser));
00638                 XML_ParserFree(parser);
00639                 unlock_fdt();
00640                 return NULL;
00641         }
00642 
00643         XML_ParserFree(parser);
00644         unlock_fdt();
00645         return fdt;
00646 }
00647 
00648 void FreeFDT(fdt_t *fdt) {
00649 
00650         file_t *next_file;
00651         file_t *file;
00652 
00653         lock_fdt();
00654 
00655         /**** Free FDT struct ****/
00656 
00657         next_file = fdt->file_list;
00658 
00659         while(next_file != NULL) {
00660                 file = next_file;
00661 
00662                 if(file->encoding != NULL) {
00663                         free(file->encoding);
00664                 }
00665 
00666                 if(file->location != NULL) {
00667                         free(file->location);
00668                 }
00669 
00670                 if(file->md5 != NULL) {
00671                         free(file->md5);
00672                 }
00673 
00674                 if(file->type != NULL) {
00675                         free(file->type);
00676                 }
00677 
00678                 next_file = file->next;
00679                 free(file);
00680         }
00681 
00682         if(fdt->encoding != NULL) {
00683                 free(fdt->encoding);
00684         }
00685         if(fdt->type != NULL) {
00686                 free(fdt->type);
00687         }
00688 
00689         free(fdt);
00690         unlock_fdt();
00691 }
00692 
00693 int update_fdt(fdt_t *fdt_db, fdt_t *instance) {
00694 
00695         file_t *tmp_file;
00696         file_t *fdt_file;
00697         file_t *new_file;
00698         int retval = 0;
00699         int updated = 0;
00700 
00701         assert (fdt_db != NULL);
00702         assert (instance != NULL);
00703 
00704         lock_fdt();
00705 
00706         tmp_file = instance->file_list;
00707 
00708         while(tmp_file != NULL) {
00709 
00710                 fdt_file = fdt_db->file_list;
00711 
00712                 for(;; fdt_file = fdt_file->next) {
00713 
00714                         if(tmp_file->toi == fdt_file->toi) {
00715 
00716                                 retval = copy_file_info(tmp_file, fdt_file);
00717 
00718                                 if(retval < 0) {
00719                                         unlock_fdt();
00720                                         return -1;
00721                                 }
00722                                 else if(((retval == 1)&&(updated != 2))) {
00723                                         updated = 1;
00724                                 }
00725 
00726                                 break;
00727                         }
00728                         else if(fdt_file->next != NULL) {
00729                                 continue;
00730                         }
00731                         else {
00732 
00733                                 if(!(new_file = (file_t*)calloc(1, sizeof(file_t)))) {
00734                                         printf("Could not alloc memory for mad_fdt file!\n");
00735                                         unlock_fdt();
00736                                         return -1;
00737                                 }
00738 
00739                                 new_file->fec_enc_id = -1;
00740                                 new_file->fec_inst_id = -1;
00741 
00742                                 retval = copy_file_info(tmp_file, new_file);
00743 
00744                                 if(retval < 0) {
00745                                         unlock_fdt();
00746                                         return -1;
00747                                 }
00748                                 else if(retval == 1) {
00749                                         updated = 2;
00750                                 }
00751 
00752                                 new_file->next = fdt_file->next;
00753                                 new_file->prev = fdt_file;
00754                                 fdt_file->next = new_file;
00755 
00756                                 break;
00757                         }
00758                 }
00759 
00760                 tmp_file = tmp_file->next;
00761         }
00762         unlock_fdt();
00763         return updated;
00764 }
00765 
00766 file_t* find_file_with_toi(fdt_t *fdt, unsigned long long toi) {
00767     file_t* file = fdt->file_list;
00768 
00769     while(file != NULL) {
00770                 if(file->toi == toi) {
00771                         return file;
00772         }
00773 
00774         file = file->next;
00775     }
00776 
00777     return NULL;
00778 }
00779 
00780 void PrintFDT(fdt_t *fdt, int s_id) {
00781 
00782         file_t *next_file;
00783         file_t *file;
00784         char encoding[5] = "null"; 
00785         char *enc = encoding;
00786 
00787         lock_fdt();
00788 
00789         next_file = fdt->file_list;
00790 
00791         while(next_file != NULL) {      
00792                 file = next_file;
00793 
00794                 if(file->encoding != NULL) {
00795                         enc = file->encoding;
00796                 }
00797 
00798 #ifdef _MSC_VER
00799                 printf("URI: %s (TOI=%I64u)\n",  file->location, file->toi);
00800 #else
00801                 printf("URI: %s (TOI=%llu)\n",  file->location, file->toi);
00802 #endif
00803                 fflush(stdout);
00804 
00805                 next_file = file->next;
00806         }
00807         unlock_fdt();
00808 }
00809 
00810 void free_file(file_t *file) {
00811 
00812         lock_fdt();
00813 
00814         if(file->encoding != NULL) {
00815                 free(file->encoding);
00816         }
00817 
00818         if(file->location != NULL) {
00819                 free(file->location);
00820         }
00821 
00822         if(file->md5 != NULL) {
00823                 free(file->md5);
00824         }
00825 
00826         if(file->type != NULL) {
00827                 free(file->type);
00828         }
00829 
00830         free(file);
00831         unlock_fdt();
00832 }

Generated on Fri Mar 9 19:59:53 2007 for MAD-FCL by  doxygen 1.5.0