1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * soup-server-message.c: Server-side messages |
---|
4 | * |
---|
5 | * Copyright (C) 2001-2003, Ximian, Inc. |
---|
6 | */ |
---|
7 | |
---|
8 | #ifdef HAVE_CONFIG_H |
---|
9 | #include <config.h> |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <string.h> |
---|
13 | #include <stdio.h> |
---|
14 | #include <stdlib.h> |
---|
15 | #include <unistd.h> |
---|
16 | |
---|
17 | #include "soup-server-message.h" |
---|
18 | #include "soup-server.h" |
---|
19 | |
---|
20 | struct SoupServerMessagePrivate { |
---|
21 | SoupServer *server; |
---|
22 | |
---|
23 | SoupTransferEncoding encoding; |
---|
24 | |
---|
25 | gboolean started; |
---|
26 | gboolean finished; |
---|
27 | }; |
---|
28 | |
---|
29 | #define PARENT_TYPE SOUP_TYPE_MESSAGE |
---|
30 | static SoupMessageClass *parent_class; |
---|
31 | |
---|
32 | static void |
---|
33 | init (GObject *object) |
---|
34 | { |
---|
35 | SoupServerMessage *smsg = SOUP_SERVER_MESSAGE (object); |
---|
36 | |
---|
37 | smsg->priv = g_new0 (SoupServerMessagePrivate, 1); |
---|
38 | } |
---|
39 | |
---|
40 | static void |
---|
41 | finalize (GObject *object) |
---|
42 | { |
---|
43 | SoupServerMessage *smsg = SOUP_SERVER_MESSAGE (object); |
---|
44 | |
---|
45 | /* FIXME */ |
---|
46 | g_free ((char *) ((SoupMessage *)smsg)->method); |
---|
47 | |
---|
48 | g_free (smsg->priv); |
---|
49 | |
---|
50 | G_OBJECT_CLASS (parent_class)->finalize (object); |
---|
51 | } |
---|
52 | |
---|
53 | static void |
---|
54 | dispose (GObject *object) |
---|
55 | { |
---|
56 | SoupServerMessage *smsg = SOUP_SERVER_MESSAGE (object); |
---|
57 | |
---|
58 | if (smsg->priv->server) |
---|
59 | g_object_unref (smsg->priv->server); |
---|
60 | |
---|
61 | G_OBJECT_CLASS (parent_class)->dispose (object); |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | static void |
---|
67 | class_init (GObjectClass *object_class) |
---|
68 | { |
---|
69 | parent_class = g_type_class_ref (PARENT_TYPE); |
---|
70 | |
---|
71 | /* virtual method override */ |
---|
72 | object_class->finalize = finalize; |
---|
73 | object_class->dispose = dispose; |
---|
74 | } |
---|
75 | |
---|
76 | SOUP_MAKE_TYPE (soup_server_message, SoupServerMessage, class_init, init, PARENT_TYPE) |
---|
77 | |
---|
78 | |
---|
79 | SoupServerMessage * |
---|
80 | soup_server_message_new (SoupServer *server) |
---|
81 | { |
---|
82 | SoupServerMessage *smsg; |
---|
83 | |
---|
84 | g_return_val_if_fail (SOUP_IS_SERVER (server), NULL); |
---|
85 | |
---|
86 | smsg = g_object_new (SOUP_TYPE_SERVER_MESSAGE, NULL); |
---|
87 | smsg->priv->server = g_object_ref (server); |
---|
88 | |
---|
89 | return smsg; |
---|
90 | } |
---|
91 | |
---|
92 | SoupServer * |
---|
93 | soup_server_message_get_server (SoupServerMessage *smsg) |
---|
94 | { |
---|
95 | g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (smsg), NULL); |
---|
96 | |
---|
97 | return smsg->priv->server; |
---|
98 | } |
---|
99 | |
---|
100 | void |
---|
101 | soup_server_message_set_encoding (SoupServerMessage *smsg, |
---|
102 | SoupTransferEncoding encoding) |
---|
103 | { |
---|
104 | g_return_if_fail (SOUP_IS_SERVER_MESSAGE (smsg)); |
---|
105 | |
---|
106 | smsg->priv->encoding = encoding; |
---|
107 | } |
---|
108 | |
---|
109 | SoupTransferEncoding |
---|
110 | soup_server_message_get_encoding (SoupServerMessage *smsg) |
---|
111 | { |
---|
112 | g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (smsg), SOUP_TRANSFER_UNKNOWN); |
---|
113 | |
---|
114 | return smsg->priv->encoding; |
---|
115 | } |
---|
116 | |
---|
117 | void |
---|
118 | soup_server_message_start (SoupServerMessage *smsg) |
---|
119 | { |
---|
120 | g_return_if_fail (SOUP_IS_SERVER_MESSAGE (smsg)); |
---|
121 | |
---|
122 | smsg->priv->started = TRUE; |
---|
123 | |
---|
124 | soup_message_io_unpause (SOUP_MESSAGE (smsg)); |
---|
125 | } |
---|
126 | |
---|
127 | gboolean |
---|
128 | soup_server_message_is_started (SoupServerMessage *smsg) |
---|
129 | { |
---|
130 | g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (smsg), TRUE); |
---|
131 | |
---|
132 | return smsg->priv->started; |
---|
133 | } |
---|
134 | |
---|
135 | void |
---|
136 | soup_server_message_finish (SoupServerMessage *smsg) |
---|
137 | { |
---|
138 | g_return_if_fail (SOUP_IS_SERVER_MESSAGE (smsg)); |
---|
139 | |
---|
140 | smsg->priv->started = TRUE; |
---|
141 | smsg->priv->finished = TRUE; |
---|
142 | |
---|
143 | soup_message_io_unpause (SOUP_MESSAGE (smsg)); |
---|
144 | } |
---|
145 | |
---|
146 | gboolean |
---|
147 | soup_server_message_is_finished (SoupServerMessage *smsg) |
---|
148 | { |
---|
149 | g_return_val_if_fail (SOUP_IS_SERVER_MESSAGE (smsg), TRUE); |
---|
150 | |
---|
151 | return smsg->priv->finished; |
---|
152 | } |
---|