Subversion Repositories HelenOS

Rev

Rev 3666 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3666 Rev 3685
Line 34... Line 34...
34
 * @file
34
 * @file
35
 */
35
 */
36
 
36
 
37
#include <errno.h>
37
#include <errno.h>
38
#include <malloc.h>
38
#include <malloc.h>
-
 
39
#include <stdio.h>
39
#include <string.h>
40
#include <string.h>
40
#include <unistd.h>
41
#include <unistd.h>
41
#include <ipc/ipc.h>
42
#include <ipc/ipc.h>
42
 
43
 
43
#include "err.h"
44
#include "err.h"
Line 67... Line 68...
67
    int     index;
68
    int     index;
68
    size_t      length;
69
    size_t      length;
69
    char *      next;
70
    char *      next;
70
    ipc_callid_t    callid;
71
    ipc_callid_t    callid;
71
 
72
 
72
    if(( ! strings ) || ( !( * data )) || ( count <= 0 )){
73
    if(( ! strings ) || ( ! data ) || ( count <= 0 )){
73
        return EINVAL;
74
        return EINVAL;
74
    }
75
    }
75
    lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 ));
76
    lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 ));
76
    if( ! lengths ) return ENOMEM;
77
    if( ! lengths ) return ENOMEM;
77
    if( ERROR_OCCURED( ipc_data_write_receive( & callid, & length ))){
78
    if(( ! ipc_data_write_receive( & callid, & length ))
78
        free( lengths );
-
 
79
        return ERROR_CODE;
-
 
80
    }
-
 
81
    if( length < sizeof( size_t ) * ( count + 1 )){
79
    || ( length != sizeof( size_t ) * ( count + 1 ))){
82
        free( lengths );
80
        free( lengths );
83
        return EINVAL;
81
        return EINVAL;
84
    }
82
    }
