just kick off another build
[moon.git] / src / utils.h
blob883b1ab03cc38f2081aaf4a5f34f10b3a884c295
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * utils.h:
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
14 #ifndef __UTILS_H__
15 #define __UTILS_H__
17 #include <glib.h>
18 #include <cairo.h>
19 #include <sys/types.h>
21 #include "downloader.h"
22 #include "zip/unzip.h"
24 G_BEGIN_DECLS
26 typedef gboolean (*Stream_CanSeek) (void *handle);
27 typedef gboolean (*Stream_CanRead) (void *handle);
28 typedef gint64 (*Stream_Length) (void *handle);
29 typedef gint64 (*Stream_Position) (void *handle);
30 typedef gint32 (*Stream_Read) (void *handle, void *buffer, gint32 offset, gint32 count);
31 typedef void (*Stream_Write) (void *handle, void *buffer, gint32 offset, gint32 count);
32 typedef void (*Stream_Seek) (void *handle, gint64 offset, gint32 origin);
33 typedef void (*Stream_Close) (void *handle);
35 struct ManagedStreamCallbacks {
36 void *handle;
37 Stream_CanSeek CanSeek;
38 Stream_CanRead CanRead;
39 Stream_Length Length;
40 Stream_Position Position;
41 Stream_Read Read;
42 Stream_Write Write;
43 Stream_Seek Seek;
44 Stream_Close Close;
47 /* @GeneratePInvoke */
48 gboolean managed_unzip_stream_to_stream (ManagedStreamCallbacks *source, ManagedStreamCallbacks *dest, const char *partname);
50 gboolean managed_unzip_extract_to_stream (unzFile zipFile, ManagedStreamCallbacks *dest);
52 G_GNUC_INTERNAL void g_ptr_array_insert (GPtrArray *array, guint index, void *item);
54 G_GNUC_INTERNAL void g_ptr_array_insert_sorted (GPtrArray *array, GCompareFunc cmp, void *item);
56 const char *CanonicalizeFilename (char *filename, int n, bool lower);
58 bool ExtractFile (unzFile zip, int fd);
59 bool ExtractAll (unzFile zip, const char *dir, bool lower);
61 char *MakeTempDir (char *tmpdir);
62 char *CreateTempDir (const char *filename);
64 int RemoveDir (const char *dir);
66 int CopyFileTo (const char *filename, int fd);
68 int write_all (int fd, char *buf, size_t len);
70 cairo_t *measuring_context_create (void);
71 void measuring_context_destroy (cairo_t *cr);
73 GArray *double_garray_from_str (const char *s, gint max);
76 * Returns a pointer to the first token found.
78 * @input: the input string
79 * @c: output, upon return contains the first character not in the token.
80 * @end: output, upon return contains a pointer to the remaining input (NULL if no more data)
82 * Note: the input string is modified.
84 char *parse_rfc_1945_token (char *input, char *c, char **end);
87 * Returns a pointer to the unquoted string.
89 * @input: the input string
90 * @c: output, upon return contains the first character not in the quoted string.
91 * @end: output, upon return contains a pointer to the remaining input (NULL if no more data)
93 * Note: the input string is modified.
95 char *parse_rfc_1945_quoted_string (char *input, char *c, char **end);
97 G_END_DECLS
99 class TextStream {
100 protected:
101 char buffer[4096];
102 size_t buflen;
103 char *bufptr;
104 GIConv cd;
106 char *textbuf;
107 char *textbufptr;
108 int textbufsize;
110 int fd;
111 bool eof;
113 bool fmode;
115 bool ReadBOM (bool force);
116 ssize_t ReadInternal (char *buf, ssize_t n);
118 public:
119 TextStream ();
120 ~TextStream ();
122 bool OpenBuffer (const char *buf, int size);
123 bool OpenFile (const char *filename, bool force);
124 void Close ();
126 bool Eof ();
128 ssize_t Read (char *buf, size_t n);
131 typedef void (*CancelCallback) (gpointer user_data, void *context);
133 class Cancellable {
134 private:
135 CancelCallback cancel_cb;
136 Downloader *downloader;
137 void *context;
138 public:
139 Cancellable ();
140 ~Cancellable ();
142 void Cancel ();
143 void SetCancelFuncAndData (CancelCallback cb, Downloader *user_data, void *context);
146 #endif /* __UTILS_H__ */