diff options
Diffstat (limited to 'ext/syck/handler.c')
-rw-r--r-- | ext/syck/handler.c | 81 |
1 files changed, 23 insertions, 58 deletions
diff --git a/ext/syck/handler.c b/ext/syck/handler.c index 50ba3e4232..c54ee0408e 100644 --- a/ext/syck/handler.c +++ b/ext/syck/handler.c @@ -30,7 +30,7 @@ SyckNode * syck_hdlr_add_anchor( SyckParser *p, char *a, SyckNode *n ) { n->anchor = a; - st_insert( p->anchors, (st_data_t)a, (st_data_t)n ); + st_insert( p->anchors, a, n ); return n; } @@ -39,7 +39,7 @@ syck_hdlr_add_alias( SyckParser *p, char *a ) { SyckNode *n; - if ( st_lookup( p->anchors, (st_data_t)a, (st_data_t *)&n ) ) + if ( st_lookup( p->anchors, a, &n ) ) { return n; } @@ -54,76 +54,41 @@ syck_add_transfer( char *uri, SyckNode *n, int taguri ) char *slash = uri; char *domain = NULL; - if ( taguri == 0 ) + if ( n->type_id != NULL ) { - n->type_id = uri; - return; + S_FREE( n->type_id ); } - if ( uri[0] == '!' ) + if ( taguri == 0 ) { - syck_xprivate( n, uri + 1, strlen( uri ) - 1 ); - S_FREE( uri ); + n->type_id = uri; return; } - while ( *(++slash) != '\0' ) - { - if ( *slash == '/' ) - break; - - if ( *slash == ',' ) - comma = slash; - } - - if ( *slash == '\0' ) - { - syck_taguri( n, "yaml.org,2002", uri, strlen( uri ) ); - } - else if ( comma == NULL ) - { - domain = S_ALLOC_N( char, ( slash - uri ) + 15 ); - domain[0] = '\0'; - strncat( domain, uri, slash - uri ); - strcat( domain, ".yaml.org,2002" ); - syck_taguri( n, domain, slash + 1, strlen( uri ) - ( slash - uri + 1 ) ); - S_FREE( domain ); - } - else - { - domain = S_ALLOC_N( char, slash - uri ); - domain[0] = '\0'; - strncat( domain, uri, slash - uri ); - syck_taguri( n, domain, slash + 1, strlen( uri ) - ( slash - uri + 1 ) ); - S_FREE( domain ); - } + n->type_id = syck_type_id_to_uri( uri ); S_FREE( uri ); } -void -syck_xprivate( SyckNode *n, char *type_id, int type_len ) +char * +syck_xprivate( char *type_id, int type_len ) { - if ( n->type_id != NULL ) - S_FREE( n->type_id ); - - n->type_id = S_ALLOC_N( char, type_len + 14 ); - n->type_id[0] = '\0'; - strcat( n->type_id, "x-private:" ); - strncat( n->type_id, type_id, type_len ); + char *uri = S_ALLOC_N( char, type_len + 14 ); + uri[0] = '\0'; + strcat( uri, "x-private:" ); + strncat( uri, type_id, type_len ); + return uri; } -void -syck_taguri( SyckNode *n, char *domain, char *type_id, int type_len ) +char * +syck_taguri( char *domain, char *type_id, int type_len ) { - if ( n->type_id != NULL ) - S_FREE( n->type_id ); - - n->type_id = S_ALLOC_N( char, strlen( domain ) + type_len + 14 ); - n->type_id[0] = '\0'; - strcat( n->type_id, "taguri:" ); - strcat( n->type_id, domain ); - strcat( n->type_id, ":" ); - strncat( n->type_id, type_id, type_len ); + char *uri = S_ALLOC_N( char, strlen( domain ) + type_len + 14 ); + uri[0] = '\0'; + strcat( uri, "taguri:" ); + strcat( uri, domain ); + strcat( uri, ":" ); + strncat( uri, type_id, type_len ); + return uri; } int |