85
    if( ERROR_OCCURED( ipc_data_write_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
83
    if( ERROR_OCCURED( ipc_data_write_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
86
        free( lengths );
84
        free( lengths );
87
        return ERROR_CODE;
85
        return ERROR_CODE;
88
    }
86
    }
89
    * data = malloc( lengths[ count ] );
87
    * data = malloc( lengths[ count ] );
90
    if( !( * data )) return ENOMEM;
88
    if( !( * data )) return ENOMEM;
-
 
89
    ( * data )[ lengths[ count ] - 1 ] = '\0';
91
    * strings = ( measured_string_ref ) malloc( sizeof( measured_string_t ) * count );
90
    * strings = ( measured_string_ref ) malloc( sizeof( measured_string_t ) * count );
92
    if( !( * strings )){
91
    if( !( * strings )){
93
        free( lengths );
92
        free( lengths );
94
        free( * data );
93
        free( * data );
95
        return ENOMEM;
94
        return ENOMEM;
96
    }
95
    }
97
    next = * data;
96
    next = * data;
98
    for( index = 0; index < count; ++ index ){
97
    for( index = 0; index < count; ++ index ){
99
        ( * strings)[ index ].length = lengths[ index ];
98
        ( * strings)[ index ].length = lengths[ index ];
100
        if( lengths[ index ] > 0 ){
99
        if( lengths[ index ] > 0 ){
101
            ERROR_PROPAGATE( ipc_data_write_receive( & callid, & length ));
100
            if(( ! ipc_data_write_receive( & callid, & length ))
102
            if( length < lengths[ index ] + 1 ){
101
            || ( length != lengths[ index ] )){
103
                free( * data );
102
                free( * data );
104
                free( * strings );
103
                free( * strings );
105
                free( lengths );
104
                free( lengths );
106
                return EINVAL;
105
                return EINVAL;
107
            }
106
            }
108
            ERROR_PROPAGATE( ipc_data_write_finalize( callid, next, lengths[ index ] ));
107
            ERROR_PROPAGATE( ipc_data_write_finalize( callid, next, lengths[ index ] ));
-
 
108
            ( * strings)[ index ].value = next;
109
            next += lengths[ index ];
109
            next += lengths[ index ];
110
            * next = '\0';
110
            * next = '\0';
111
            ++ next;
111
            ++ next;
112
        }else{
112
        }else{
113
            ( * strings )[ index ].value = NULL;
113
            ( * strings )[ index ].value = NULL;
Line 128... Line 128...
128
    if(( ! strings ) || ( count <= 0 )){
128
    if(( ! strings ) || ( count <= 0 )){
129
        return EINVAL;
129
        return EINVAL;
130
    }
130
    }
131
    lengths = prepare_lengths( strings, count );
131
    lengths = prepare_lengths( strings, count );
132
    if( ! lengths ) return ENOMEM;
132
    if( ! lengths ) return ENOMEM;
133
    if( ERROR_OCCURED( ipc_data_read_receive( & callid, & length ))){
133
    if(( ! ipc_data_read_receive( & callid, & length ))
134
        free( lengths );
-
 
135
        return ERROR_CODE;
-
 
136
    }
-
 
137
    if( length < strings[ index ].length + 1 ){
134
    || ( length != sizeof( size_t ) * ( count + 1 ))){
138
        free( lengths );
135
        free( lengths );
139
        return EINVAL;
136
        return EINVAL;
140
    }
137
    }
141
    if( ERROR_OCCURED( ipc_data_read_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
138
    if( ERROR_OCCURED( ipc_data_read_finalize( callid, lengths, sizeof( size_t ) * ( count + 1 )))){
142
        free( lengths );
139
        free( lengths );
143
        return ERROR_CODE;
140
        return ERROR_CODE;
144
    }
141
    }
145
    free( lengths );
142
    free( lengths );
146
    for( index = 0; index < count; ++ index ){
143
    for( index = 0; index < count; ++ index ){
147
        if( strings[ index ].length > 0 ){
144
        if( strings[ index ].length > 0 ){
148
            ERROR_PROPAGATE( ipc_data_read_receive( & callid, & length ));
145
            if(( ! ipc_data_read_receive( & callid, & length ))
149
            if( length < strings[ index ].length + 1 ){
146
            || ( length != strings[ index ].length )){
150
                return EINVAL;
147
                return EINVAL;
151
            }
148
            }
152
            ERROR_PROPAGATE( ipc_data_read_finalize( callid, strings[ index ].value, strings[ index ].length ));
149
            ERROR_PROPAGATE( ipc_data_read_finalize( callid, strings[ index ].value, strings[ index ].length ));
153
        }
150
        }
154
    }
151
    }
Line 160... Line 157...
160
 
157
 
161
    size_t *    lengths;
158
    size_t *    lengths;
162
    int     index;
159
    int     index;
163
    char *      next;
160
    char *      next;
164
 
161
 
165
    if(( phone <= 0 ) || ( ! strings ) || ( !( * data )) || ( count <= 0 )){
162
    if(( phone <= 0 ) || ( ! strings ) || ( ! data ) || ( count <= 0 )){
166
        return EINVAL;
163
        return EINVAL;
167
    }
164
    }
168
    lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 ));
165
    lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 ));
169
    if( ! lengths ) return ENOMEM;
166
    if( ! lengths ) return ENOMEM;
170
    if( ERROR_OCCURED( ipc_data_read_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){
167
    if( ERROR_OCCURED( ipc_data_read_start( phone, lengths, sizeof( size_t ) * ( count + 1 )))){
Line 181... Line 178...
181
    }
178
    }
182
    next = * data;
179
    next = * data;
183
    for( index = 0; index < count; ++ index ){
180
    for( index = 0; index < count; ++ index ){
184
        ( * strings )[ index ].length = lengths[ index ];
181
        ( * strings )[ index ].length = lengths[ index ];
185
        if( lengths[ index ] > 0 ){
182
        if( lengths[ index ] > 0 ){
186
            ( * strings )[ index ].value = next;
-
 
187
            ERROR_PROPAGATE( ipc_data_read_start( phone, next, lengths[ index ] ));
183
            ERROR_PROPAGATE( ipc_data_read_start( phone, next, lengths[ index ] ));
-
 
184
            ( * strings )[ index ].value = next;
188
            next += lengths[ index ];
185
            next += lengths[ index ];
189
            * next = '\0';
186
            * next = '\0';
190
            ++ next;
187
            ++ next;
191
        }else{
188
        }else{
192
            ( * strings )[ index ].value = NULL;
189
            ( * strings )[ index ].value = NULL;
Line 212... Line 209...
212
        return ERROR_CODE;
209
        return ERROR_CODE;
213
    }
210
    }
214
    free( lengths );
211
    free( lengths );
215
    for( index = 0; index < count; ++ index ){
212
    for( index = 0; index < count; ++ index ){
216
        if( strings[ index ].length > 0 ){
213
        if( strings[ index ].length > 0 ){
217
            ERROR_PROPAGATE( ipc_data_write_start( phone, strings[ index ].value, strings[ index ].length + 1 ));
214
            ERROR_PROPAGATE( ipc_data_write_start( phone, strings[ index ].value, strings[ index ].length ));
218
        }
215
        }
219
    }
216
    }
220
    return EOK;
217
    return EOK;
221
}
218
}
222
 
219