Kaynağa Gözat

[http] Disambiguate the various error causes

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 yıl önce
ebeveyn
işleme
b9720e4ebf
1 değiştirilmiş dosya ile 45 ekleme ve 13 silme
  1. 45
    13
      src/net/tcp/httpcore.c

+ 45
- 13
src/net/tcp/httpcore.c Dosyayı Görüntüle

47
 #include <ipxe/acpi.h>
47
 #include <ipxe/acpi.h>
48
 #include <ipxe/http.h>
48
 #include <ipxe/http.h>
49
 
49
 
50
+/* Disambiguate the various error causes */
51
+#define EACCES_401 __einfo_error ( EINFO_EACCES_401 )
52
+#define EINFO_EACCES_401 \
53
+	__einfo_uniqify ( EINFO_EACCES, 0x01, "HTTP 401 Unauthorized" )
54
+#define EIO_OTHER __einfo_error ( EINFO_EIO_OTHER )
55
+#define EINFO_EIO_OTHER \
56
+	__einfo_uniqify ( EINFO_EIO, 0x01, "Unrecognised HTTP response code" )
57
+#define EIO_CONTENT_LENGTH __einfo_error ( EINFO_EIO_CONTENT_LENGTH )
58
+#define EINFO_EIO_CONTENT_LENGTH \
59
+	__einfo_uniqify ( EINFO_EIO, 0x02, "Content length mismatch" )
60
+#define EINVAL_RESPONSE __einfo_error ( EINFO_EINVAL_RESPONSE )
61
+#define EINFO_EINVAL_RESPONSE \
62
+	__einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid content length" )
63
+#define EINVAL_HEADER __einfo_error ( EINFO_EINVAL_HEADER )
64
+#define EINFO_EINVAL_HEADER \
65
+	__einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid header" )
66
+#define EINVAL_CONTENT_LENGTH __einfo_error ( EINFO_EINVAL_CONTENT_LENGTH )
67
+#define EINFO_EINVAL_CONTENT_LENGTH \
68
+	__einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid content length" )
69
+#define EINVAL_CHUNK_LENGTH __einfo_error ( EINFO_EINVAL_CHUNK_LENGTH )
70
+#define EINFO_EINVAL_CHUNK_LENGTH \
71
+	__einfo_uniqify ( EINFO_EINVAL, 0x04, "Invalid chunk length" )
72
+#define ENOENT_404 __einfo_error ( EINFO_ENOENT_404 )
73
+#define EINFO_ENOENT_404 \
74
+	__einfo_uniqify ( EINFO_ENOENT, 0x01, "HTTP 404 Not Found" )
75
+#define EPERM_403 __einfo_error ( EINFO_EPERM_403 )
76
+#define EINFO_EPERM_403 \
77
+	__einfo_uniqify ( EINFO_EPERM, 0x01, "HTTP 403 Forbidden" )
78
+#define EPROTO_UNSOLICITED __einfo_error ( EINFO_EPROTO_UNSOLICITED )
79
+#define EINFO_EPROTO_UNSOLICITED \
80
+	__einfo_uniqify ( EINFO_EPROTO, 0x01, "Unsolicited data" )
81
+
50
 /** Block size used for HTTP block device request */
82
 /** Block size used for HTTP block device request */
51
 #define HTTP_BLKSIZE 512
83
 #define HTTP_BLKSIZE 512
52
 
84
 
146
 		DBGC ( http, "HTTP %p incorrect length %zd, should be %zd\n",
178
 		DBGC ( http, "HTTP %p incorrect length %zd, should be %zd\n",
147
 		       http, http->rx_len, ( http->rx_len + http->remaining ) );
179
 		       http, http->rx_len, ( http->rx_len + http->remaining ) );
148
 		if ( rc == 0 )
180
 		if ( rc == 0 )
149
-			rc = -EIO;
181
+			rc = -EIO_CONTENT_LENGTH;
150
 	}
182
 	}
151
 
183
 
152
 	/* Remove process */
184
 	/* Remove process */
169
 	 * isn't correct, force an error
201
 	 * isn't correct, force an error
170
 	 */
202
 	 */
171
 	if ( http->remaining != 0 ) {
203
 	if ( http->remaining != 0 ) {
172
-		http_close ( http, -EIO );
204
+		http_close ( http, -EIO_CONTENT_LENGTH );
173
 		return;
205
 		return;
174
 	}
206
 	}
175
 
207
 
203
 	case 303:
235
 	case 303:
204
 		return 0;
236
 		return 0;
205
 	case 404:
237
 	case 404:
206
-		return -ENOENT;
238
+		return -ENOENT_404;
207
 	case 403:
