2003-05-13 02:34:18 -04:00
|
|
|
/*
|
2003-08-19 12:38:02 -04:00
|
|
|
* handler.c
|
2003-05-13 02:34:18 -04:00
|
|
|
*
|
|
|
|
* $Author$
|
|
|
|
* $Date$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 why the lucky stiff
|
|
|
|
*/
|
2003-05-09 17:25:50 -04:00
|
|
|
|
|
|
|
#include "syck.h"
|
2003-07-28 15:27:42 -04:00
|
|
|
#include "ruby.h"
|
2003-05-09 17:25:50 -04:00
|
|
|
|
|
|
|
SYMID
|
|
|
|
syck_hdlr_add_node( SyckParser *p, SyckNode *n )
|
|
|
|
{
|
|
|
|
SYMID id;
|
2003-05-29 19:33:10 -04:00
|
|
|
|
2003-05-09 17:25:50 -04:00
|
|
|
if ( ! n->id )
|
|
|
|
{
|
|
|
|
n->id = (p->handler)( p, n );
|
|
|
|
}
|
|
|
|
id = n->id;
|
|
|
|
|
|
|
|
if ( n->anchor == NULL )
|
|
|
|
{
|
|
|
|
syck_free_node( n );
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyckNode *
|
|
|
|
syck_hdlr_add_anchor( SyckParser *p, char *a, SyckNode *n )
|
|
|
|
{
|
|
|
|
n->anchor = a;
|
2003-06-17 12:55:54 -04:00
|
|
|
if ( p->bad_anchors != NULL )
|
|
|
|
{
|
|
|
|
SyckNode *bad;
|
|
|
|
if ( st_lookup( p->bad_anchors, (st_data_t)a, (st_data_t *)&bad ) )
|
|
|
|
{
|
|
|
|
if ( n->kind != syck_str_kind )
|
|
|
|
{
|
|
|
|
n->id = bad->id;
|
|
|
|
(p->handler)( p, n );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-06-05 00:43:05 -04:00
|
|
|
if ( p->anchors == NULL )
|
|
|
|
{
|
|
|
|
p->anchors = st_init_strtable();
|
|
|
|
}
|
2003-05-13 07:41:19 -04:00
|
|
|
st_insert( p->anchors, (st_data_t)a, (st_data_t)n );
|
2003-05-09 17:25:50 -04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2003-06-17 12:55:54 -04:00
|
|
|
void
|
|
|
|
syck_hdlr_remove_anchor( SyckParser *p, char *a )
|
|
|
|
{
|
|
|
|
if ( p->anchors == NULL )
|
|
|
|
{
|
|
|
|
p->anchors = st_init_strtable();
|
|
|
|
}
|
|
|
|
st_insert( p->anchors, (st_data_t)a, (st_data_t)1 );
|
|
|
|
}
|
|
|
|
|
2003-05-09 17:25:50 -04:00
|
|
|
SyckNode *
|
2003-06-17 12:55:54 -04:00
|
|
|
syck_hdlr_get_anchor( SyckParser *p, char *a )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-06-17 12:55:54 -04:00
|
|
|
SyckNode *n = NULL;
|
2003-05-09 17:25:50 -04:00
|
|
|
|
2003-06-05 00:43:05 -04:00
|
|
|
if ( p->anchors != NULL )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-06-17 12:55:54 -04:00
|
|
|
if ( st_lookup( p->anchors, (st_data_t)a, (st_data_t *)&n ) )
|
|
|
|
{
|
|
|
|
if ( n != (void *)1 )
|
|
|
|
{
|
2003-08-19 12:38:02 -04:00
|
|
|
S_FREE( a );
|
2003-06-17 12:55:54 -04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( p->bad_anchors == NULL )
|
|
|
|
{
|
|
|
|
p->bad_anchors = st_init_strtable();
|
|
|
|
}
|
|
|
|
if ( ! st_lookup( p->bad_anchors, (st_data_t)a, (st_data_t *)&n ) )
|
|
|
|
{
|
|
|
|
n = (p->bad_anchor_handler)( p, a );
|
|
|
|
st_insert( p->bad_anchors, (st_data_t)a, (st_data_t)n );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-06-17 12:55:54 -04:00
|
|
|
if ( n == NULL )
|
|
|
|
{
|
|
|
|
n = (p->bad_anchor_handler)( p, a );
|
|
|
|
}
|
2003-08-19 12:38:02 -04:00
|
|
|
|
|
|
|
if ( n->anchor )
|
|
|
|
{
|
|
|
|
S_FREE( a );
|
2003-10-14 19:15:19 -04:00
|
|
|
}
|
2003-08-19 12:38:02 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
n->anchor = a;
|
|
|
|
}
|
|
|
|
|
2003-06-17 12:55:54 -04:00
|
|
|
return n;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
syck_add_transfer( char *uri, SyckNode *n, int taguri )
|
|
|
|
{
|
2003-05-10 15:55:18 -04:00
|
|
|
if ( n->type_id != NULL )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-05-10 15:55:18 -04:00
|
|
|
S_FREE( n->type_id );
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-05-10 15:55:18 -04:00
|
|
|
if ( taguri == 0 )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-05-10 15:55:18 -04:00
|
|
|
n->type_id = uri;
|
2003-05-09 17:25:50 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-10 15:55:18 -04:00
|
|
|
n->type_id = syck_type_id_to_uri( uri );
|
2003-05-09 17:25:50 -04:00
|
|
|
S_FREE( uri );
|
|
|
|
}
|
|
|
|
|
2003-05-10 15:55:18 -04:00
|
|
|
char *
|
|
|
|
syck_xprivate( char *type_id, int type_len )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-05-10 15:55:18 -04:00
|
|
|
char *uri = S_ALLOC_N( char, type_len + 14 );
|
|
|
|
uri[0] = '\0';
|
|
|
|
strcat( uri, "x-private:" );
|
|
|
|
strncat( uri, type_id, type_len );
|
|
|
|
return uri;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
2003-05-10 15:55:18 -04:00
|
|
|
char *
|
|
|
|
syck_taguri( char *domain, char *type_id, int type_len )
|
2003-05-09 17:25:50 -04:00
|
|
|
{
|
2003-05-10 15:55:18 -04:00
|
|
|
char *uri = S_ALLOC_N( char, strlen( domain ) + type_len + 14 );
|
|
|
|
uri[0] = '\0';
|
2003-10-14 19:15:19 -04:00
|
|
|
strcat( uri, "tag:" );
|
2003-05-10 15:55:18 -04:00
|
|
|
strcat( uri, domain );
|
|
|
|
strcat( uri, ":" );
|
|
|
|
strncat( uri, type_id, type_len );
|
|
|
|
return uri;
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
syck_try_implicit( SyckNode *n )
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|