Commit 8fe9f929 8fe9f9292791c6f5ede4368553c728c4331718fb by Sam Roberts

message_create_copy(): creates a copy of a message, useful when you want

to operate on a temporary copy of a message.
1 parent 0e2610e1
...@@ -30,6 +30,8 @@ extern "C" { ...@@ -30,6 +30,8 @@ extern "C" {
30 extern int message_create __P ((message_t *, void *owner)); 30 extern int message_create __P ((message_t *, void *owner));
31 extern void message_destroy __P ((message_t *, void *owner)); 31 extern void message_destroy __P ((message_t *, void *owner));
32 32
33 extern int message_create_copy __P ((message_t *to, message_t from));
34
33 extern void * message_get_owner __P ((message_t)); 35 extern void * message_get_owner __P ((message_t));
34 extern int message_is_modified __P ((message_t)); 36 extern int message_is_modified __P ((message_t));
35 extern int message_clear_modified __P ((message_t)); 37 extern int message_clear_modified __P ((message_t));
......
...@@ -162,6 +162,41 @@ message_destroy (message_t *pmsg, void *owner) ...@@ -162,6 +162,41 @@ message_destroy (message_t *pmsg, void *owner)
162 } 162 }
163 163
164 int 164 int
165 message_create_copy (message_t *to, message_t from)
166 {
167 int status = 0;
168 stream_t fromstr = NULL;
169 stream_t tostr = NULL;
170 off_t off = 0;
171 size_t n = 0;
172 char buf[512];
173
174 if(!to || !from)
175 return EINVAL;
176
177 if((status = message_create (to, NULL)))
178 return status;
179
180 message_get_stream (from, &fromstr);
181 message_get_stream (*to, &tostr);
182
183 while (
184 (status = stream_readline (fromstr, buf, sizeof(buf), off, &n)) == 0
185 &&
186 n > 0
187 )
188 {
189 stream_write (tostr, buf, n, off, NULL);
190 off += n;
191 }
192
193 if(status)
194 message_destroy(to, NULL);
195
196 return status;
197 }
198
199 int
165 message_ref (message_t msg) 200 message_ref (message_t msg)
166 { 201 {
167 if (msg) 202 if (msg)
......