Changes in uspace/lib/http/src/headers.c [5a6cc679:a35b458] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/http/src/headers.c
r5a6cc679 ra35b458 64 64 return NULL; 65 65 } 66 66 67 67 header->value = str_dup(value); 68 68 if (header->value == NULL) { … … 101 101 if (name_end) 102 102 recv_mark_update(rb, name_end); 103 103 104 104 errno_t rc = recv_char(rb, &c, true); 105 105 if (rc != EOK) 106 106 return rc; 107 107 } while (is_token(c)); 108 108 109 109 if (c != ':') 110 110 return EINVAL; 111 111 112 112 return EOK; 113 113 } … … 118 118 errno_t rc = EOK; 119 119 char c = 0; 120 120 121 121 /* Ignore any inline LWS */ 122 122 while (true) { 123 123 if (value_start) 124 124 recv_mark_update(rb, value_start); 125 125 126 126 rc = recv_char(rb, &c, false); 127 127 if (rc != EOK) 128 128 return rc; 129 129 130 130 if (c != ' ' && c != '\t') 131 131 break; 132 132 133 133 rc = recv_char(rb, &c, true); 134 134 if (rc != EOK) 135 135 return rc; 136 136 } 137 137 138 138 while (true) { 139 139 recv_mark_update(rb, value_end); 140 140 141 141 rc = recv_char(rb, &c, true); 142 142 if (rc != EOK) 143 143 return rc; 144 144 145 145 if (c != '\r' && c != '\n') 146 146 continue; 147 147 148 148 size_t nrecv; 149 149 rc = recv_discard(rb, (c == '\r' ? '\n' : '\r'), &nrecv); 150 150 if (rc != EOK) 151 151 return rc; 152 152 153 153 rc = recv_char(rb, &c, false); 154 154 if (rc != EOK) 155 155 return rc; 156 156 157 157 if (c != ' ' && c != '\t') 158 158 break; 159 159 160 160 /* Ignore the char */ 161 161 rc = recv_char(rb, &c, true); … … 163 163 return rc; 164 164 } 165 165 166 166 return EOK; 167 167 } … … 172 172 receive_buffer_mark_t mark_start; 173 173 receive_buffer_mark_t mark_end; 174 174 175 175 recv_mark(rb, &mark_start); 176 176 recv_mark(rb, &mark_end); 177 177 178 178 errno_t rc = http_header_receive_name(rb, &mark_end); 179 179 if (rc != EOK) 180 180 goto end; 181 181 182 182 size_t name_size = mark_end.offset - mark_start.offset; 183 183 if (size_limit > 0 && name_size > size_limit) { … … 185 185 goto end; 186 186 } 187 187 188 188 char *name = NULL; 189 189 rc = recv_cut_str(rb, &mark_start, &mark_end, &name); 190 190 if (rc != EOK) 191 191 goto end; 192 192 193 193 rc = http_header_receive_value(rb, &mark_start, &mark_end); 194 194 if (rc != EOK) 195 195 goto end_with_name; 196 196 197 197 size_t value_size = mark_end.offset - mark_start.offset; 198 198 if (size_limit > 0 && (name_size + value_size) > size_limit) { … … 200 200 goto end_with_name; 201 201 } 202 202 203 203 char *value = NULL; 204 204 rc = recv_cut_str(rb, &mark_start, &mark_end, &value); 205 205 if (rc != EOK) 206 206 goto end_with_name; 207 207 208 208 if (out_bytes_used) 209 209 *out_bytes_used = name_size + value_size; 210 210 211 211 header->name = name; 212 212 header->value = value; … … 228 228 size_t read_index = 0; 229 229 size_t write_index = 0; 230 230 231 231 while (is_lws(value[read_index])) read_index++; 232 232 233 233 while (value[read_index] != 0) { 234 234 if (is_lws(value[read_index])) { 235 235 while (is_lws(value[read_index])) read_index++; 236 236 237 237 if (value[read_index] != 0) 238 238 value[write_index++] = ' '; 239 239 240 240 continue; 241 241 } 242 242 243 243 value[write_index++] = value[read_index++]; 244 244 } 245 245 246 246 value[write_index] = 0; 247 247 } … … 266 266 if (!http_header_name_match(header->name, name)) 267 267 continue; 268 268 269 269 if (found == NULL) { 270 270 found = header; … … 274 274 } 275 275 } 276 276 277 277 if (found == NULL) 278 278 return HTTP_EMISSING_HEADER; 279 279 280 280 *out_header = found; 281 281 return EOK; … … 288 288 if (header == NULL) 289 289 return ENOMEM; 290 290 291 291 http_headers_append_header(headers, header); 292 292 return EOK; … … 300 300 if (rc != EOK && rc != HTTP_EMISSING_HEADER) 301 301 return rc; 302 302 303 303 if (rc == HTTP_EMISSING_HEADER) 304 304 return http_headers_append(headers, name, value); 305 305 306 306 char *new_value = str_dup(value); 307 307 if (new_value == NULL) 308 308 return ENOMEM; 309 309 310 310 free(header->value); 311 311 header->value = new_value; … … 319 319 if (rc != EOK) 320 320 return rc; 321 321 322 322 *value = header->value; 323 323 return EOK; … … 329 329 errno_t rc = EOK; 330 330 unsigned added = 0; 331 331 332 332 while (true) { 333 333 char c = 0; … … 335 335 if (rc != EOK) 336 336 goto error; 337 337 338 338 if (c == '\n' || c == '\r') 339 339 break; 340 340 341 341 if (limit_count > 0 && added >= limit_count) { 342 342 rc = ELIMIT; 343 343 goto error; 344 344 } 345 345 346 346 http_header_t *header = malloc(sizeof(http_header_t)); 347 347 if (header == NULL) { … … 350 350 } 351 351 http_header_init(header); 352 352 353 353 size_t header_size; 354 354 rc = http_header_receive(rb, header, limit_alloc, &header_size); … … 358 358 } 359 359 limit_alloc -= header_size; 360 360 361 361 http_headers_append_header(headers, header); 362 362 added++; 363 363 } 364 364 365 365 return EOK; 366 366 error:
Note:
See TracChangeset
for help on using the changeset viewer.