Rev 3685 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3685 | Rev 3846 | ||
---|---|---|---|
Line 25... | Line 25... | ||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup net |
29 | /** @addtogroup net |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
- | |
34 | * @file |
33 | /** @file |
- | 34 | * A character string with measured length implementation file. |
|
- | 35 | * @see measured_strings.h |
|
35 | */ |
36 | */ |
36 | 37 | ||
37 | #include <errno.h> |
38 | #include <errno.h> |
38 | #include <malloc.h> |
39 | #include <malloc.h> |
39 | #include <stdio.h> |
40 | #include <stdio.h> |
40 | #include <string.h> |
41 | #include <string.h> |
41 | #include <unistd.h> |
42 | #include <unistd.h> |
- | 43 | ||
42 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
43 | 45 | ||
44 | #include "err.h" |
46 | #include "err.h" |
45 | #include "measured_strings.h" |
47 | #include "measured_strings.h" |
46 | #include "modules.h" |
48 | #include "modules.h" |
47 | 49 | ||
- | 50 | /** Computes the lengths of the measured strings in the given array. |
|
- | 51 | * @param strings The measured strings array to be processed. Input parameter. |
|
- | 52 | * @param count The measured strings array size. Input parameter. |
|
- | 53 | * @returns The computed sizes array. |
|
- | 54 | * @returns NULL if there is no memory left. |
|
- | 55 | */ |
|
48 | size_t * prepare_lengths( measured_string_ref strings, size_t count ); |
56 | size_t * prepare_lengths( const measured_string_ref strings, size_t count ); |
49 | 57 | ||
50 | measured_string_ref measured_string_create_bulk( const char * string, size_t length ){ |
58 | measured_string_ref measured_string_create_bulk( const char * string, size_t length ){ |
51 | measured_string_ref new; |
59 | measured_string_ref new; |
52 | 60 | ||
53 | if( length == 0 ){ |
61 | if( length == 0 ){ |
Line 55... | Line 63... | ||
55 | } |
63 | } |
56 | new = ( measured_string_ref ) malloc( sizeof( measured_string_t ) + ( sizeof( char ) * ( length + 1 ))); |
64 | new = ( measured_string_ref ) malloc( sizeof( measured_string_t ) + ( sizeof( char ) * ( length + 1 ))); |
57 | if( ! new ) return NULL; |
65 | if( ! new ) return NULL; |
58 | new->length = length; |
66 | new->length = length; |
59 | new->value = (( char * ) new ) + sizeof( measured_string_t ); |
67 | new->value = (( char * ) new ) + sizeof( measured_string_t ); |
- | 68 | // append terminating zero explicitly - to be safe |
|
60 | memcpy( new->value, string, new->length + 1 ); |
69 | memcpy( new->value, string, new->length ); |
- | 70 | new->value[ new->length ] = '\0'; |
|
61 | return new; |
71 | return new; |
62 | } |
72 | } |
63 | 73 | ||
64 | int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count ){ |
74 | int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count ){ |
65 | ERROR_DECLARE; |
75 | ERROR_DECLARE; |
66 | 76 | ||
67 | size_t * lengths; |
77 | size_t * lengths; |
68 | int index; |
78 | int index; |
69 | size_t length; |
79 | size_t length; |
70 | char * next; |
80 | char * next; |
71 | ipc_callid_t callid; |
81 | ipc_callid_t callid; |
72 | 82 | ||
73 | if(( ! strings ) || ( ! data ) || ( count <= 0 )){ |
83 | if(( ! strings ) || ( ! data ) || ( count <= 0 )){ |
74 | return EINVAL; |
84 | return EINVAL; |
75 | } |
85 | } |
Line 115... | Line 125... | ||
115 | } |
125 | } |
116 | free( lengths ); |
126 | free( lengths ); |
117 | return EOK; |
127 | return EOK; |
118 | } |
128 | } |
119 | 129 | ||
120 | int measured_strings_reply( measured_string_ref strings, size_t count ){ |
130 | int measured_strings_reply( const measured_string_ref strings, size_t count ){ |
121 | ERROR_DECLARE; |
131 | ERROR_DECLARE; |
122 | 132 | ||
123 | size_t * lengths; |
133 | size_t * lengths; |
124 | int index; |
134 | int index; |
125 | size_t length; |
135 | size_t length; |
126 | ipc_callid_t callid; |
136 | ipc_callid_t callid; |
127 | 137 | ||
128 | if(( ! strings ) || ( count <= 0 )){ |
138 | if(( ! strings ) || ( count <= 0 )){ |
129 | return EINVAL; |
139 | return EINVAL; |
130 | } |
140 | } |
Line 154... | Line 164... | ||
154 | 164 | ||
155 | int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count ){ |
165 | int measured_strings_return( int phone, measured_string_ref * strings, char ** data, size_t count ){ |
156 | ERROR_DECLARE; |
166 | ERROR_DECLARE; |
157 | 167 | ||
158 | size_t * lengths; |
168 | size_t * lengths; |
159 | int index; |
169 | int index; |
160 | char * next; |
170 | char * next; |
161 | 171 | ||
162 | if(( phone <= 0 ) || ( ! strings ) || ( ! data ) || ( count <= 0 )){ |
172 | if(( phone <= 0 ) || ( ! strings ) || ( ! data ) || ( count <= 0 )){ |
163 | return EINVAL; |
173 | return EINVAL; |
164 | } |
174 | } |
Line 191... | Line 201... | ||
191 | } |
201 | } |
192 | free( lengths ); |
202 | free( lengths ); |
193 | return EOK; |
203 | return EOK; |
194 | } |
204 | } |
195 | 205 | ||
196 | int measured_strings_send( int phone, measured_string_ref strings, size_t count ){ |
206 | int measured_strings_send( int phone, const measured_string_ref strings, size_t count ){ |
197 | ERROR_DECLARE; |
207 | ERROR_DECLARE; |
198 | 208 | ||
199 | size_t * lengths; |
209 | size_t * lengths; |
200 | int index; |
210 | int index; |
201 | 211 | ||
202 | if(( phone <= 0 ) || ( ! strings ) || ( count <= 0 )){ |
212 | if(( phone <= 0 ) || ( ! strings ) || ( count <= 0 )){ |
203 | return EINVAL; |
213 | return EINVAL; |
204 | } |
214 | } |
205 | lengths = prepare_lengths( strings, count ); |
215 | lengths = prepare_lengths( strings, count ); |
Line 215... | Line 225... | ||
215 | } |
225 | } |
216 | } |
226 | } |
217 | return EOK; |
227 | return EOK; |
218 | } |
228 | } |
219 | 229 | ||
220 | size_t * prepare_lengths( measured_string_ref strings, size_t count ){ |
230 | size_t * prepare_lengths( const measured_string_ref strings, size_t count ){ |
221 | size_t * lengths; |
231 | size_t * lengths; |
222 | int index; |
232 | int index; |
223 | size_t length; |
233 | size_t length; |
224 | 234 | ||
225 | lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
235 | lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
226 | if( ! lengths ) return NULL; |
236 | if( ! lengths ) return NULL; |
227 | length = 0; |
237 | length = 0; |