added a new root type for httpd - <XXX> where XXX is a relocation code or an error code
This commit is contained in:
		| @ -1414,7 +1414,7 @@ printf ("task_main_cgi_2 trigger[0].mask=%d trigger[1].mask=%d cmask=%d\n", | ||||
| 	return 1; | ||||
|  | ||||
| oops: | ||||
| 	return (qse_httpd_entask_err (httpd, client, task, 500, cgi->method, &cgi->version, cgi->keepalive) == QSE_NULL)? -1: 0; | ||||
| 	return (qse_httpd_entask_error (httpd, client, task, 500, cgi->method, &cgi->version, cgi->keepalive) == QSE_NULL)? -1: 0; | ||||
| } | ||||
|  | ||||
| static int task_main_cgi ( | ||||
| @ -1578,7 +1578,7 @@ oops: | ||||
| 		cgi->script_htrd = QSE_NULL; | ||||
| 	} | ||||
|  | ||||
| 	return (qse_httpd_entask_err ( | ||||
| 	return (qse_httpd_entask_error ( | ||||
| 		httpd, client, task, http_errnum,  | ||||
| 		cgi->method, &cgi->version, cgi->keepalive) == QSE_NULL)? -1: 0; | ||||
| } | ||||
|  | ||||
| @ -586,7 +586,7 @@ qse_httpd_task_t* qse_httpd_entaskdir ( | ||||
| 				int status; | ||||
| 				status = (httpd->errnum == QSE_HTTPD_ENOENT)? 404: | ||||
| 					    (httpd->errnum == QSE_HTTPD_EACCES)? 403: 500; | ||||
| 				return qse_httpd_entaskerr (httpd, client, pred, status, req); | ||||
| 				return qse_httpd_entaskerror (httpd, client, pred, status, req); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| @ -643,7 +643,7 @@ qse_httpd_task_t* qse_httpd_entaskdir ( | ||||
| 				} | ||||
| 			} | ||||
| 				 | ||||
| 			return qse_httpd_entaskerr (httpd, client, pred, status, req); | ||||
| 			return qse_httpd_entaskerror (httpd, client, pred, status, req); | ||||
| 		} | ||||
|  | ||||
|  | ||||
| @ -657,11 +657,11 @@ qse_httpd_task_t* qse_httpd_entaskdir ( | ||||
| 				         (httpd->errnum == QSE_HTTPD_EACCES)? 403: 500; | ||||
| 			} | ||||
|  | ||||
| 			return qse_httpd_entaskerr (httpd, client, pred, status, req); | ||||
| 			return qse_httpd_entaskerror (httpd, client, pred, status, req); | ||||
| 		} | ||||
|  | ||||
| 		default: | ||||
| 			/* Method not allowed */ | ||||
| 			return qse_httpd_entaskerr (httpd, client, pred, 405, req); | ||||
| 			return qse_httpd_entaskerror (httpd, client, pred, 405, req); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -191,7 +191,7 @@ static QSE_INLINE int task_main_getfile ( | ||||
| 		int http_errnum; | ||||
| 		http_errnum = (httpd->errnum == QSE_HTTPD_ENOENT)? 404: | ||||
| 		              (httpd->errnum == QSE_HTTPD_EACCES)? 403: 500; | ||||
| 		x = qse_httpd_entask_err ( | ||||
| 		x = qse_httpd_entask_error ( | ||||
| 			httpd, client, x, http_errnum,  | ||||
| 			file->method, &file->version, file->keepalive); | ||||
| 		goto no_file_send; | ||||
| @ -203,7 +203,7 @@ static QSE_INLINE int task_main_getfile ( | ||||
| 		int http_errnum; | ||||
| 		http_errnum = (httpd->errnum == QSE_HTTPD_ENOENT)? 404: | ||||
| 		              (httpd->errnum == QSE_HTTPD_EACCES)? 403: 500; | ||||
| 		x = qse_httpd_entask_err ( | ||||
| 		x = qse_httpd_entask_error ( | ||||
| 			httpd, client, x, http_errnum,  | ||||
| 			file->method, &file->version, file->keepalive); | ||||
| 		goto no_file_send; | ||||
| @ -226,7 +226,7 @@ static QSE_INLINE int task_main_getfile ( | ||||
|  | ||||
| 		if (file->u.get.range.from >= st.size) | ||||
| 		{ | ||||
| 			x = qse_httpd_entask_err ( | ||||
| 			x = qse_httpd_entask_error ( | ||||
| 				httpd, client, x, 416, file->method, &file->version, file->keepalive); | ||||
| 			goto no_file_send; | ||||
| 		} | ||||
| @ -491,7 +491,7 @@ static int task_main_putfile_2 ( | ||||
|  | ||||
| 	/* snatching is over. writing error may have occurred as well. | ||||
| 	 * file->u.put.status should hold a proper status code */ | ||||
| 	if (qse_httpd_entask_err ( | ||||
| 	if (qse_httpd_entask_error ( | ||||
| 		httpd, client, task, file->u.put.status, | ||||
| 		file->method, &file->version, file->keepalive) == QSE_NULL) return -1; | ||||
| 	return 0; /* no more data to read. task over */ | ||||
| @ -516,7 +516,7 @@ static int task_main_putfile ( | ||||
| 	 * note: if initialization error occurred and there is contents for the | ||||
| 	 * client to send, this reply may get to the client before it finishes  | ||||
| 	 * sending the contents. */ | ||||
| 	if (qse_httpd_entask_err ( | ||||
| 	if (qse_httpd_entask_error ( | ||||
| 		httpd, client, task, file->u.put.status, | ||||
| 		file->method, &file->version, file->keepalive) == QSE_NULL) return -1; | ||||
| 	return 0; /* task over */ | ||||
| @ -603,7 +603,7 @@ qse_httpd_task_t* qse_httpd_entaskfile ( | ||||
| 				/*while (tmp->next) tmp = tmp->next;*/ /* get the last value */ | ||||
| 				if (qse_parsehttprange (tmp->ptr, &data.u.get.range) <= -1) | ||||
| 				{ | ||||
| 					return qse_httpd_entaskerr (httpd, client, pred, 416, req); | ||||
| 					return qse_httpd_entaskerror (httpd, client, pred, 416, req); | ||||
| 				} | ||||
| 			} | ||||
| 			else  | ||||
| @ -638,13 +638,13 @@ qse_httpd_task_t* qse_httpd_entaskfile ( | ||||
| 				         (httpd->errnum == QSE_HTTPD_EACCES)? 403: 500; | ||||
| 			} | ||||
| 				 | ||||
| 			return qse_httpd_entaskerr (httpd, client, pred, status, req); | ||||
| 			return qse_httpd_entaskerror (httpd, client, pred, status, req); | ||||
| 		} | ||||
|  | ||||
| 		default: | ||||
| 			/* Method not allowed */ | ||||
| 			qse_htre_discardcontent (req); | ||||
| 			return qse_httpd_entaskerr (httpd, client, pred, 405, req); | ||||
| 			return qse_httpd_entaskerror (httpd, client, pred, 405, req); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -1865,7 +1865,7 @@ qse_printf (QSE_T("TRAILING DATA=%d, [%hs]\n"), (int)QSE_MBS_LEN(proxy->res), QS | ||||
|  | ||||
| oops: | ||||
| 	if (proxy->resflags & PROXY_RES_EVER_SENTBACK) return -1; | ||||
| 	return (qse_httpd_entask_err (httpd, client, task, http_errnum, proxy->method, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0; | ||||
| 	return (qse_httpd_entask_error (httpd, client, task, http_errnum, proxy->method, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0; | ||||
| } | ||||
|  | ||||
| static int task_main_proxy_1 ( | ||||
| @ -1958,7 +1958,7 @@ static int task_main_proxy_1 ( | ||||
| 	return 1; | ||||
|  | ||||
| oops: | ||||
| 	return (qse_httpd_entask_err (httpd, client, task, http_errnum, proxy->method, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0; | ||||
| 	return (qse_httpd_entask_error (httpd, client, task, http_errnum, proxy->method, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0; | ||||
| } | ||||
|  | ||||
| static void on_peer_name_resolved (qse_httpd_t* httpd, const qse_mchar_t* name, const qse_nwad_t* nwad, void* ctx) | ||||
| @ -2062,7 +2062,7 @@ printf ("XXXXXXXXXXXXXXXXXXXXXXXXXX URL REWRITTEN TO [%s].....\n", new_url); | ||||
| 			/* relocation code is given explictly, no slash appending is needed. | ||||
| 			 * use qse_httpd_entask_status() rather than qse_httpd_entaskreloc(). */ | ||||
| 			reloc.flags = 0;  | ||||
| 			reloc.dst = nuptr; | ||||
| 			reloc.target = nuptr; | ||||
|  | ||||
| 			if (qse_httpd_entask_status ( | ||||
| 				httpd, proxy->client, proxy->task, redir_code, &reloc, | ||||
| @ -2402,7 +2402,7 @@ oops: | ||||
| 		proxy->peer_htrd = QSE_NULL; | ||||
| 	} | ||||
|  | ||||
| 	return (qse_httpd_entask_err ( | ||||
| 	return (qse_httpd_entask_error ( | ||||
| 		httpd, client, task, http_errnum,  | ||||
| 		proxy->method, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0; | ||||
| } | ||||
|  | ||||
| @ -2189,7 +2189,7 @@ if (qse_htre_getcontentlen(req) > 0) | ||||
| 				/* POST without Content-Length nor not chunked */ | ||||
| 				req->flags &= ~QSE_HTRE_ATTR_KEEPALIVE; | ||||
| 				qse_httpd_discardcontent (httpd, req); | ||||
| 				task = qse_httpd_entaskerr (httpd, client, QSE_NULL, 411, req); | ||||
| 				task = qse_httpd_entaskerror (httpd, client, QSE_NULL, 411, req); | ||||
| 				if (task)  | ||||
| 				{ | ||||
| 					/* 411 Length Required - can't keep alive. Force disconnect */ | ||||
| @ -2204,7 +2204,7 @@ if (qse_htre_getcontentlen(req) > 0) | ||||
| 				 * error code, it should return 0 with the QSE_HTTPD_RSRC_ERROR | ||||
| 				 * resource. */ | ||||
| 				qse_httpd_discardcontent (httpd, req); | ||||
| 				task = qse_httpd_entaskerr (httpd, client, QSE_NULL, 500, req); | ||||
| 				task = qse_httpd_entaskerror (httpd, client, QSE_NULL, 500, req); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| @ -2252,7 +2252,7 @@ printf ("CANOT MAKE RESOURCE.... %s\n", qse_htre_getqpath(req)); | ||||
| 				 * '500 Internal Server Error'. If it wants to return a specific | ||||
| 				 * error code, it should return 0 with the QSE_HTTPD_RSRC_ERROR | ||||
| 				 * resource. */ | ||||
| 				task = qse_httpd_entaskerr (httpd, client, QSE_NULL, 500, req); | ||||
| 				task = qse_httpd_entaskerror (httpd, client, QSE_NULL, 500, req); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| @ -2494,8 +2494,8 @@ static void free_resource ( | ||||
| 			break; | ||||
|  | ||||
| 		case QSE_HTTPD_RSRC_RELOC: | ||||
| 			if (target->u.reloc.dst != qpath) | ||||
| 				QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.reloc.dst); | ||||
| 			if (target->u.reloc.target != qpath) | ||||
| 				QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.reloc.target); | ||||
| 			break; | ||||
|  | ||||
| 		default: | ||||
| @ -2608,8 +2608,8 @@ static int attempt_cgi ( | ||||
| 				/* create a relocation resource */ | ||||
| 				QSE_MEMSET (target, 0, QSE_SIZEOF(*target)); | ||||
| 				target->type = QSE_HTTPD_RSRC_RELOC; | ||||
| 				target->u.reloc.dst = merge_paths (httpd, tmp->qpath, tmp->idxfile); | ||||
| 				if (target->u.reloc.dst == QSE_NULL) goto oops; | ||||
| 				target->u.reloc.target = merge_paths (httpd, tmp->qpath, tmp->idxfile); | ||||
| 				if (target->u.reloc.target == QSE_NULL) goto oops; | ||||
|  | ||||
| 				/* free tmp->xpath here upon success since it's not used for relocation. | ||||
| 				 * upon failure, it is freed by the caller. so the 'oops' part  | ||||
| @ -3022,7 +3022,7 @@ auth_ok: | ||||
| 				qse_htre_discardcontent (req); | ||||
| 				target->type = QSE_HTTPD_RSRC_RELOC; | ||||
| 				target->u.reloc.flags = QSE_HTTPD_RSRC_RELOC_APPENDSLASH | QSE_HTTPD_RSRC_RELOC_PERMANENT; | ||||
| 				target->u.reloc.dst = tmp.qpath; | ||||
| 				target->u.reloc.target = tmp.qpath; | ||||
| 				/* free xpath since it won't be used */ | ||||
| 				QSE_MMGR_FREE (httpd->mmgr, tmp.xpath); | ||||
| 			} | ||||
| @ -3089,8 +3089,8 @@ auth_ok: | ||||
|  | ||||
| 				/* create a relocation resource */ | ||||
| 				target->type = QSE_HTTPD_RSRC_RELOC; | ||||
| 				target->u.reloc.dst = merge_paths (httpd, tmp.qpath, tmp.idxfile); | ||||
| 				if (target->u.reloc.dst == QSE_NULL) return -1; | ||||
| 				target->u.reloc.target = merge_paths (httpd, tmp.qpath, tmp.idxfile); | ||||
| 				if (target->u.reloc.target == QSE_NULL) return -1; | ||||
| 			} | ||||
| 			else if (acc == QSE_HTTPD_SERVERSTD_DIRACC) | ||||
| 			{ | ||||
|  | ||||
| @ -188,7 +188,7 @@ qse_httpd_task_t* qse_httpd_entask_status ( | ||||
| 			reloc = (qse_httpd_rsrc_reloc_t*)extra; | ||||
| 			extrapre = QSE_MT("Location: "); | ||||
| 			extrapst = (reloc->flags & QSE_HTTPD_RSRC_RELOC_APPENDSLASH)? QSE_MT("/\r\n"): QSE_MT("\r\n"); | ||||
| 			extraval = reloc->dst; | ||||
| 			extraval = reloc->target; | ||||
| 			break; | ||||
| 		} | ||||
|  | ||||
| @ -228,7 +228,7 @@ qse_httpd_task_t* qse_httpd_entask_status ( | ||||
| } | ||||
| /*------------------------------------------------------------------------*/ | ||||
|  | ||||
| qse_httpd_task_t* qse_httpd_entask_err ( | ||||
| qse_httpd_task_t* qse_httpd_entask_error ( | ||||
| 	qse_httpd_t* httpd, qse_httpd_client_t* client,  | ||||
| 	qse_httpd_task_t* pred, int code, | ||||
| 	qse_http_method_t method, const qse_http_version_t* version, int keepalive) | ||||
| @ -236,7 +236,7 @@ qse_httpd_task_t* qse_httpd_entask_err ( | ||||
| 	return qse_httpd_entask_status (httpd, client, pred, code, QSE_NULL, method, version, keepalive); | ||||
| } | ||||
|  | ||||
| qse_httpd_task_t* qse_httpd_entaskerr ( | ||||
| qse_httpd_task_t* qse_httpd_entaskerror ( | ||||
| 	qse_httpd_t* httpd, qse_httpd_client_t* client,  | ||||
| 	qse_httpd_task_t* pred, int code, qse_htre_t* req) | ||||
| { | ||||
| @ -384,7 +384,7 @@ qse_httpd_task_t* qse_httpd_entaskrsrc ( | ||||
| 			break; | ||||
|  | ||||
| 		case QSE_HTTPD_RSRC_ERROR: | ||||
| 			task = qse_httpd_entaskerr (httpd, client, pred, rsrc->u.error.code, req); | ||||
| 			task = qse_httpd_entaskerror (httpd, client, pred, rsrc->u.error.code, req); | ||||
| 			break; | ||||
|  | ||||
| 		case QSE_HTTPD_RSRC_FILE: | ||||
|  | ||||
| @ -102,7 +102,7 @@ qse_httpd_task_t* qse_httpd_entasktext ( | ||||
|  | ||||
| 		default: | ||||
| 			/* Method not allowed */ | ||||
| 			return qse_httpd_entaskerr (httpd, client, pred, 405, req); | ||||
| 			return qse_httpd_entaskerror (httpd, client, pred, 405, req); | ||||
| 	} | ||||
|  | ||||
| 	qse_fmtuintmaxtombs (b_tlen, QSE_COUNTOF(b_tlen), tlen, 10, -1, QSE_MT('\0'), QSE_NULL); | ||||
|  | ||||
| @ -131,7 +131,7 @@ qse_httpd_task_t* qse_httpd_entask_status ( | ||||
| 	int keepalive | ||||
| ); | ||||
|  | ||||
| qse_httpd_task_t* qse_httpd_entask_err ( | ||||
| qse_httpd_task_t* qse_httpd_entask_error ( | ||||
| 	qse_httpd_t* httpd, | ||||
| 	qse_httpd_client_t* client, | ||||
| 	qse_httpd_task_t* pred, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user