/* *
* $Id: xmlparser.c 22 2004-06-21 14:21:39Z federico $
*
* This file is part of Fenice
*
* Fenice -- Open Media Server
*
* Copyright (C) 2004 by
*
* - Giampaolo Mancini <giampaolo.mancini@polito.it>
* - Francesco Varano <francesco.varano@polito.it>
* - Marco Penno <marco.penno@polito.it>
* - Federico Ridolfo <federico.ridolfo@polito.it>
* - Eugenio Menegatti <m.eu@libero.it>
* - Stefano Cau
* - Giuliano Emma
* - Stefano Oldrini
*
* Fenice 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.
*
* Fenice 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 Fenice; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* *** this file is a modified version taken from xine <http://xinehq.de/> ***
* */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#define LOG_MODULE "xmlparser"
#define LOG_VERBOSE
/*
#define LOG
*/
#include <fenice/xmllexer.h>
#include <fenice/xmlparser.h>
#define TOKEN_SIZE 4 * 1024
#define DATA_SIZE 4 * 1024
#define MAX_RECURSION 10
/* private global variables */
static int xml_parser_mode;
/* private functions */
static char * strtoupper(char * str) {
int i = 0;
while (str[i] != '\0') {
str[i] = (char)toupper((int)str[i]);
i++;
}
return str;
}
static xml_node_t * new_xml_node(void) {
xml_node_t * new_node;
new_node = (xml_node_t*) malloc(sizeof(xml_node_t));
new_node->name = NULL;
new_node->data = NULL;
new_node->props = NULL;
new_node->child = NULL;
new_node->next = NULL;
return new_node;
}
static void free_xml_node(xml_node_t * node) {
if (node->name)
free (node->name);
if (node->data)
free (node->data);
free(node);
}
static xml_property_t * new_xml_property(void) {
xml_property_t * new_property;
new_property = (xml_property_t*) malloc(sizeof(xml_property_t));
new_property->name = NULL;
new_property->value = NULL;
new_property->next = NULL;
return new_property;
}
static void free_xml_property(xml_property_t * property) {
if (property->name)
free (property->name);
if (property->value)
free (property->value);
free(property);
}
void xml_parser_init(char * buf, int size, int mode) {
lexer_init(buf, size);
xml_parser_mode = mode;
}
static void xml_parser_free_props(xml_property_t *current_property) {
if (current_property) {
if (!current_property->next) {
free_xml_property(current_property);
} else {
xml_parser_free_props(current_property->next);
free_xml_property(current_property);
}
}
}
static void xml_parser_free_tree_rec(xml_node_t *current_node, int free_next) {
//lprintf("xml_parser_free_tree_rec: %s\n", current_node->name);
if (current_node) {
/* properties */
if (current_node->props) {
xml_parser_free_props(current_node->props);
}
/* child nodes */
if (current_node->child) {
//lprintf("xml_parser_free_tree_rec: child\n");
xml_parser_free_tree_rec(current_node->child, 1);
}
/* next nodes */
if (free_next) {
xml_node_t *next_node = current_node->next;
xml_node_t *next_next_node;
while (next_node) {
next_next_node = next_node->next;
//lprintf("xml_parser_free_tree_rec: next\n");
xml_parser_free_tree_rec(next_node, 0);
next_node = next_next_node;
}
}
free_xml_node(current_node);
}
}
void xml_parser_free_tree(xml_node_t *current_node) {
//lprintf("xml_parser_free_tree\n");
xml_parser_free_tree_rec(current_node, 1);
}
#define STATE_IDLE 0
#define STATE_NODE 1
#define STATE_COMMENT 7
static int xml_parser_get_node (xml_node_t *current_node, char *root_name, int rec) {
char tok[TOKEN_SIZE];
char property_name[TOKEN_SIZE];
char node_name[TOKEN_SIZE];
int state = STATE_IDLE;
int res = 0;
int parse_res;
int bypass_get_token = 0;
xml_node_t *subtree = NULL;
xml_node_t *current_subtree = NULL;
xml_property_t *current_property = NULL;
xml_property_t *properties = NULL;
if (rec < MAX_RECURSION) {
while ((bypass_get_token) || (res = lexer_get_token(tok, TOKEN_SIZE)) != T_ERROR) {
bypass_get_token = 0;
//lprintf("info: %d - %d : '%s'\n", state, res, tok);
switch (state) {
case STATE_IDLE:
switch (res) {
case (T_EOL):
case (T_SEPAR):
/* do nothing */
break;
case (T_EOF):
return 0; /* normal end */
break;
case (T_M_START_1):
state = STATE_NODE;
break;
case (T_M_START_2):
state = 3;
break;
case (T_C_START):
state = STATE_COMMENT;
break;
case (T_TI_START):
state = 8;
break;
case (T_DOCTYPE_START):
state = 9;
break;
case (T_DATA):
/* current data */
if (current_node->data) {
/* avoid a memory leak */
free(current_node->data);
}
current_node->data = strdup(tok);
//lprintf("info: node data : %s\n", current_node->data);
break;
default:
//lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
return -1;
break;
}
break;
case STATE_NODE:
switch (res) {
case (T_IDENT):
properties = NULL;
current_property = NULL;
/* save node name */
if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) {
strtoupper(tok);
}
strcpy(node_name, tok);
state = 2;
//lprintf("info: current node name \"%s\"\n", node_name);
break;
default:
//lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
return -1;
break;
}
break;
case 2:
switch (res) {
case (T_EOL):
case (T_SEPAR):
/* nothing */
break;
case (T_M_STOP_1):
/* new subtree */
subtree = new_xml_node();
/* set node name */
subtree->name = strdup(node_name);
/* set node propertys */
subtree->props = properties;
//lprintf("info: rec %d new subtree %s\n", rec, node_name);
parse_res = xml_parser_get_node(subtree, node_name, rec + 1);
if (parse_res != 0) {
return parse_res;
}
if (current_subtree == NULL) {
current_node->child = subtree;
current_subtree = subtree;
} else {
current_subtree->next = subtree;
current_subtree = subtree;
}
state = STATE_IDLE;
break;
case (T_M_STOP_2):
/* new leaf */
/* new subtree */
subtree = new_xml_node();
/* set node name */
subtree->name = strdup (node_name);
/* set node propertys */
subtree->props = properties;
//lprintf("info: rec %d new subtree %s\n", rec, node_name);
if (current_subtree == NULL) {
current_node->child = subtree;
current_subtree = subtree;
} else {
current_subtree->next = subtree;
current_subtree = subtree;
}
state = STATE_IDLE;
break;
case (T_IDENT):
/* save property name */
if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) {
strtoupper(tok);
}
strcpy(property_name, tok);
state = 5;
//lprintf("info: current property name \"%s\"\n", property_name);
break;
default:
//lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
return -1;
break;
}
break;
case 3:
switch (res) {
case (T_IDENT):
/* must be equal to root_name */
if (xml_parser_mode == XML_PARSER_CASE_INSENSITIVE) {
strtoupper(tok);
}
if (strcmp(tok, root_name) == 0) {
state = 4;
} else {
//lprintf("error: xml struct, tok=%s, waited_tok=%s\n", tok, root_name);
return -1;
}
break;
default:
//lprintf("error: unexpected token \"%s\", state %d\n", tok, state);
return -1;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
rtsp.rar_RTSP c++_RTSP_C_rtsp协议_rtsp拉流代码_网络协议代码 (271个子文件)
fenice.1 3KB
@fenice_log_file@ 0B
configure.ac 9KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 806B
Makefile.am 645B
Makefile.am 514B
Makefile.am 467B
Makefile.am 419B
Makefile.am 413B
Makefile.am 410B
Makefile.am 406B
Makefile.am 377B
Makefile.am 340B
Makefile.am 300B
Makefile.am 289B
Makefile.am 273B
Makefile.am 223B
Makefile.am 222B
Makefile.am 211B
Makefile.am 210B
Makefile.am 17B
AUTHORS 290B
RTSP_describe.c.bak 3KB
xmlparser.c 13KB
read_MPEG_video.c 11KB
read_MPEGSYSTEM_utils.c 11KB
RTSP_setup.c 11KB
read_MPEG_utils.c 10KB
md5c.c 10KB
parse_SD_file.c 10KB
RTSP_play.c 8KB
read_MPEG4ES_utils.c 8KB
xmllexer.c 8KB
read_MPEG_system.c 7KB
read_MPEG4ES_video.c 7KB
upgrade_MP3.c 7KB
downgrade_MP3.c 7KB
get_SDP_descr.c 7KB
half_MP3.c 6KB
rtsp_server.c 5KB
load_MPA.c 5KB
RTSP_teardown.c 5KB
RTCP_recv_packet.c 5KB
RTCP_send_packet.c 5KB
schedule_do.c 5KB
RTP_send_packet.c 4KB
RTSP_describe.c 4KB
RTSP_state_machine.c 4KB
load_MP4ES.c 4KB
RTSP_msg_len.c 4KB
RTSP_full_msg_rcvd.c 4KB
RTSP_pause.c 4KB
read_H26L.c 4KB
prefs_init.c 4KB
fnc_log.c 4KB
upgrade_GSM.c 4KB
downgrade_GSM.c 4KB
register_media.c 4KB
search_media.c 4KB
validate_stream.c 4KB
schedule_connections.c 3KB
main.c 3KB
read_MP3.c 3KB
read_PCM.c 3KB
OMSbuff_read.c 3KB
half_GSM.c 3KB
read_GSM.c 3KB
parse_url.c 3KB
command_environment.c 3KB
send_setup_reply.c 3KB
eventloop.c 3KB
schedule_start.c 3KB
sock_ntop_host.c 3KB
get_stat.c 3KB
stream_change.c 3KB
RTSP_validate_method.c 3KB
send_redirect_3xx.c 3KB
RTP_session_destroy.c 3KB
send_describe_reply.c 3KB
get_media_descr.c 3KB
send_play_reply.c 2KB
RTCP_handler.c 2KB
enum_media.c 2KB
tcp_connect.c 2KB
load_GSM.c 2KB
RTSP_options.c 2KB
tcp_listen.c 2KB
RTSP_valid_response_msg.c 2KB
send_reply.c 2KB
OMSbuff_write.c 2KB
udp_connect.c 2KB
udp_open.c 2KB
priority_increase.c 2KB
get_address.c 2KB
read_dim.c 2KB
common_utils.c 2KB
schedule_resume.c 2KB
共 271 条
- 1
- 2
- 3
资源评论
- koishi⑤①④2023-07-20这个资源值得下载,资源内容详细全面,与描述一致,受益匪浅。
局外狗
- 粉丝: 64
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功