Changeset cbfc8b7 in mainline
- Timestamp:
- 2013-10-05T20:49:27Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4f086417
- Parents:
- c42f50d
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/download/main.c
rc42f50d rcbfc8b7 171 171 172 172 http_response_t *response = NULL; 173 rc = http_receive_response(&http->recv_buffer, &response); 173 rc = http_receive_response(&http->recv_buffer, &response, 16 * 1024, 174 100); 174 175 if (rc != EOK) { 175 176 fprintf(stderr, "Failed receiving response: %s\n", str_error(rc)); -
uspace/lib/http/include/http/http.h
rc42f50d rcbfc8b7 88 88 extern void http_header_init(http_header_t *); 89 89 extern http_header_t *http_header_create(const char *, const char *); 90 extern int http_header_receive_name(receive_buffer_t *, char **); 91 extern int http_header_receive_value(receive_buffer_t *, char **); 92 extern int http_header_receive(receive_buffer_t *, http_header_t *); 90 extern int http_header_receive_name(receive_buffer_t *, receive_buffer_mark_t *); 91 extern int http_header_receive_value(receive_buffer_t *, receive_buffer_mark_t *, 92 receive_buffer_mark_t *); 93 extern int http_header_receive(receive_buffer_t *, http_header_t *, size_t, 94 size_t *); 93 95 extern void http_header_normalize_value(char *); 94 96 extern bool http_header_name_match(const char *, const char *); … … 102 104 extern int http_headers_set(http_headers_t *, const char *, const char *); 103 105 extern int http_headers_get(http_headers_t *, const char *, char **); 104 extern int http_headers_receive(receive_buffer_t *, http_headers_t *); 106 extern int http_headers_receive(receive_buffer_t *, http_headers_t *, size_t, 107 unsigned); 105 108 extern void http_headers_clear(http_headers_t *); 106 109 … … 126 129 extern int http_receive_status(receive_buffer_t *, http_version_t *, uint16_t *, 127 130 char **); 128 extern int http_receive_response(receive_buffer_t *, http_response_t **); 131 extern int http_receive_response(receive_buffer_t *, http_response_t **, 132 size_t, unsigned); 129 133 extern void http_response_destroy(http_response_t *); 130 134 extern int http_close(http_t *); -
uspace/lib/http/src/headers.c
rc42f50d rcbfc8b7 94 94 } 95 95 96 int http_header_receive_name(receive_buffer_t *rb, char **out_name) 97 { 98 receive_buffer_mark_t name_start; 99 receive_buffer_mark_t name_end; 100 101 recv_mark(rb, &name_start); 102 recv_mark(rb, &name_end); 103 96 int http_header_receive_name(receive_buffer_t *rb, 97 receive_buffer_mark_t *name_end) 98 { 104 99 char c = 0; 105 100 do { 106 recv_mark_update(rb, &name_end); 101 if (name_end) 102 recv_mark_update(rb, name_end); 107 103 108 104 int rc = recv_char(rb, &c, true); 109 if (rc != EOK) { 110 recv_unmark(rb, &name_start); 111 recv_unmark(rb, &name_end); 112 return rc; 113 } 105 if (rc != EOK) 106 return rc; 114 107 } while (is_token(c)); 115 108 116 if (c != ':') { 117 recv_unmark(rb, &name_start); 118 recv_unmark(rb, &name_end); 109 if (c != ':') 119 110 return EINVAL; 120 } 121 122 char *name = NULL; 123 int rc = recv_cut_str(rb, &name_start, &name_end, &name); 124 recv_unmark(rb, &name_start); 125 recv_unmark(rb, &name_end); 126 if (rc != EOK) 127 return rc; 128 129 *out_name = name; 130 return EOK; 131 } 132 133 int http_header_receive_value(receive_buffer_t *rb, char **out_value) 111 112 return EOK; 113 } 114 115 int http_header_receive_value(receive_buffer_t *rb, 116 receive_buffer_mark_t *value_start, receive_buffer_mark_t *value_end) 134 117 { 135 118 int rc = EOK; 136 119 char c = 0; 137 120 138 receive_buffer_mark_t value_start;139 recv_mark(rb, &value_start);140 141 121 /* Ignore any inline LWS */ 142 122 while (true) { 143 recv_mark_update(rb, &value_start); 123 if (value_start) 124 recv_mark_update(rb, value_start); 125 144 126 rc = recv_char(rb, &c, false); 145 127 if (rc != EOK) 146 goto error;128 return rc; 147 129 148 130 if (c != ' ' && c != '\t') … … 151 133 rc = recv_char(rb, &c, true); 152 134 if (rc != EOK) 153 goto error; 154 } 155 156 receive_buffer_mark_t value_end; 157 recv_mark(rb, &value_end); 135 return rc; 136 } 158 137 159 138 while (true) { 160 recv_mark_update(rb, &value_end);139 recv_mark_update(rb, value_end); 161 140 162 141 rc = recv_char(rb, &c, true); 163 142 if (rc != EOK) 164 goto error_end;143 return rc; 165 144 166 145 if (c != '\r' && c != '\n') … … 169 148 rc = recv_discard(rb, (c == '\r' ? '\n' : '\r')); 170 149 if (rc < 0) 171 goto error_end;150 return rc; 172 151 173 152 rc = recv_char(rb, &c, false); 174 153 if (rc != EOK) 175 goto error_end;154 return rc; 176 155 177 156 if (c != ' ' && c != '\t') … … 181 160 rc = recv_char(rb, &c, true); 182 161 if (rc != EOK) 183 goto error_end; 162 return rc; 163 } 164 165 return EOK; 166 } 167 168 int http_header_receive(receive_buffer_t *rb, http_header_t *header, 169 size_t size_limit, size_t *out_bytes_used) 170 { 171 receive_buffer_mark_t mark_start; 172 receive_buffer_mark_t mark_end; 173 174 recv_mark(rb, &mark_start); 175 recv_mark(rb, &mark_end); 176 177 int rc = http_header_receive_name(rb, &mark_end); 178 if (rc != EOK) 179 goto end; 180 181 size_t name_size = mark_end.offset - mark_start.offset; 182 if (size_limit > 0 && name_size > size_limit) { 183 rc = ELIMIT; 184 goto end; 185 } 186 187 char *name = NULL; 188 rc = recv_cut_str(rb, &mark_start, &mark_end, &name); 189 if (rc != EOK) 190 goto end; 191 192 rc = http_header_receive_value(rb, &mark_start, &mark_end); 193 if (rc != EOK) 194 goto end_with_name; 195 196 size_t value_size = mark_end.offset - mark_start.offset; 197 if (size_limit > 0 && (name_size + value_size) > size_limit) { 198 rc = ELIMIT; 199 goto end_with_name; 184 200 } 185 201 186 202 char *value = NULL; 187 rc = recv_cut_str(rb, &value_start, &value_end, &value); 188 recv_unmark(rb, &value_start); 189 recv_unmark(rb, &value_end); 190 if (rc != EOK) 191 return rc; 192 193 *out_value = value; 194 return EOK; 195 error_end: 196 recv_unmark(rb, &value_end); 197 error: 198 recv_unmark(rb, &value_start); 199 return rc; 200 } 201 202 int http_header_receive(receive_buffer_t *rb, http_header_t *header) 203 { 204 char *name = NULL; 205 int rc = http_header_receive_name(rb, &name); 206 if (rc != EOK) { 207 return rc; 208 } 209 210 char *value = NULL; 211 rc = http_header_receive_value(rb, &value); 212 if (rc != EOK) { 213 free(name); 214 return rc; 215 } 203 rc = recv_cut_str(rb, &mark_start, &mark_end, &value); 204 if (rc != EOK) 205 goto end_with_name; 206 207 if (out_bytes_used) 208 *out_bytes_used = name_size + value_size; 216 209 217 210 header->name = name; 218 211 header->value = value; 219 return EOK; 212 goto end; 213 end_with_name: 214 free(name); 215 end: 216 recv_unmark(rb, &mark_start); 217 recv_unmark(rb, &mark_end); 218 return rc; 220 219 } 221 220 … … 324 323 } 325 324 326 int http_headers_receive(receive_buffer_t *rb, http_headers_t *headers) 325 int http_headers_receive(receive_buffer_t *rb, http_headers_t *headers, 326 size_t limit_alloc, unsigned limit_count) 327 327 { 328 328 int rc = EOK; … … 337 337 if (c == '\n' || c == '\r') 338 338 break; 339 340 if (limit_count > 0 && added >= limit_count) { 341 rc = ELIMIT; 342 goto error; 343 } 339 344 340 345 http_header_t *header = malloc(sizeof(http_header_t)); … … 345 350 http_header_init(header); 346 351 347 rc = http_header_receive(rb, header); 352 size_t header_size; 353 rc = http_header_receive(rb, header, limit_alloc, &header_size); 348 354 if (rc != EOK) { 349 355 free(header); 350 356 goto error; 351 357 } 358 limit_alloc -= header_size; 352 359 353 360 http_headers_append_header(headers, header); -
uspace/lib/http/src/response.c
rc42f50d rcbfc8b7 185 185 } 186 186 187 int http_receive_response(receive_buffer_t *rb, http_response_t **out_response) 187 int http_receive_response(receive_buffer_t *rb, http_response_t **out_response, 188 size_t max_headers_size, unsigned max_headers_count) 188 189 { 189 190 http_response_t *resp = malloc(sizeof(http_response_t)); … … 198 199 goto error; 199 200 200 rc = http_headers_receive(rb, &resp->headers); 201 rc = http_headers_receive(rb, &resp->headers, max_headers_size, 202 max_headers_count); 201 203 if (rc != EOK) 202 204 goto error;
Note:
See TracChangeset
for help on using the changeset viewer.