3 * Web service library with GLib integration
5 * Copyright (C) 2009-2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <sys/socket.h>
33 #include <arpa/inet.h>
36 #include "giognutls.h"
40 #define DEFAULT_BUFFER_SIZE 2048
42 #define SESSION_FLAG_USE_TLS (1 << 0)
67 struct addrinfo *addr;
71 GIOChannel *transport_channel;
72 guint transport_watch;
78 guint8 *receive_buffer;
81 GString *current_header;
85 gboolean request_started;
87 enum chunk_state chunck_state;
94 GWebResultFunc result_func;
95 GWebInputFunc input_func;
113 char *user_agent_profile;
115 gboolean close_connection;
117 GWebDebugFunc debug_func;
121 static inline void debug(GWeb *web, const char *format, ...)
126 if (web->debug_func == NULL)
129 va_start(ap, format);
131 if (vsnprintf(str, sizeof(str), format, ap) > 0)
132 web->debug_func(str, web->debug_data);
137 static void free_session(struct web_session *session)
139 GWeb *web = session->web;
144 g_free(session->request);
146 if (session->resolv_action > 0)
147 g_resolv_cancel_lookup(web->resolv, session->resolv_action);
149 if (session->transport_watch > 0)
150 g_source_remove(session->transport_watch);
152 if (session->send_watch > 0)
153 g_source_remove(session->send_watch);
155 if (session->transport_channel != NULL)
156 g_io_channel_unref(session->transport_channel);
158 g_free(session->result.last_key);
160 if (session->result.headers != NULL)
161 g_hash_table_destroy(session->result.headers);
163 if (session->send_buffer != NULL)
164 g_string_free(session->send_buffer, TRUE);
166 if (session->current_header != NULL)
167 g_string_free(session->current_header, TRUE);
169 g_free(session->receive_buffer);
171 g_free(session->content_type);
173 g_free(session->host);
174 g_free(session->address);
175 if (session->addr != NULL)
176 freeaddrinfo(session->addr);
181 static void flush_sessions(GWeb *web)
185 for (list = g_list_first(web->session_list);
186 list; list = g_list_next(list))
187 free_session(list->data);
189 g_list_free(web->session_list);
190 web->session_list = NULL;
193 GWeb *g_web_new(int index)
200 web = g_try_new0(GWeb, 1);
206 web->next_query_id = 1;
208 web->family = AF_UNSPEC;
211 web->session_list = NULL;
213 web->resolv = g_resolv_new(index);
214 if (web->resolv == NULL) {
219 web->accept_option = g_strdup("*/*");
220 web->user_agent = g_strdup_printf("GWeb/%s", VERSION);
221 web->close_connection = FALSE;
226 GWeb *g_web_ref(GWeb *web)
231 g_atomic_int_inc(&web->ref_count);
236 void g_web_unref(GWeb *web)
241 if (g_atomic_int_dec_and_test(&web->ref_count) == FALSE)
246 g_resolv_unref(web->resolv);
250 g_free(web->accept_option);
251 g_free(web->user_agent);
252 g_free(web->user_agent_profile);
253 g_free(web->http_version);
258 void g_web_set_debug(GWeb *web, GWebDebugFunc func, gpointer user_data)
263 web->debug_func = func;
264 web->debug_data = user_data;
266 g_resolv_set_debug(web->resolv, func, user_data);
269 gboolean g_web_set_proxy(GWeb *web, const char *proxy)
278 debug(web, "clearing proxy");
280 web->proxy = g_strdup(proxy);
281 debug(web, "setting proxy %s", web->proxy);
287 gboolean g_web_set_address_family(GWeb *web, int family)
292 if (family != AF_UNSPEC && family != AF_INET && family != AF_INET6)
295 web->family = family;
300 gboolean g_web_add_nameserver(GWeb *web, const char *address)
305 g_resolv_add_nameserver(web->resolv, address, 53, 0);
310 static gboolean set_accept_option(GWeb *web, const char *format, va_list args)
312 g_free(web->accept_option);
314 if (format == NULL) {
315 web->accept_option = NULL;
316 debug(web, "clearing accept option");
318 web->accept_option = g_strdup_vprintf(format, args);
319 debug(web, "setting accept %s", web->accept_option);
325 gboolean g_web_set_accept(GWeb *web, const char *format, ...)
333 va_start(args, format);
334 result = set_accept_option(web, format, args);
340 static gboolean set_user_agent(GWeb *web, const char *format, va_list args)
342 g_free(web->user_agent);
344 if (format == NULL) {
345 web->user_agent = NULL;
346 debug(web, "clearing user agent");
348 web->user_agent = g_strdup_vprintf(format, args);
349 debug(web, "setting user agent %s", web->user_agent);
355 gboolean g_web_set_user_agent(GWeb *web, const char *format, ...)
363 va_start(args, format);
364 result = set_user_agent(web, format, args);
370 gboolean g_web_set_ua_profile(GWeb *web, const char *profile)
375 g_free(web->user_agent_profile);
377 web->user_agent_profile = g_strdup(profile);
378 debug(web, "setting user agent profile %s", web->user_agent);
383 gboolean g_web_set_http_version(GWeb *web, const char *version)
388 g_free(web->http_version);
390 if (version == NULL) {
391 web->http_version = NULL;
392 debug(web, "clearing HTTP version");
394 web->http_version = g_strdup(version);
395 debug(web, "setting HTTP version %s", web->http_version);
401 void g_web_set_close_connection(GWeb *web, gboolean enabled)
406 web->close_connection = enabled;
409 gboolean g_web_get_close_connection(GWeb *web)
414 return web->close_connection;
417 static inline void call_result_func(struct web_session *session, guint16 status)
421 if (session->result_func == NULL)
425 session->result.status = status;
427 result = session->result_func(&session->result, session->user_data);
429 debug(session->web, "[result function] %s",
430 result == TRUE ? "continue" : "stop");
433 static gboolean process_send_buffer(struct web_session *session)
435 GString *buf = session->send_buffer;
436 gsize count, bytes_written;
442 if (session->request_started == TRUE &&
443 session->more_data == FALSE)
444 session->body_done = TRUE;
449 status = g_io_channel_write_chars(session->transport_channel,
450 buf->str, count, &bytes_written, NULL);
452 debug(session->web, "status %u bytes to write %zu bytes written %zu",
453 status, count, bytes_written);
455 if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
458 g_string_erase(buf, 0, bytes_written);
463 static void process_next_chunk(struct web_session *session)
465 GString *buf = session->send_buffer;
469 if (session->input_func == NULL) {
470 session->more_data = FALSE;
474 session->more_data = session->input_func(&body, &length,
478 g_string_append_printf(buf, "%zx\r\n", length);
479 g_string_append_len(buf, (char *) body, length);
480 g_string_append(buf, "\r\n");
483 if (session->more_data == FALSE)
484 g_string_append(buf, "0\r\n\r\n");
487 static void start_request(struct web_session *session)
489 GString *buf = session->send_buffer;
494 debug(session->web, "request %s from %s",
495 session->request, session->host);
497 g_string_truncate(buf, 0);
499 if (session->web->http_version == NULL)
502 version = session->web->http_version;
504 if (session->content_type == NULL)
505 g_string_append_printf(buf, "GET %s HTTP/%s\r\n",
506 session->request, version);
508 g_string_append_printf(buf, "POST %s HTTP/%s\r\n",
509 session->request, version);
511 g_string_append_printf(buf, "Host: %s\r\n", session->host);
513 if (session->web->user_agent != NULL)
514 g_string_append_printf(buf, "User-Agent: %s\r\n",
515 session->web->user_agent);
517 if (session->web->user_agent_profile != NULL) {
518 g_string_append_printf(buf, "x-wap-profile: %s\r\n",
519 session->web->user_agent_profile);
522 if (session->web->accept_option != NULL)
523 g_string_append_printf(buf, "Accept: %s\r\n",
524 session->web->accept_option);
526 if (session->content_type != NULL) {
527 g_string_append_printf(buf, "Content-Type: %s\r\n",
528 session->content_type);
529 if (session->input_func == NULL) {
530 session->more_data = FALSE;
533 session->more_data = session->input_func(&body, &length,
535 if (session->more_data == FALSE)
536 g_string_append_printf(buf, "Content-Length: %zu\r\n",
539 g_string_append(buf, "Transfer-Encoding: chunked\r\n");
542 if (session->web->close_connection == TRUE)
543 g_string_append(buf, "Connection: close\r\n");
545 g_string_append(buf, "\r\n");
547 if (session->content_type != NULL && length > 0) {
548 if (session->more_data == TRUE) {
549 g_string_append_printf(buf, "%zx\r\n", length);
550 g_string_append_len(buf, (char *) body, length);
551 g_string_append(buf, "\r\n");
553 g_string_append_len(buf, (char *) body, length);
557 static gboolean send_data(GIOChannel *channel, GIOCondition cond,
560 struct web_session *session = user_data;
562 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
563 session->send_watch = 0;
567 if (process_send_buffer(session) == TRUE)
570 if (session->request_started == FALSE) {
571 session->request_started = TRUE;
572 start_request(session);
573 } else if (session->more_data == TRUE)
574 process_next_chunk(session);
576 process_send_buffer(session);
578 if (session->body_done == TRUE) {
579 session->send_watch = 0;
586 static int decode_chunked(struct web_session *session,
587 const guint8 *buf, gsize len)
589 const guint8 *ptr = buf;
597 switch (session->chunck_state) {
599 pos = memchr(ptr, '\n', len);
601 g_string_append_len(session->current_header,
607 if (count < 1 || ptr[count - 1] != '\r')
610 g_string_append_len(session->current_header,
611 (gchar *) ptr, count);
616 str = session->current_header->str;
618 counter = strtoul(str, NULL, 16);
619 if ((counter == 0 && errno == EINVAL) ||
620 counter == ULONG_MAX)
623 session->chunk_size = counter;
624 session->chunk_left = counter;
626 session->chunck_state = CHUNK_DATA;
633 session->chunck_state = CHUNK_N_BODY;
640 session->chunck_state = CHUNK_SIZE;
643 if (session->chunk_size == 0) {
644 debug(session->web, "Download Done in chunk");
645 g_string_truncate(session->current_header, 0);
649 if (session->chunk_left <= len) {
650 session->result.buffer = ptr;
651 session->result.length = session->chunk_left;
652 call_result_func(session, 0);
654 len -= session->chunk_left;
655 ptr += session->chunk_left;
657 session->total_len += session->chunk_left;
658 session->chunk_left = 0;
660 g_string_truncate(session->current_header, 0);
661 session->chunck_state = CHUNK_R_BODY;
665 session->result.buffer = ptr;
666 session->result.length = len;
667 call_result_func(session, 0);
669 session->chunk_left -= len;
670 session->total_len += len;
681 static int handle_body(struct web_session *session,
682 const guint8 *buf, gsize len)
686 debug(session->web, "[body] length %zu", len);
688 if (session->result.use_chunk == FALSE) {
690 session->result.buffer = buf;
691 session->result.length = len;
692 call_result_func(session, 0);
697 err = decode_chunked(session, buf, len);
699 debug(session->web, "Error in chunk decode %d", err);
701 session->result.buffer = NULL;
702 session->result.length = 0;
703 call_result_func(session, 400);
709 static void handle_multi_line(struct web_session *session)
715 str = session->current_header->str;
717 if (str[0] != ' ' && str[0] != '\t')
720 while (str[0] == ' ' || str[0] == '\t')
723 count = str - session->current_header->str;
725 g_string_erase(session->current_header, 0, count);
726 g_string_insert_c(session->current_header, 0, ' ');
729 value = g_hash_table_lookup(session->result.headers,
730 session->result.last_key);
732 g_string_insert(session->current_header, 0, value);
734 str = session->current_header->str;
736 g_hash_table_replace(session->result.headers,
737 g_strdup(session->result.last_key),
742 static void add_header_field(struct web_session *session)
750 str = session->current_header->str;
752 pos = memchr(str, ':', session->current_header->len);
759 /* remove preceding white spaces */
763 count = (char *) pos - str;
765 g_string_erase(session->current_header, 0, count);
767 value = g_hash_table_lookup(session->result.headers, key);
769 g_string_insert_c(session->current_header, 0, ' ');
770 g_string_insert_c(session->current_header, 0, ';');
772 g_string_insert(session->current_header, 0, value);
775 str = session->current_header->str;
776 g_hash_table_replace(session->result.headers, key,
779 g_free(session->result.last_key);
780 session->result.last_key = g_strdup(key);
784 static gboolean received_data(GIOChannel *channel, GIOCondition cond,
787 struct web_session *session = user_data;
788 guint8 *ptr = session->receive_buffer;
792 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
793 session->transport_watch = 0;
794 session->result.buffer = NULL;
795 session->result.length = 0;
796 call_result_func(session, 400);
800 status = g_io_channel_read_chars(channel,
801 (gchar *) session->receive_buffer,
802 session->receive_space - 1, &bytes_read, NULL);
804 debug(session->web, "bytes read %zu", bytes_read);
806 if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN) {
807 session->transport_watch = 0;
808 session->result.buffer = NULL;
809 session->result.length = 0;
810 call_result_func(session, 0);
814 session->receive_buffer[bytes_read] = '\0';
816 if (session->header_done == TRUE) {
817 if (handle_body(session, session->receive_buffer,
819 session->transport_watch = 0;
825 while (bytes_read > 0) {
830 pos = memchr(ptr, '\n', bytes_read);
832 g_string_append_len(session->current_header,
833 (gchar *) ptr, bytes_read);
838 count = strlen((char *) ptr);
839 if (count > 0 && ptr[count - 1] == '\r') {
844 g_string_append_len(session->current_header,
845 (gchar *) ptr, count);
847 bytes_read -= count + 1;
853 if (session->current_header->len == 0) {
856 session->header_done = TRUE;
858 val = g_hash_table_lookup(session->result.headers,
859 "Transfer-Encoding");
861 val = g_strrstr(val, "chunked");
863 session->result.use_chunk = TRUE;
865 session->chunck_state = CHUNK_SIZE;
866 session->chunk_left = 0;
867 session->total_len = 0;
871 if (handle_body(session, ptr, bytes_read) < 0) {
872 session->transport_watch = 0;
878 str = session->current_header->str;
880 if (session->result.status == 0) {
883 if (sscanf(str, "HTTP/%*s %u %*s", &code) == 1)
884 session->result.status = code;
887 debug(session->web, "[header] %s", str);
889 /* handle multi-line header */
890 if (str[0] == ' ' || str[0] == '\t')
891 handle_multi_line(session);
893 add_header_field(session);
895 g_string_truncate(session->current_header, 0);
901 static int connect_session_transport(struct web_session *session)
906 sk = socket(session->addr->ai_family, SOCK_STREAM, IPPROTO_TCP);
910 if (session->flags & SESSION_FLAG_USE_TLS) {
911 debug(session->web, "using TLS encryption");
912 session->transport_channel = g_io_channel_gnutls_new(sk);
914 debug(session->web, "no encryption");
915 session->transport_channel = g_io_channel_unix_new(sk);
918 if (session->transport_channel == NULL) {
923 flags = g_io_channel_get_flags(session->transport_channel);
924 g_io_channel_set_flags(session->transport_channel,
925 flags | G_IO_FLAG_NONBLOCK, NULL);
927 g_io_channel_set_encoding(session->transport_channel, NULL, NULL);
928 g_io_channel_set_buffered(session->transport_channel, FALSE);
930 g_io_channel_set_close_on_unref(session->transport_channel, TRUE);
932 if (connect(sk, session->addr->ai_addr,
933 session->addr->ai_addrlen) < 0) {
934 if (errno != EINPROGRESS) {
940 session->transport_watch = g_io_add_watch(session->transport_channel,
941 G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
942 received_data, session);
944 session->send_watch = g_io_add_watch(session->transport_channel,
945 G_IO_OUT | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
951 static int create_transport(struct web_session *session)
955 err = connect_session_transport(session);
959 debug(session->web, "creating session %s:%u",
960 session->address, session->port);
965 static int parse_url(struct web_session *session,
966 const char *url, const char *proxy)
968 char *scheme, *host, *port, *path;
970 scheme = g_strdup(url);
974 host = strstr(scheme, "://");
979 if (strcasecmp(scheme, "https") == 0) {
981 session->flags |= SESSION_FLAG_USE_TLS;
982 } else if (strcasecmp(scheme, "http") == 0) {
993 path = strchr(host, '/');
998 session->request = g_strdup_printf("/%s", path ? path : "");
1000 session->request = g_strdup(url);
1002 port = strrchr(host, ':');
1005 int tmp = strtol(port + 1, &end, 10);
1009 session->port = tmp;
1013 session->host = g_strdup(host);
1015 session->host = g_strdup_printf("%s:%u", host, tmp);
1017 session->host = g_strdup(host);
1024 scheme = g_strdup(proxy);
1028 host = strstr(proxy, "://");
1033 if (strcasecmp(scheme, "http") != 0) {
1040 path = strchr(host, '/');
1044 port = strrchr(host, ':');
1047 int tmp = strtol(port + 1, &end, 10);
1051 session->port = tmp;
1055 session->address = g_strdup(host);
1062 static void resolv_result(GResolvResultStatus status,
1063 char **results, gpointer user_data)
1065 struct web_session *session = user_data;
1066 struct addrinfo hints;
1070 if (results == NULL || results[0] == NULL) {
1071 call_result_func(session, 404);
1075 debug(session->web, "address %s", results[0]);
1077 memset(&hints, 0, sizeof(struct addrinfo));
1078 hints.ai_flags = AI_NUMERICHOST;
1079 hints.ai_family = session->web->family;
1081 if (session->addr != NULL) {
1082 freeaddrinfo(session->addr);
1083 session->addr = NULL;
1086 port = g_strdup_printf("%u", session->port);
1087 ret = getaddrinfo(results[0], port, &hints, &session->addr);
1089 if (ret != 0 || session->addr == NULL) {
1090 call_result_func(session, 400);
1094 session->address = g_strdup(results[0]);
1096 if (create_transport(session) < 0) {
1097 call_result_func(session, 409);
1102 static guint do_request(GWeb *web, const char *url,
1103 const char *type, GWebInputFunc input,
1104 GWebResultFunc func, gpointer user_data)
1106 struct web_session *session;
1108 if (web == NULL || url == NULL)
1111 debug(web, "request %s", url);
1113 session = g_try_new0(struct web_session, 1);
1114 if (session == NULL)
1117 if (parse_url(session, url, web->proxy) < 0) {
1118 free_session(session);
1122 debug(web, "address %s", session->address);
1123 debug(web, "port %u", session->port);
1124 debug(web, "host %s", session->host);
1125 debug(web, "flags %lu", session->flags);
1126 debug(web, "request %s", session->request);
1129 session->content_type = g_strdup(type);
1131 debug(web, "content-type %s", session->content_type);
1136 session->result_func = func;
1137 session->input_func = input;
1138 session->user_data = user_data;
1140 session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE);
1141 if (session->receive_buffer == NULL) {
1142 free_session(session);
1146 session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal,
1148 if (session->result.headers == NULL) {
1149 free_session(session);
1153 session->receive_space = DEFAULT_BUFFER_SIZE;
1154 session->send_buffer = g_string_sized_new(0);
1155 session->current_header = g_string_sized_new(0);
1156 session->header_done = FALSE;
1157 session->body_done = FALSE;
1159 if (session->address == NULL && inet_aton(session->host, NULL) == 0) {
1160 session->resolv_action = g_resolv_lookup_hostname(web->resolv,
1161 session->host, resolv_result, session);
1162 if (session->resolv_action == 0) {
1163 free_session(session);
1167 struct addrinfo hints;
1171 if (session->address == NULL)
1172 session->address = g_strdup(session->host);
1174 memset(&hints, 0, sizeof(struct addrinfo));
1175 hints.ai_flags = AI_NUMERICHOST;
1176 hints.ai_family = session->web->family;
1178 if (session->addr != NULL) {
1179 freeaddrinfo(session->addr);
1180 session->addr = NULL;
1183 port = g_strdup_printf("%u", session->port);
1184 ret = getaddrinfo(session->address, port, &hints,
1187 if (ret != 0 || session->addr == NULL) {
1188 free_session(session);
1192 if (create_transport(session) < 0) {
1193 free_session(session);
1198 web->session_list = g_list_append(web->session_list, session);
1200 return web->next_query_id++;
1203 guint g_web_request_get(GWeb *web, const char *url,
1204 GWebResultFunc func, gpointer user_data)
1206 return do_request(web, url, NULL, NULL, func, user_data);
1209 guint g_web_request_post(GWeb *web, const char *url,
1210 const char *type, GWebInputFunc input,
1211 GWebResultFunc func, gpointer user_data)
1213 return do_request(web, url, type, input, func, user_data);
1216 gboolean g_web_cancel_request(GWeb *web, guint id)
1224 guint16 g_web_result_get_status(GWebResult *result)
1229 return result->status;
1232 gboolean g_web_result_get_chunk(GWebResult *result,
1233 const guint8 **chunk, gsize *length)
1241 *chunk = result->buffer;
1244 *length = result->length;
1249 gboolean g_web_result_get_header(GWebResult *result,
1250 const char *header, const char **value)
1258 *value = g_hash_table_lookup(result->headers, header);
1266 struct _GWebParser {
1270 const char *token_str;
1275 GWebParserFunc func;
1279 GWebParser *g_web_parser_new(const char *begin, const char *end,
1280 GWebParserFunc func, gpointer user_data)
1284 parser = g_try_new0(GWebParser, 1);
1288 parser->ref_count = 1;
1290 parser->begin_token = g_strdup(begin);
1291 parser->end_token = g_strdup(end);
1293 if (parser->begin_token == NULL) {
1298 parser->func = func;
1299 parser->user_data = user_data;
1301 parser->token_str = parser->begin_token;
1302 parser->token_len = strlen(parser->token_str);
1303 parser->token_pos = 0;
1305 parser->intoken = FALSE;
1306 parser->content = g_string_sized_new(0);
1311 GWebParser *g_web_parser_ref(GWebParser *parser)
1316 g_atomic_int_inc(&parser->ref_count);
1321 void g_web_parser_unref(GWebParser *parser)
1326 if (g_atomic_int_dec_and_test(&parser->ref_count) == FALSE)
1329 g_string_free(parser->content, TRUE);
1331 g_free(parser->begin_token);
1332 g_free(parser->end_token);
1336 void g_web_parser_feed_data(GWebParser *parser,
1337 const guint8 *data, gsize length)
1339 const guint8 *ptr = data;
1344 while (length > 0) {
1345 guint8 chr = parser->token_str[parser->token_pos];
1347 if (parser->token_pos == 0) {
1350 pos = memchr(ptr, chr, length);
1352 if (parser->intoken == TRUE)
1353 g_string_append_len(parser->content,
1354 (gchar *) ptr, length);
1358 if (parser->intoken == TRUE)
1359 g_string_append_len(parser->content,
1360 (gchar *) ptr, (pos - ptr) + 1);
1362 length -= (pos - ptr) + 1;
1365 parser->token_pos++;
1369 if (parser->intoken == TRUE)
1370 g_string_append_c(parser->content, ptr[0]);
1372 if (ptr[0] != chr) {
1376 parser->token_pos = 0;
1383 parser->token_pos++;
1385 if (parser->token_pos == parser->token_len) {
1386 if (parser->intoken == FALSE) {
1387 g_string_append(parser->content,
1390 parser->intoken = TRUE;
1391 parser->token_str = parser->end_token;
1392 parser->token_len = strlen(parser->end_token);
1393 parser->token_pos = 0;
1396 str = g_string_free(parser->content, FALSE);
1397 parser->content = g_string_sized_new(0);
1399 parser->func(str, parser->user_data);
1402 parser->intoken = FALSE;
1403 parser->token_str = parser->begin_token;
1404 parser->token_len = strlen(parser->begin_token);
1405 parser->token_pos = 0;
1411 void g_web_parser_end_data(GWebParser *parser)