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;
297 g_resolv_set_address_family(web->resolv, family);
302 gboolean g_web_add_nameserver(GWeb *web, const char *address)
307 g_resolv_add_nameserver(web->resolv, address, 53, 0);
312 static gboolean set_accept_option(GWeb *web, const char *format, va_list args)
314 g_free(web->accept_option);
316 if (format == NULL) {
317 web->accept_option = NULL;
318 debug(web, "clearing accept option");
320 web->accept_option = g_strdup_vprintf(format, args);
321 debug(web, "setting accept %s", web->accept_option);
327 gboolean g_web_set_accept(GWeb *web, const char *format, ...)
335 va_start(args, format);
336 result = set_accept_option(web, format, args);
342 static gboolean set_user_agent(GWeb *web, const char *format, va_list args)
344 g_free(web->user_agent);
346 if (format == NULL) {
347 web->user_agent = NULL;
348 debug(web, "clearing user agent");
350 web->user_agent = g_strdup_vprintf(format, args);
351 debug(web, "setting user agent %s", web->user_agent);
357 gboolean g_web_set_user_agent(GWeb *web, const char *format, ...)
365 va_start(args, format);
366 result = set_user_agent(web, format, args);
372 gboolean g_web_set_ua_profile(GWeb *web, const char *profile)
377 g_free(web->user_agent_profile);
379 web->user_agent_profile = g_strdup(profile);
380 debug(web, "setting user agent profile %s", web->user_agent);
385 gboolean g_web_set_http_version(GWeb *web, const char *version)
390 g_free(web->http_version);
392 if (version == NULL) {
393 web->http_version = NULL;
394 debug(web, "clearing HTTP version");
396 web->http_version = g_strdup(version);
397 debug(web, "setting HTTP version %s", web->http_version);
403 void g_web_set_close_connection(GWeb *web, gboolean enabled)
408 web->close_connection = enabled;
411 gboolean g_web_get_close_connection(GWeb *web)
416 return web->close_connection;
419 static inline void call_result_func(struct web_session *session, guint16 status)
423 if (session->result_func == NULL)
427 session->result.status = status;
429 result = session->result_func(&session->result, session->user_data);
431 debug(session->web, "[result function] %s",
432 result == TRUE ? "continue" : "stop");
435 static gboolean process_send_buffer(struct web_session *session)
437 GString *buf = session->send_buffer;
438 gsize count, bytes_written;
444 if (session->request_started == TRUE &&
445 session->more_data == FALSE)
446 session->body_done = TRUE;
451 status = g_io_channel_write_chars(session->transport_channel,
452 buf->str, count, &bytes_written, NULL);
454 debug(session->web, "status %u bytes to write %zu bytes written %zu",
455 status, count, bytes_written);
457 if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN)
460 g_string_erase(buf, 0, bytes_written);
465 static void process_next_chunk(struct web_session *session)
467 GString *buf = session->send_buffer;
471 if (session->input_func == NULL) {
472 session->more_data = FALSE;
476 session->more_data = session->input_func(&body, &length,
480 g_string_append_printf(buf, "%zx\r\n", length);
481 g_string_append_len(buf, (char *) body, length);
482 g_string_append(buf, "\r\n");
485 if (session->more_data == FALSE)
486 g_string_append(buf, "0\r\n\r\n");
489 static void start_request(struct web_session *session)
491 GString *buf = session->send_buffer;
496 debug(session->web, "request %s from %s",
497 session->request, session->host);
499 g_string_truncate(buf, 0);
501 if (session->web->http_version == NULL)
504 version = session->web->http_version;
506 if (session->content_type == NULL)
507 g_string_append_printf(buf, "GET %s HTTP/%s\r\n",
508 session->request, version);
510 g_string_append_printf(buf, "POST %s HTTP/%s\r\n",
511 session->request, version);
513 g_string_append_printf(buf, "Host: %s\r\n", session->host);
515 if (session->web->user_agent != NULL)
516 g_string_append_printf(buf, "User-Agent: %s\r\n",
517 session->web->user_agent);
519 if (session->web->user_agent_profile != NULL) {
520 g_string_append_printf(buf, "x-wap-profile: %s\r\n",
521 session->web->user_agent_profile);
524 if (session->web->accept_option != NULL)
525 g_string_append_printf(buf, "Accept: %s\r\n",
526 session->web->accept_option);
528 if (session->content_type != NULL) {
529 g_string_append_printf(buf, "Content-Type: %s\r\n",
530 session->content_type);
531 if (session->input_func == NULL) {
532 session->more_data = FALSE;
535 session->more_data = session->input_func(&body, &length,
537 if (session->more_data == FALSE)
538 g_string_append_printf(buf, "Content-Length: %zu\r\n",
541 g_string_append(buf, "Transfer-Encoding: chunked\r\n");
544 if (session->web->close_connection == TRUE)
545 g_string_append(buf, "Connection: close\r\n");
547 g_string_append(buf, "\r\n");
549 if (session->content_type != NULL && length > 0) {
550 if (session->more_data == TRUE) {
551 g_string_append_printf(buf, "%zx\r\n", length);
552 g_string_append_len(buf, (char *) body, length);
553 g_string_append(buf, "\r\n");
555 g_string_append_len(buf, (char *) body, length);
559 static gboolean send_data(GIOChannel *channel, GIOCondition cond,
562 struct web_session *session = user_data;
564 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
565 session->send_watch = 0;
569 if (process_send_buffer(session) == TRUE)
572 if (session->request_started == FALSE) {
573 session->request_started = TRUE;
574 start_request(session);
575 } else if (session->more_data == TRUE)
576 process_next_chunk(session);
578 process_send_buffer(session);
580 if (session->body_done == TRUE) {
581 session->send_watch = 0;
588 static int decode_chunked(struct web_session *session,
589 const guint8 *buf, gsize len)
591 const guint8 *ptr = buf;
599 switch (session->chunck_state) {
601 pos = memchr(ptr, '\n', len);
603 g_string_append_len(session->current_header,
609 if (count < 1 || ptr[count - 1] != '\r')
612 g_string_append_len(session->current_header,
613 (gchar *) ptr, count);
618 str = session->current_header->str;
620 counter = strtoul(str, NULL, 16);
621 if ((counter == 0 && errno == EINVAL) ||
622 counter == ULONG_MAX)
625 session->chunk_size = counter;
626 session->chunk_left = counter;
628 session->chunck_state = CHUNK_DATA;
635 session->chunck_state = CHUNK_N_BODY;
642 session->chunck_state = CHUNK_SIZE;
645 if (session->chunk_size == 0) {
646 debug(session->web, "Download Done in chunk");
647 g_string_truncate(session->current_header, 0);
651 if (session->chunk_left <= len) {
652 session->result.buffer = ptr;
653 session->result.length = session->chunk_left;
654 call_result_func(session, 0);
656 len -= session->chunk_left;
657 ptr += session->chunk_left;
659 session->total_len += session->chunk_left;
660 session->chunk_left = 0;
662 g_string_truncate(session->current_header, 0);
663 session->chunck_state = CHUNK_R_BODY;
667 session->result.buffer = ptr;
668 session->result.length = len;
669 call_result_func(session, 0);
671 session->chunk_left -= len;
672 session->total_len += len;
683 static int handle_body(struct web_session *session,
684 const guint8 *buf, gsize len)
688 debug(session->web, "[body] length %zu", len);
690 if (session->result.use_chunk == FALSE) {
692 session->result.buffer = buf;
693 session->result.length = len;
694 call_result_func(session, 0);
699 err = decode_chunked(session, buf, len);
701 debug(session->web, "Error in chunk decode %d", err);
703 session->result.buffer = NULL;
704 session->result.length = 0;
705 call_result_func(session, 400);
711 static void handle_multi_line(struct web_session *session)
717 str = session->current_header->str;
719 if (str[0] != ' ' && str[0] != '\t')
722 while (str[0] == ' ' || str[0] == '\t')
725 count = str - session->current_header->str;
727 g_string_erase(session->current_header, 0, count);
728 g_string_insert_c(session->current_header, 0, ' ');
731 value = g_hash_table_lookup(session->result.headers,
732 session->result.last_key);
734 g_string_insert(session->current_header, 0, value);
736 str = session->current_header->str;
738 g_hash_table_replace(session->result.headers,
739 g_strdup(session->result.last_key),
744 static void add_header_field(struct web_session *session)
752 str = session->current_header->str;
754 pos = memchr(str, ':', session->current_header->len);
761 /* remove preceding white spaces */
765 count = (char *) pos - str;
767 g_string_erase(session->current_header, 0, count);
769 value = g_hash_table_lookup(session->result.headers, key);
771 g_string_insert_c(session->current_header, 0, ' ');
772 g_string_insert_c(session->current_header, 0, ';');
774 g_string_insert(session->current_header, 0, value);
777 str = session->current_header->str;
778 g_hash_table_replace(session->result.headers, key,
781 g_free(session->result.last_key);
782 session->result.last_key = g_strdup(key);
786 static gboolean received_data(GIOChannel *channel, GIOCondition cond,
789 struct web_session *session = user_data;
790 guint8 *ptr = session->receive_buffer;
794 if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
795 session->transport_watch = 0;
796 session->result.buffer = NULL;
797 session->result.length = 0;
798 call_result_func(session, 400);
802 status = g_io_channel_read_chars(channel,
803 (gchar *) session->receive_buffer,
804 session->receive_space - 1, &bytes_read, NULL);
806 debug(session->web, "bytes read %zu", bytes_read);
808 if (status != G_IO_STATUS_NORMAL && status != G_IO_STATUS_AGAIN) {
809 session->transport_watch = 0;
810 session->result.buffer = NULL;
811 session->result.length = 0;
812 call_result_func(session, 0);
816 session->receive_buffer[bytes_read] = '\0';
818 if (session->header_done == TRUE) {
819 if (handle_body(session, session->receive_buffer,
821 session->transport_watch = 0;
827 while (bytes_read > 0) {
832 pos = memchr(ptr, '\n', bytes_read);
834 g_string_append_len(session->current_header,
835 (gchar *) ptr, bytes_read);
840 count = strlen((char *) ptr);
841 if (count > 0 && ptr[count - 1] == '\r') {
846 g_string_append_len(session->current_header,
847 (gchar *) ptr, count);
849 bytes_read -= count + 1;
855 if (session->current_header->len == 0) {
858 session->header_done = TRUE;
860 val = g_hash_table_lookup(session->result.headers,
861 "Transfer-Encoding");
863 val = g_strrstr(val, "chunked");
865 session->result.use_chunk = TRUE;
867 session->chunck_state = CHUNK_SIZE;
868 session->chunk_left = 0;
869 session->total_len = 0;
873 if (handle_body(session, ptr, bytes_read) < 0) {
874 session->transport_watch = 0;
880 str = session->current_header->str;
882 if (session->result.status == 0) {
885 if (sscanf(str, "HTTP/%*s %u %*s", &code) == 1)
886 session->result.status = code;
889 debug(session->web, "[header] %s", str);
891 /* handle multi-line header */
892 if (str[0] == ' ' || str[0] == '\t')
893 handle_multi_line(session);
895 add_header_field(session);
897 g_string_truncate(session->current_header, 0);
903 static int connect_session_transport(struct web_session *session)
908 sk = socket(session->addr->ai_family, SOCK_STREAM | SOCK_CLOEXEC,
913 if (session->flags & SESSION_FLAG_USE_TLS) {
914 debug(session->web, "using TLS encryption");
915 session->transport_channel = g_io_channel_gnutls_new(sk);
917 debug(session->web, "no encryption");
918 session->transport_channel = g_io_channel_unix_new(sk);
921 if (session->transport_channel == NULL) {
926 flags = g_io_channel_get_flags(session->transport_channel);
927 g_io_channel_set_flags(session->transport_channel,
928 flags | G_IO_FLAG_NONBLOCK, NULL);
930 g_io_channel_set_encoding(session->transport_channel, NULL, NULL);
931 g_io_channel_set_buffered(session->transport_channel, FALSE);
933 g_io_channel_set_close_on_unref(session->transport_channel, TRUE);
935 if (connect(sk, session->addr->ai_addr,
936 session->addr->ai_addrlen) < 0) {
937 if (errno != EINPROGRESS) {
943 session->transport_watch = g_io_add_watch(session->transport_channel,
944 G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
945 received_data, session);
947 session->send_watch = g_io_add_watch(session->transport_channel,
948 G_IO_OUT | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
954 static int create_transport(struct web_session *session)
958 err = connect_session_transport(session);
962 debug(session->web, "creating session %s:%u",
963 session->address, session->port);
968 static int parse_url(struct web_session *session,
969 const char *url, const char *proxy)
971 char *scheme, *host, *port, *path;
973 scheme = g_strdup(url);
977 host = strstr(scheme, "://");
982 if (strcasecmp(scheme, "https") == 0) {
984 session->flags |= SESSION_FLAG_USE_TLS;
985 } else if (strcasecmp(scheme, "http") == 0) {
996 path = strchr(host, '/');
1001 session->request = g_strdup_printf("/%s", path ? path : "");
1003 session->request = g_strdup(url);
1005 port = strrchr(host, ':');
1008 int tmp = strtol(port + 1, &end, 10);
1012 session->port = tmp;
1016 session->host = g_strdup(host);
1018 session->host = g_strdup_printf("%s:%u", host, tmp);
1020 session->host = g_strdup(host);
1027 scheme = g_strdup(proxy);
1031 host = strstr(proxy, "://");
1036 if (strcasecmp(scheme, "http") != 0) {
1043 path = strchr(host, '/');
1047 port = strrchr(host, ':');
1050 int tmp = strtol(port + 1, &end, 10);
1054 session->port = tmp;
1058 session->address = g_strdup(host);
1065 static void resolv_result(GResolvResultStatus status,
1066 char **results, gpointer user_data)
1068 struct web_session *session = user_data;
1069 struct addrinfo hints;
1073 if (results == NULL || results[0] == NULL) {
1074 call_result_func(session, 404);
1078 debug(session->web, "address %s", results[0]);
1080 memset(&hints, 0, sizeof(struct addrinfo));
1081 hints.ai_flags = AI_NUMERICHOST;
1082 hints.ai_family = session->web->family;
1084 if (session->addr != NULL) {
1085 freeaddrinfo(session->addr);
1086 session->addr = NULL;
1089 port = g_strdup_printf("%u", session->port);
1090 ret = getaddrinfo(results[0], port, &hints, &session->addr);
1092 if (ret != 0 || session->addr == NULL) {
1093 call_result_func(session, 400);
1097 session->address = g_strdup(results[0]);
1099 if (create_transport(session) < 0) {
1100 call_result_func(session, 409);
1105 static guint do_request(GWeb *web, const char *url,
1106 const char *type, GWebInputFunc input,
1107 GWebResultFunc func, gpointer user_data)
1109 struct web_session *session;
1111 if (web == NULL || url == NULL)
1114 debug(web, "request %s", url);
1116 session = g_try_new0(struct web_session, 1);
1117 if (session == NULL)
1120 if (parse_url(session, url, web->proxy) < 0) {
1121 free_session(session);
1125 debug(web, "address %s", session->address);
1126 debug(web, "port %u", session->port);
1127 debug(web, "host %s", session->host);
1128 debug(web, "flags %lu", session->flags);
1129 debug(web, "request %s", session->request);
1132 session->content_type = g_strdup(type);
1134 debug(web, "content-type %s", session->content_type);
1139 session->result_func = func;
1140 session->input_func = input;
1141 session->user_data = user_data;
1143 session->receive_buffer = g_try_malloc(DEFAULT_BUFFER_SIZE);
1144 if (session->receive_buffer == NULL) {
1145 free_session(session);
1149 session->result.headers = g_hash_table_new_full(g_str_hash, g_str_equal,
1151 if (session->result.headers == NULL) {
1152 free_session(session);
1156 session->receive_space = DEFAULT_BUFFER_SIZE;
1157 session->send_buffer = g_string_sized_new(0);
1158 session->current_header = g_string_sized_new(0);
1159 session->header_done = FALSE;
1160 session->body_done = FALSE;
1162 if (session->address == NULL && inet_aton(session->host, NULL) == 0) {
1163 session->resolv_action = g_resolv_lookup_hostname(web->resolv,
1164 session->host, resolv_result, session);
1165 if (session->resolv_action == 0) {
1166 free_session(session);
1170 struct addrinfo hints;
1174 if (session->address == NULL)
1175 session->address = g_strdup(session->host);
1177 memset(&hints, 0, sizeof(struct addrinfo));
1178 hints.ai_flags = AI_NUMERICHOST;
1179 hints.ai_family = session->web->family;
1181 if (session->addr != NULL) {
1182 freeaddrinfo(session->addr);
1183 session->addr = NULL;
1186 port = g_strdup_printf("%u", session->port);
1187 ret = getaddrinfo(session->address, port, &hints,
1190 if (ret != 0 || session->addr == NULL) {
1191 free_session(session);
1195 if (create_transport(session) < 0) {
1196 free_session(session);
1201 web->session_list = g_list_append(web->session_list, session);
1203 return web->next_query_id++;
1206 guint g_web_request_get(GWeb *web, const char *url,
1207 GWebResultFunc func, gpointer user_data)
1209 return do_request(web, url, NULL, NULL, func, user_data);
1212 guint g_web_request_post(GWeb *web, const char *url,
1213 const char *type, GWebInputFunc input,
1214 GWebResultFunc func, gpointer user_data)
1216 return do_request(web, url, type, input, func, user_data);
1219 gboolean g_web_cancel_request(GWeb *web, guint id)
1227 guint16 g_web_result_get_status(GWebResult *result)
1232 return result->status;
1235 gboolean g_web_result_get_chunk(GWebResult *result,
1236 const guint8 **chunk, gsize *length)
1244 *chunk = result->buffer;
1247 *length = result->length;
1252 gboolean g_web_result_get_header(GWebResult *result,
1253 const char *header, const char **value)
1261 *value = g_hash_table_lookup(result->headers, header);
1269 struct _GWebParser {
1273 const char *token_str;
1278 GWebParserFunc func;
1282 GWebParser *g_web_parser_new(const char *begin, const char *end,
1283 GWebParserFunc func, gpointer user_data)
1287 parser = g_try_new0(GWebParser, 1);
1291 parser->ref_count = 1;
1293 parser->begin_token = g_strdup(begin);
1294 parser->end_token = g_strdup(end);
1296 if (parser->begin_token == NULL) {
1301 parser->func = func;
1302 parser->user_data = user_data;
1304 parser->token_str = parser->begin_token;
1305 parser->token_len = strlen(parser->token_str);
1306 parser->token_pos = 0;
1308 parser->intoken = FALSE;
1309 parser->content = g_string_sized_new(0);
1314 GWebParser *g_web_parser_ref(GWebParser *parser)
1319 g_atomic_int_inc(&parser->ref_count);
1324 void g_web_parser_unref(GWebParser *parser)
1329 if (g_atomic_int_dec_and_test(&parser->ref_count) == FALSE)
1332 g_string_free(parser->content, TRUE);
1334 g_free(parser->begin_token);
1335 g_free(parser->end_token);
1339 void g_web_parser_feed_data(GWebParser *parser,
1340 const guint8 *data, gsize length)
1342 const guint8 *ptr = data;
1347 while (length > 0) {
1348 guint8 chr = parser->token_str[parser->token_pos];
1350 if (parser->token_pos == 0) {
1353 pos = memchr(ptr, chr, length);
1355 if (parser->intoken == TRUE)
1356 g_string_append_len(parser->content,
1357 (gchar *) ptr, length);
1361 if (parser->intoken == TRUE)
1362 g_string_append_len(parser->content,
1363 (gchar *) ptr, (pos - ptr) + 1);
1365 length -= (pos - ptr) + 1;
1368 parser->token_pos++;
1372 if (parser->intoken == TRUE)
1373 g_string_append_c(parser->content, ptr[0]);
1375 if (ptr[0] != chr) {
1379 parser->token_pos = 0;
1386 parser->token_pos++;
1388 if (parser->token_pos == parser->token_len) {
1389 if (parser->intoken == FALSE) {
1390 g_string_append(parser->content,
1393 parser->intoken = TRUE;
1394 parser->token_str = parser->end_token;
1395 parser->token_len = strlen(parser->end_token);
1396 parser->token_pos = 0;
1399 str = g_string_free(parser->content, FALSE);
1400 parser->content = g_string_sized_new(0);
1402 parser->func(str, parser->user_data);
1405 parser->intoken = FALSE;
1406 parser->token_str = parser->begin_token;
1407 parser->token_len = strlen(parser->begin_token);
1408 parser->token_pos = 0;
1414 void g_web_parser_end_data(GWebParser *parser)