239
 	case 403:
208
-		return -EPERM;
240
+		return -EPERM_403;
209
 	case 401:
241
 	case 401:
210
-		return -EACCES;
242
+		return -EACCES_401;
211
 	default:
243
 	default:
212
-		return -EIO;
244
+		return -EIO_OTHER;
213
 	}
245
 	}
214
 }
246
 }
215
 
247
 
229
 
261
 
230
 	/* Check response starts with "HTTP/" */
262
 	/* Check response starts with "HTTP/" */
231
 	if ( strncmp ( response, "HTTP/", 5 ) != 0 )
263
 	if ( strncmp ( response, "HTTP/", 5 ) != 0 )
232
-		return -EIO;
264
+		return -EINVAL_RESPONSE;
233
 
265
 
234
 	/* Locate and check response code */
266
 	/* Locate and check response code */
235
 	spc = strchr ( response, ' ' );
267
 	spc = strchr ( response, ' ' );
236
 	if ( ! spc )
268
 	if ( ! spc )
237
-		return -EIO;
269
+		return -EINVAL_RESPONSE;
238
 	code = strtoul ( spc, NULL, 10 );
270
 	code = strtoul ( spc, NULL, 10 );
239
 	if ( ( rc = http_response_to_rc ( code ) ) != 0 )
271
 	if ( ( rc = http_response_to_rc ( code ) ) != 0 )
240
 		return rc;
272
 		return rc;
284
 	if ( *endp != '\0' ) {
316
 	if ( *endp != '\0' ) {
285
 		DBGC ( http, "HTTP %p invalid Content-Length \"%s\"\n",
317
 		DBGC ( http, "HTTP %p invalid Content-Length \"%s\"\n",
286
 		       http, value );
318
 		       http, value );
287
-		return -EIO;
319
+		return -EINVAL_CONTENT_LENGTH;
288
 	}
320
 	}
289
 
321
 
290
 	/* If we already have an expected content length, and this
322
 	/* If we already have an expected content length, and this
293
 	if ( http->remaining && ( http->remaining != content_len ) ) {
325
 	if ( http->remaining && ( http->remaining != content_len ) ) {
294
 		DBGC ( http, "HTTP %p incorrect Content-Length %zd (expected "
326
 		DBGC ( http, "HTTP %p incorrect Content-Length %zd (expected "
295
 		       "%zd)\n", http, content_len, http->remaining );
327
 		       "%zd)\n", http, content_len, http->remaining );
296
-		return -EIO;
328
+		return -EIO_CONTENT_LENGTH;
297
 	}
329
 	}
298
 	if ( ! ( http->flags & HTTP_HEAD_ONLY ) )
330
 	if ( ! ( http->flags & HTTP_HEAD_ONLY ) )
299
 		http->remaining = content_len;
331
 		http->remaining = content_len;
397
 	separator = strstr ( header, ": " );
429
 	separator = strstr ( header, ": " );
398
 	if ( ! separator ) {
430
 	if ( ! separator ) {
399
 		DBGC ( http, "HTTP %p malformed header\n", http );
431
 		DBGC ( http, "HTTP %p malformed header\n", http );
400
-		return -EIO;
432
+		return -EINVAL_HEADER;
401
 	}
433
 	}
402
 	*separator = '\0';
434
 	*separator = '\0';
403
 	value = ( separator + 2 );
435
 	value = ( separator + 2 );
432
 	if ( *endp != '\0' ) {
464
 	if ( *endp != '\0' ) {
433
 		DBGC ( http, "HTTP %p invalid chunk length \"%s\"\n",
465
 		DBGC ( http, "HTTP %p invalid chunk length \"%s\"\n",
434
 		       http, length );
466
 		       http, length );
435
-		return -EIO;
467
+		return -EINVAL_CHUNK_LENGTH;
436
 	}
468
 	}
437
 
469
 
438
 	/* Terminate chunked encoding if applicable */
470
 	/* Terminate chunked encoding if applicable */
500
 			       http, iob_len ( iobuf ),
532
 			       http, iob_len ( iobuf ),
501
 			       ( ( http->rx_state == HTTP_RX_IDLE ) ?
533
 			       ( ( http->rx_state == HTTP_RX_IDLE ) ?
502
 				 "idle" : "dead" ) );
534
 				 "idle" : "dead" ) );
503
-			rc = -EPROTO;
535
+			rc = -EPROTO_UNSOLICITED;
504
 			goto done;
536
 			goto done;
505
 		case HTTP_RX_DEAD:
537
 		case HTTP_RX_DEAD:
506
 			/* Do no further processing */
538
 			/* Do no further processing */

Loading…
İptal
Kaydet