⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fdt.c

📁 这个程序实现了FLUTE协议
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Author: peltotal $ $Date: 2006/02/17 08:07:16 $ $Revision: 1.5 $ *//* *   MAD-FLUTELIB: Implementation of FLUTE protocol. *   Copyright (c) 2003-2006 TUT - Tampere University of Technology *   main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi * *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "flute_inc.h"/* Global variables */fdt_t *fdt;file_t *file;file_t *prev;bool is_first_toi;/* Private function */int copy_file_info(file_t *src, file_t *dest);/* * This function parses FDT XML document to fdt structure. * * Params:	void *userData: Not used, *			const char *name: Pointer to buffer containing element name, *			const char **atts: Pointer to buffer containing element's attributes. * * Return:	static void * */static void startElement_FDT(void *userData, const char *name, const char **atts) {#ifndef WIN32  char *ep;#endif  int errno;  char *mbstr;  while(*atts != NULL) {        if(!strcmp(name, "File")) {            if(file == NULL) {			if(!(file = (file_t*)calloc(1, sizeof(file_t)))) {			printf("Could not alloc memory for mad_fdt file!\n");			return;		}			/* initialise file parameters */		file->prev = NULL;		file->next = NULL;		file->toi = 0;		file->is_downloaded = 0;		file->toi_len = 0;		file->file_len = 0;		file->location = NULL;		file->md5 = NULL;		file->type = NULL;		file->encoding = NULL;				file->expires = fdt->expires;		file->fec_enc_id = fdt->fec_enc_id;		file->fec_inst_id = fdt->fec_inst_id;		file->max_sb_len = fdt->max_sb_len;		file->es_len = fdt->es_len;		file->max_nb_of_es = fdt->max_nb_of_es;		fdt->nb_of_files++;      }      if(!strcmp(*atts, "TOI")) {	#ifdef WIN32    	file->toi = _atoi64(*(++atts));		if(file->toi > (ULONGLONG)0xFFFFFFFFFFFFFFFF) {	  printf("TOI too big for unsigned long long (64 bits)\n");	  fflush(stdout);	  return;	}#else               	file->toi = strtoull(*(++atts), &ep, 10);		if(*(atts) == '\0' || *ep != '\0') {	  printf("TOI not a number\n");	  fflush(stdout);	  return;	}		if(errno == ERANGE && file->toi == 0xFFFFFFFFFFFFFFFFULL) {	  printf("TOI too big for unsigned long long (64 bits)\n");	  fflush(stdout);	  return;	}#endif	if(is_first_toi) {	  fdt->file_list = file;	  is_first_toi = false;	}	else {	  prev->next = file;	  file->prev = prev;	}		prev = file;      }      else if(!strcmp(*atts, "Content-Location")) {		atts++;        if(!(mbstr = (char*)calloc((strlen(*atts)+ 1), sizeof(char)))) {          printf("Could not alloc memory for mbstr!\n");          return;        }	x_utf8s_to_iso_8859_1s(mbstr, *atts, strlen(*atts)); 	if(!(file->location = (char*)calloc((size_t)(strlen(mbstr) + 1), sizeof(char)))) {	  printf("Could not alloc memory for file->location!\n");	  return;	}	memcpy(file->location, mbstr, strlen(mbstr));	free(mbstr);      }      else if(!strcmp(*atts, "Content-Length")) {	#ifdef WIN32     	file->file_len = _atoi64(*(++atts));		if(file->file_len > (ULONGLONG)0xFFFFFFFFFFFFFFFF) {	  printf("Content-Length too big for unsigned long long (64 bits)\n");	  fflush(stdout);	  return;	}#else               	/*file->file_len = atoll(*(++atts));*/		file->file_len = strtoull(*(++atts), &ep, 10);		if(*(atts) == '\0' || *ep != '\0') {	  printf("Content-Length not a number\n");	  fflush(stdout);	  return;	}		if(errno == ERANGE && file->file_len == 0xFFFFFFFFFFFFFFFFULL) {	  printf("Content-Length too big for unsigned long long (64 bits)\n");	  fflush(stdout);	  return;	}	#endif	if(file->toi_len == 0) {	  file->toi_len = file->file_len;	}      }      else if(!strcmp(*atts, "Transfer-Length")) {	#ifdef WIN32			  	file->toi_len = _atoi64(*(++atts));		if(file->toi_len > (ULONGLONG)0xFFFFFFFFFFFFFFFF) {	  printf("Transfer-Length too big for unsigned long long (64 bits)\n");	  fflush(stdout);	  return;	}#else	/*file->toi_len = atoll(*(++atts));*/		file->toi_len = strtoull(*(++atts), &ep, 10);		if(*(atts) == '\0' || *ep != '\0') {	  printf("Transfer-Length not a number\n");	  fflush(stdout);	  return;	}		if(errno == ERANGE && file->toi_len == 0xFFFFFFFFFFFFFFFFULL) {	  printf("Transfer-Length too big for unsigned long long (64 bits)\n");	  fflush(stdout);	  return;	}#endif 	#ifdef WIN32	if(file->toi_len > (ULONGLONG)0xFFFFFFFFFFFF) {	  printf("Transfer-Length too big (max=%I64u)\n", (ULONGLONG)0xFFFFFFFFFFFF);#else	if(file->toi_len > 0xFFFFFFFFFFFFULL) {	  printf("Transfer-Length too big (max=%llu)\n", 0xFFFFFFFFFFFFULL);#endif	  fflush(stdout);	  return;	}	}	else if(!strcmp(*atts, "Content-Type")) {	  	  atts++;	  	  if(!(file->type = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {	    printf("Could not alloc memory for file->type!\n");	    return;	  }	  	  memcpy(file->type, *atts, strlen(*atts));	}	else if(!strcmp(*atts, "Content-Encoding")) {	  	  atts++;	  	  if(!(file->encoding = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {	    printf("Could not alloc memory for file->encoding!\n");	    return;	  }	  	  memcpy(file->encoding, *atts, strlen(*atts));	}	else if(!strcmp(*atts, "Content-MD5")) {	  	  atts++;	  	  if(!(file->md5 = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {	    printf("Could not alloc memory for file->md5!\n");	    return;	  }	  	  memcpy(file->md5, *atts, strlen(*atts));	}	else if(!strcmp(*atts, "FEC-OTI-FEC-Encoding-ID")) {	  file->fec_enc_id = (unsigned char)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-FEC-Instance-ID")) {	  file->fec_inst_id = (unsigned short)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-Maximum-Source-Block-Length")) {	  file->max_sb_len = (unsigned int)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-Encoding-Symbol-Length")) {	  file->es_len = (unsigned short)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-Max-Number-of-Encoding-Symbols")) {	  file->max_nb_of_es = (unsigned short)atoi(*(++atts));	}	else {			  	  atts++;	}		atts++;	/* copy common parameters from FDT to File when we are leaving File element */	if(*atts == NULL) {		if(file->type == NULL && fdt->type != NULL) {			if(!(file->type = (char*)calloc((strlen(fdt->type) + 1), sizeof(char)))) {				printf("Could not alloc memory for file->type!\n");				return;			}			memcpy(file->type, fdt->type, strlen(fdt->type));		}		if(file->encoding == NULL && fdt->encoding != NULL) {			if(!(file->encoding = (char*)calloc((strlen(fdt->encoding) + 1), sizeof(char)))) {				printf("Could not alloc memory for file->encoding!\n");				return;			}			memcpy(file->encoding, fdt->encoding, strlen(fdt->encoding));		}	}      }      else if(!strcmp(name, "FDT-Instance")) {		if(!strcmp(*atts, "Expires")) {  #ifdef WIN32	  fdt->expires = _atoi64(*(++atts));	  	  if(fdt->expires > (ULONGLONG)0xFFFFFFFFFFFFFFFF) {	    printf("Expires too big for unsigned long long (64 bits)\n");	    fflush(stdout);	    return;	  }#else	  /*fdt->expires = atoll(*(++atts));*/	  	  fdt->expires = strtoull(*(++atts), &ep, 10);	  	  if(*(atts) == '\0' || *ep != '\0') {	    printf("Expires not a number\n");	    fflush(stdout);	    return;	  }	  	  if(errno == ERANGE && fdt->expires == 0xFFFFFFFFFFFFFFFFULL) {	    printf("Expires too big for unsigned long long (64 bits)\n");	    fflush(stdout);	    return;	  }#endif	}	else if(!strcmp(*atts, "Complete")) {	  if(!strcmp("true", *(++atts))) {	    fdt->complete = true;	  }	  else {	    fdt->complete = false;	  }	}	else if(!strcmp(*atts, "FEC-OTI-FEC-Encoding-ID")) {	  fdt->fec_enc_id = (unsigned char)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-FEC-Instance-ID")) {	  fdt->fec_inst_id = (unsigned short)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-Maximum-Source-Block-Length")) {	  fdt->max_sb_len = (unsigned int)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-Encoding-Symbol-Length")) {	  fdt->es_len = (unsigned short)atoi(*(++atts));	}	else if(!strcmp(*atts, "FEC-OTI-Max-Number-of-Encoding-Symbols")) {	  fdt->max_nb_of_es = (unsigned short)atoi(*(++atts));	}	else if(!strcmp(*atts, "Content-Type")) {	  atts++;	  	  if(!(fdt->type = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {	    printf("Could not alloc memory for fdt->type!\n");	    return;	  }	  	  memcpy(fdt->type, *atts, strlen(*atts));	}	else if(!strcmp(*atts, "Content-Encoding")) {	  atts++;	  	  if(!(fdt->encoding = (char*)calloc((strlen(*atts) + 1), sizeof(char)))) {	    printf("Could not alloc memory for fdt->encoding!\n");	    return;	  }	  	  memcpy(fdt->encoding, *atts, strlen(*atts));	}	else {	  atts++;	}	atts++;      }      else {	atts += 2;      }    }        file = NULL;    /*iconv_close(iconv);*/  }/* * This function decodes FDT XML document to fdt structure by using Expat XML library. * * Params:	char *fdt_payload: Pointer to buffer containing FDT XML document. * * Return:	fdt_t*: Pointer to fdt structure. * */fdt_t* decode_fdt_payload(char *fdt_payload) {  XML_Parser parser = XML_ParserCreate(NULL);  /* XML_Parser parser = XML_ParserCreate("iso-8859-1"); */    size_t len = strlen(fdt_payload);  fdt = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -