📄 fdt.c
字号:
if(!(fdt = (fdt_t*)calloc(1, sizeof(fdt_t)))) { printf("Could not alloc memory for fdt!\n"); XML_ParserFree(parser); return NULL; } /* initialise fdt parameters */ fdt->expires = 0; fdt->complete = false; fdt->fec_enc_id = -1; fdt->fec_inst_id = -1; fdt->max_sb_len = 0; fdt->es_len = 0; fdt->max_nb_of_es = 0; fdt->nb_of_files = 0; fdt->type = NULL; fdt->encoding = NULL; file = NULL; prev = NULL; is_first_toi = true; XML_SetStartElementHandler(parser, startElement_FDT); if(XML_Parse(parser, fdt_payload, len, 1) == XML_STATUS_ERROR) { fprintf(stderr, "%s at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser)); XML_ParserFree(parser); return NULL; } XML_ParserFree(parser); return fdt;}/* * This function frees FDT structure * * Params: fdt_t *fdt: Pointer to FDT structure to be freed. * * Return: void * */void FreeFDT(fdt_t *fdt) { file_t *next_file; file_t *file; /**** Free FDT struct ****/ next_file = fdt->file_list; while(next_file != NULL) { file = next_file; if(file->encoding != NULL) { free(file->encoding); } if(file->location != NULL) { free(file->location); } if(file->md5 != NULL) { free(file->md5); } if(file->type != NULL) { free(file->type); } next_file = file->next; free(file); } if(fdt->encoding != NULL) { free(fdt->encoding); } if(fdt->type != NULL) { free(fdt->type); } free(fdt);}/* * This function prints FDT information * * Params: fdt_t *fdt: Pointer to FDT structure to be freed, * int s_id: Session Identifier. * * Return: void * */void PrintFDT(fdt_t *fdt, int s_id) { file_t *next_file; file_t *file; char encoding[5] = "null"; char *enc = encoding; next_file = fdt->file_list; while(next_file != NULL) { file = next_file; if(file->encoding != NULL) { enc = file->encoding; } #ifdef WIN32 printf("URI: %s (TOI=%I64u)\n", file->location, file->toi);#else printf("URI: %s (TOI=%llu)\n", file->location, file->toi);#endif fflush(stdout); next_file = file->next; }}/* * This function frees file structure * * Params: file_t *file: Pointer to file structure to be freed. * * Return: void * */void free_file(file_t *file) { if(file->encoding != NULL) { free(file->encoding); } if(file->location != NULL) { free(file->location); } if(file->md5 != NULL) { free(file->md5); } if(file->type != NULL) { free(file->type); } free(file);}/* * This function copies file description from source to destination. * * Params: file_t *src: Pointer to source file structure, * file_t *dest: Pointer to destination file structure. * * Return: int: 1 if file description is updated, 0 if not, and -1 otherwise * */int copy_file_info(file_t *src, file_t *dest) { int updated = 0; /* Copy only if particular field is not present in destination, so file description can be only complemented not modified */ if(src->toi != 0) { if(dest->toi == 0) { dest->toi = src->toi; updated = 1; } } if(src->expires != 0) { if(dest->expires == 0) { dest->expires = src->expires; updated = 1; } } if(src->toi_len != 0) { if(dest->toi_len == 0) { dest->toi_len = src->toi_len; updated = 1; } } if(src->file_len != 0) { if(dest->file_len == 0) { dest->file_len = src->file_len; updated = 1; } } if(src->fec_enc_id != -1) { if(dest->fec_enc_id == -1) { dest->fec_enc_id = src->fec_enc_id; updated = 1; } } if(src->fec_inst_id != -1) { if(dest->fec_inst_id == -1) { dest->fec_inst_id = src->fec_inst_id; updated = 1; } } if(src->max_sb_len != 0) { if(dest->max_sb_len == 0) { dest->max_sb_len = src->max_sb_len; updated = 1; } } if(src->es_len != 0) { if(dest->es_len == 0) { dest->es_len = src->es_len; updated = 1; } } if(src->max_nb_of_es != 0) { if(dest->max_nb_of_es == 0) { dest->max_nb_of_es = src->max_nb_of_es; updated = 1; } } if(src->location != NULL) { if(dest->location == NULL) { if(!(dest->location = (char*)calloc((strlen(src->location) + 1), sizeof(char)))) { printf("Could not alloc memory for file->location!\n"); return -1; } memcpy(dest->location, src->location, strlen(src->location)); updated = 1; } } if(src->type != NULL) { if(dest->type == NULL) { if(!(dest->type = (char*)calloc((strlen(src->type) + 1), sizeof(char)))) { printf("Could not alloc memory for file->type!\n"); return -1; } memcpy(dest->type, src->type, strlen(src->type)); updated = 1; } } if(src->md5 != NULL) { if(dest->md5 == NULL) { if(!(dest->md5 = (char*)calloc((strlen(src->md5) + 1), sizeof(char)))) { printf("Could not alloc memory for file->md5!\n"); return -1; } memcpy(dest->md5, src->md5, strlen(src->md5)); updated = 1; } } if(src->encoding != NULL) { if(dest->encoding == NULL) { if(!(dest->encoding = (char*)calloc((strlen(src->encoding) + 1), sizeof(char)))) { printf("Could not alloc memory for file->encoding!\n"); return -1; } memcpy(dest->encoding, src->encoding, strlen(src->encoding)); updated = 1; } } return updated;}/* * This function updates FDT database. * * Params: fdt_t *fdt_db: Pointer to FDT database, * fdt_t *instance: Pointer to received FDT Instance. * * Return: int: 1 (existing file description is complemented or 2 (new file description entity) if * FDT database is updated, 0 if not, and -1 otherwise * */int update_fdt(fdt_t *fdt_db, fdt_t *instance) { file_t *tmp_file; file_t *fdt_file; file_t *new_file; int retval = 0; int updated = 0; tmp_file = instance->file_list; while(tmp_file != NULL) { /* Test Print */ /* #ifdef WIN32 printf("TOI:%I64u\n", tmp_file->toi); #else printf("TOI:%llu\n", tmp_file->toi); #endif printf("Content-Location:%s\n", tmp_file->location); printf("Content-Length:%u\n", tmp_file->file_len); printf("Transfer-Length:%u\n", tmp_file->toi_len); printf("Content-Type:%s\n", tmp_file->type); printf("Content-Encoding:%s\n", tmp_file->encoding); printf("Content-MD5:%s\n", tmp_file->md5); printf("FEC-OTI-FEC-Encoding-ID:%u\n", tmp_file->fec_enc_id); printf("FEC-OTI-FEC-Instance-ID:%u\n", tmp_file->fec_inst_id); printf("FEC-OTI-Maximum-Source-Block-Length:%u\n", tmp_file->max_sb_len); printf("FEC-OTI-Encoding-Symbol-Length:%u\n", tmp_file->es_len); printf("FEC-OTI-Max-Number-of-Encoding-Symbols:%u\n", tmp_file->max_nb_of_es); */ fdt_file = fdt_db->file_list; for(;; fdt_file = fdt_file->next) { if(tmp_file->toi == fdt_file->toi) { retval = copy_file_info(tmp_file, fdt_file); if(retval < 0) { return -1; } else if(((retval == 1)&&(updated != 2))) { updated = 1; } break; } else if(fdt_file->next != NULL) { continue; } else { if(!(new_file = (file_t*)calloc(1, sizeof(file_t)))) { printf("Could not alloc memory for mad_fdt file!\n"); return -1; } new_file->fec_enc_id = -1; new_file->fec_inst_id = -1; retval = copy_file_info(tmp_file, new_file); if(retval < 0) { return -1; } else if(retval == 1) { updated = 2; } new_file->next = fdt_file->next; new_file->prev = fdt_file; fdt_file->next = new_file; break; } } tmp_file = tmp_file->next; } return updated;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -