2 * Copyright (c)2004 Cat's Eye Technologies. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * Neither the name of Cat's Eye Technologies nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
36 * $Id: encode.c,v 1.12 2005/02/07 06:40:00 cpressey Exp $
43 #include <libaura/buffer.h>
45 #define NEEDS_DFUI_STRUCTURE_DEFINITIONS
47 #undef NEEDS_DFUI_STRUCTURE_DEFINITIONS
53 dfui_encode_string(struct aura_buffer
*e
, const char *str
)
58 aura_buffer_cat(e
, "0:");
60 snprintf(fmt
, 16, "%zu", strlen(str
));
61 aura_buffer_cat(e
, fmt
);
62 aura_buffer_cat(e
, ":");
63 aura_buffer_cat(e
, str
);
68 dfui_encode_int(struct aura_buffer
*e
, int i
)
72 snprintf(fmt
, 16, "%d", i
);
73 aura_buffer_cat(e
, fmt
);
74 aura_buffer_cat(e
, " ");
78 dfui_encode_bool(struct aura_buffer
*e
, int b
)
81 aura_buffer_cat(e
, "Y");
83 aura_buffer_cat(e
, "N");
89 dfui_encode_info(struct aura_buffer
*e
, struct dfui_info
*i
)
91 dfui_encode_string(e
, i
->name
);
92 dfui_encode_string(e
, i
->short_desc
);
93 dfui_encode_string(e
, i
->long_desc
);
97 dfui_encode_form(struct aura_buffer
*e
, struct dfui_form
*f
)
99 aura_buffer_cat(e
, "F{");
100 dfui_encode_string(e
, f
->id
);
101 dfui_encode_info(e
, f
->info
);
103 dfui_encode_bool(e
, f
->multiple
);
104 dfui_encode_bool(e
, f
->extensible
);
106 dfui_encode_fields(e
, f
->field_head
);
107 dfui_encode_actions(e
, f
->action_head
);
108 dfui_encode_datasets(e
, f
->dataset_head
);
109 dfui_encode_properties(e
, f
->property_head
);
111 aura_buffer_cat(e
, "}");
115 dfui_encode_fields(struct aura_buffer
*e
, struct dfui_field
*head
)
117 struct dfui_field
*fi
;
119 aura_buffer_cat(e
, "f{");
120 for (fi
= head
; fi
!= NULL
; fi
= fi
->next
) {
121 dfui_encode_field(e
, fi
);
123 aura_buffer_cat(e
, "}");
127 dfui_encode_field(struct aura_buffer
*e
, struct dfui_field
*fi
)
129 dfui_encode_string(e
, fi
->id
);
130 dfui_encode_info(e
, fi
->info
);
131 dfui_encode_options(e
, fi
->option_head
);
132 dfui_encode_properties(e
, fi
->property_head
);
136 dfui_encode_options(struct aura_buffer
*e
, struct dfui_option
*head
)
138 struct dfui_option
*o
;
140 aura_buffer_cat(e
, "O{");
141 for (o
= head
; o
!= NULL
; o
= o
->next
) {
142 dfui_encode_option(e
, o
);
144 aura_buffer_cat(e
, "}");
148 dfui_encode_option(struct aura_buffer
*e
, struct dfui_option
*o
)
150 dfui_encode_string(e
, o
->value
);
154 dfui_encode_actions(struct aura_buffer
*e
, struct dfui_action
*head
)
156 struct dfui_action
*a
;
158 aura_buffer_cat(e
, "a{");
159 for (a
= head
; a
!= NULL
; a
= a
->next
) {
160 dfui_encode_action(e
, a
);
162 aura_buffer_cat(e
, "}");
166 dfui_encode_action(struct aura_buffer
*e
, struct dfui_action
*a
)
168 dfui_encode_string(e
, a
->id
);
169 dfui_encode_info(e
, a
->info
);
170 dfui_encode_properties(e
, a
->property_head
);
174 dfui_encode_datasets(struct aura_buffer
*e
, struct dfui_dataset
*head
)
176 struct dfui_dataset
*ds
;
178 aura_buffer_cat(e
, "D{");
179 for (ds
= head
; ds
!= NULL
; ds
= ds
->next
) {
180 dfui_encode_dataset(e
, ds
);
182 aura_buffer_cat(e
, "}");
186 dfui_encode_dataset(struct aura_buffer
*e
, struct dfui_dataset
*ds
)
188 dfui_encode_celldatas(e
, ds
->celldata_head
);
192 dfui_encode_celldatas(struct aura_buffer
*e
, struct dfui_celldata
*c
)
194 aura_buffer_cat(e
, "d{");
196 dfui_encode_celldata(e
, c
);
199 aura_buffer_cat(e
, "}");
203 dfui_encode_celldata(struct aura_buffer
*e
, struct dfui_celldata
*c
)
205 dfui_encode_string(e
, c
->field_id
);
206 dfui_encode_string(e
, c
->value
);
210 dfui_encode_properties(struct aura_buffer
*e
, struct dfui_property
*h
)
212 aura_buffer_cat(e
, "p{");
214 dfui_encode_property(e
, h
);
217 aura_buffer_cat(e
, "}");
221 dfui_encode_property(struct aura_buffer
*e
, struct dfui_property
*h
)
223 dfui_encode_string(e
, h
->name
);
224 dfui_encode_string(e
, h
->value
);
228 dfui_encode_response(struct aura_buffer
*e
, struct dfui_response
*r
)
231 aura_buffer_cat(e
, "R{");
232 dfui_encode_string(e
, r
->form_id
);
233 dfui_encode_string(e
, r
->action_id
);
234 dfui_encode_datasets(e
, r
->dataset_head
);
235 aura_buffer_cat(e
, "}");
240 dfui_encode_progress(struct aura_buffer
*e
, struct dfui_progress
*pr
)
242 dfui_encode_info(e
, pr
->info
);
243 dfui_encode_int(e
, pr
->amount
);
244 dfui_encode_int(e
, pr
->streaming
);
245 dfui_encode_string(e
, pr
->msg_line
);