File: common.h

package info (click to toggle)
liferea 0.9.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,284 kB
  • ctags: 1,677
  • sloc: ansic: 15,454; sh: 8,440; makefile: 239; cpp: 187
file content (135 lines) | stat: -rw-r--r-- 4,330 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
 * @file common.h common routines
 *
 * Copyright (C) 2003-2005 Lars Lindner <lars.lindner@gmx.net>
 * Copyright (C) 2004,2005 Nathan J. Conrad <t98502@users.sourceforge.net>
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
#ifndef _COMMON_H
#define _COMMON_H

#include <config.h>
#include <time.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <glib.h>

#define htmlToCDATA(buffer) g_strdup_printf("<![CDATA[%s]]>", buffer)

extern gboolean lifereaStarted;

struct folder;

typedef struct node {
	gint type;
	gpointer *ui_data;
} *nodePtr;

/** Conversion function which should be applied to all read XML strings, 
   to ensure proper UTF8. doc points to the xml document and its encoding and
   string is a xmlChar pointer to the read string. The result gchar
   string is returned, the original XML string is freed. */
gchar * utf8_fix(xmlChar * string);

/* converts a UTF-8 string to HTML (resolves XML entities) */
gchar * convertToHTML(gchar * string);

/* converts a UTF-8 string containing HTML tags to plain text */
gchar * unhtmlize(gchar *string);

/* parses a XML node and returns its contents as a string */
/* gchar * parseHTML(htmlNodePtr cur); */

/** to extract not escaped XHTML from a node
 * @param only extract the children of the passed node */
gchar * extractHTMLNode(xmlNodePtr cur, gboolean children);

void	addToHTMLBufferFast(gchar **buffer, const gchar *string);
void	addToHTMLBuffer(gchar **buffer, const gchar *string);

/** Common function to create a XML DOM object from a given
   XML buffer. This function sets up a parser context,
   enables recovery mode and sets up the error handler.
   
   The function returns a XML document and (if errors)
   occur sets the errormsg to the last error message. */
xmlDocPtr parseBuffer(gchar *data, size_t dataLength, gchar **errormsg);

time_t 	parseISO8601Date(gchar *date);
/**
 * Parses a RFC822 format date. This FAILS if a timezone string is
 * specified such as EDT or EST and that timezone is in daylight
 * savings time.
 *
 * @returns UNIX time (GMT, no daylight savings time)
 */
time_t 	parseRFC822Date(gchar *date);
gchar *createRFC822Date(const time_t *time);
/* FIXME: formatDate used by several functions not only
   to format date column, don't use always date column format!!!
   maybe gchar * formatDate(time_t, gchar *format) */
gchar * formatDate(time_t t);

gchar *	common_get_cache_path(void);
gchar * common_create_cache_filename( const gchar *folder, const gchar *key, const gchar *extension);

/**
 * Encodes all non URI conformant characters in the passed
 * string to be included in a HTTP URI. The original string
 * is freed.
 *
 * @param string	string to be URI-escaped
 * @returns new string that can be inserted into a HTTP URI
 */
gchar * encode_uri_string(gchar *string);

/**
 * Encodes all non URI conformant characters in the passed
 * string and returns a valid HTTP URI. The original string
 * is freed.
 *
 * @param uri_string	string to be URI-escaped
 * @returns valid HTTP URI
 */
gchar * encode_uri(gchar *uri_string);

/**
 * Takes an URL and returns a new string containing
 * the escaped URL.
 *
 * @param url		the URL to escape
 */
xmlChar * common_uri_escape(const xmlChar *url);

/** 
 * To correctly escape and expand URLs, does not touch the
 * passed strings.
 *
 * @param url		relative URL
 * @param baseURL	base URL
 * @returns resulting absolute URL
 */
xmlChar * common_build_url(const gchar *url, const gchar *baseURL);

#ifndef HAVE_STRSEP
char *strsep (char **stringp, const char *delim);
#endif

gchar *strreplace(const char *string, const char *delimiter,
			   const char *replacement);

#endif