fixed a memory leak bug caused when the duplicated host name is an address.
fixed wrong redirection code processing bug in rewriting handler. fixed a bug of not setting the default port when no port is specfied in rewritten url address
This commit is contained in:
parent
1f96cd45ab
commit
ffce4c94aa
@ -1947,13 +1947,20 @@ printf ("XXXXXXXXXXXXXXXXXXXXXXXXXX URL REWRITTEN TO [%s].....\n", new_url);
|
|||||||
{
|
{
|
||||||
/* if a network address is returned, change the peer address only */
|
/* if a network address is returned, change the peer address only */
|
||||||
/* TODO: prevent proxying to self */
|
/* TODO: prevent proxying to self */
|
||||||
|
|
||||||
|
if (qse_getnwadport(&nwad) == 0)
|
||||||
|
{
|
||||||
|
/* i don't care if new_url is X.X.X.X:0 or just X.X.X.X */
|
||||||
|
qse_setnwadport (&nwad, qse_hton16(QSE_HTTPD_DEFAULT_PORT));
|
||||||
|
}
|
||||||
|
|
||||||
proxy->peer.nwad = nwad;
|
proxy->peer.nwad = nwad;
|
||||||
proxy->flags |= PROXY_URL_REWRITTEN;
|
proxy->flags |= PROXY_URL_REWRITTEN;
|
||||||
proxy->flags &= ~PROXY_RESOLVE_PEER_NAME; /* skip dns */
|
proxy->flags &= ~PROXY_RESOLVE_PEER_NAME; /* skip dns */
|
||||||
}
|
}
|
||||||
else if (new_url[0] >= QSE_MT('0') && new_url[0] <= QSE_MT('9'))
|
else if (new_url[0] >= QSE_MT('0') && new_url[0] <= QSE_MT('9'))
|
||||||
{
|
{
|
||||||
/* redirection */
|
/* check if it begins with redirection code followed by a colon */
|
||||||
int redir_code = 0;
|
int redir_code = 0;
|
||||||
qse_httpd_status_reloc_t reloc;
|
qse_httpd_status_reloc_t reloc;
|
||||||
const qse_mchar_t* nuptr = new_url;
|
const qse_mchar_t* nuptr = new_url;
|
||||||
@ -1963,7 +1970,11 @@ printf ("XXXXXXXXXXXXXXXXXXXXXXXXXX URL REWRITTEN TO [%s].....\n", new_url);
|
|||||||
nuptr++;
|
nuptr++;
|
||||||
}
|
}
|
||||||
while (*nuptr >= QSE_MT('0') && *nuptr <= QSE_MT('9'));
|
while (*nuptr >= QSE_MT('0') && *nuptr <= QSE_MT('9'));
|
||||||
if (*nuptr != QSE_MT(':')) goto fail;
|
if (*nuptr != QSE_MT(':'))
|
||||||
|
{
|
||||||
|
/* no colon is found after digits. it's probably a normal url */
|
||||||
|
goto normal_url;
|
||||||
|
}
|
||||||
if (redir_code != 301 && redir_code != 302 && redir_code != 307) redir_code = 301;
|
if (redir_code != 301 && redir_code != 302 && redir_code != 307) redir_code = 301;
|
||||||
nuptr++;
|
nuptr++;
|
||||||
|
|
||||||
@ -1981,6 +1992,7 @@ printf ("XXXXXXXXXXXXXXXXXXXXXXXXXX URL REWRITTEN TO [%s].....\n", new_url);
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
normal_url:
|
||||||
if (proxy->flags & PROXY_RAW)
|
if (proxy->flags & PROXY_RAW)
|
||||||
{
|
{
|
||||||
qse_mchar_t* tmp;
|
qse_mchar_t* tmp;
|
||||||
@ -2042,6 +2054,12 @@ printf ("XXXXXXXXXXXXXXXXXXXXXXXXXX URL REWRITTEN TO [%s].....\n", new_url);
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (qse_getnwadport(&nwad) == 0)
|
||||||
|
{
|
||||||
|
/* i don't care if tmp is X.X.X.X:0 or just X.X.X.X */
|
||||||
|
qse_setnwadport (&nwad, qse_hton16(QSE_HTTPD_DEFAULT_PORT));
|
||||||
|
}
|
||||||
|
|
||||||
proxy->peer.nwad = nwad;
|
proxy->peer.nwad = nwad;
|
||||||
proxy->flags |= PROXY_URL_REWRITTEN;
|
proxy->flags |= PROXY_URL_REWRITTEN;
|
||||||
proxy->flags &= ~PROXY_RESOLVE_PEER_NAME; /* skip dns */
|
proxy->flags &= ~PROXY_RESOLVE_PEER_NAME; /* skip dns */
|
||||||
@ -2050,6 +2068,9 @@ qse_mchar_t xxxx[128];
|
|||||||
qse_nwadtombs (&proxy->peer.nwad, xxxx, 128, QSE_NWADTOMBS_ALL);
|
qse_nwadtombs (&proxy->peer.nwad, xxxx, 128, QSE_NWADTOMBS_ALL);
|
||||||
printf ("XXXXXXXXXXXXXXXXXXXXXXXXXX PEER NAME RESOLVED.....TO [%s] IN URLREWRITING NEW_URL[%s] %d %d\n", xxxx, new_url, (int)proxy->qpath_pos_in_reqfwdbuf, (int)proxy->qpath_len_in_reqfwdbuf);
|
printf ("XXXXXXXXXXXXXXXXXXXXXXXXXX PEER NAME RESOLVED.....TO [%s] IN URLREWRITING NEW_URL[%s] %d %d\n", xxxx, new_url, (int)proxy->qpath_pos_in_reqfwdbuf, (int)proxy->qpath_len_in_reqfwdbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* the temporary string is not used. kill it */
|
||||||
|
qse_httpd_freemem (httpd, tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,8 @@ static qse_httpd_client_t* new_client (qse_httpd_t* httpd, qse_httpd_client_t* t
|
|||||||
/* copy the public fields,
|
/* copy the public fields,
|
||||||
* keep the private fields initialized at 0 */
|
* keep the private fields initialized at 0 */
|
||||||
client->status = tmpl->status;
|
client->status = tmpl->status;
|
||||||
if (httpd->opt.scb.client.accepted == QSE_NULL) client->status |= QSE_HTTPD_CLIENT_READY;
|
if (httpd->opt.scb.client.accepted == QSE_NULL)
|
||||||
|
client->status |= QSE_HTTPD_CLIENT_READY;
|
||||||
client->handle = tmpl->handle;
|
client->handle = tmpl->handle;
|
||||||
client->handle2 = tmpl->handle2;
|
client->handle2 = tmpl->handle2;
|
||||||
client->remote_addr = tmpl->remote_addr;
|
client->remote_addr = tmpl->remote_addr;
|
||||||
@ -610,6 +611,21 @@ static void move_client_to_tail (qse_httpd_t* httpd, qse_httpd_client_t* client)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
static int is_client_allowed (qse_httpd_t* httpd, qse_httpd_client_t* client)
|
||||||
|
{
|
||||||
|
qse_httpd_mod_t* mod;
|
||||||
|
|
||||||
|
/* TODO: no sequential search. speed up */
|
||||||
|
for (mod = httpd->modlist; mod; mod = mod->next)
|
||||||
|
{
|
||||||
|
if (mod->new_client) mod->new_client (httpd, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int accept_client (
|
static int accept_client (
|
||||||
qse_httpd_t* httpd, void* mux, qse_ubi_t handle, int mask, void* cbarg)
|
qse_httpd_t* httpd, void* mux, qse_ubi_t handle, int mask, void* cbarg)
|
||||||
{
|
{
|
||||||
@ -642,6 +658,14 @@ qse_printf (QSE_T("failed to accept from server [%s] [%d]\n"), tmp, server->hand
|
|||||||
if (server->dope.flags & QSE_HTTPD_SERVER_SECURE) clibuf.status |= QSE_HTTPD_CLIENT_SECURE;
|
if (server->dope.flags & QSE_HTTPD_SERVER_SECURE) clibuf.status |= QSE_HTTPD_CLIENT_SECURE;
|
||||||
clibuf.server = server;
|
clibuf.server = server;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (is_client_allowed (httpd, &clibuf) <= -1)
|
||||||
|
{
|
||||||
|
httpd->opt.scb.client.close (httpd, &clibuf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
client = new_client (httpd, &clibuf);
|
client = new_client (httpd, &clibuf);
|
||||||
if (client == QSE_NULL)
|
if (client == QSE_NULL)
|
||||||
{
|
{
|
||||||
@ -649,9 +673,6 @@ qse_printf (QSE_T("failed to accept from server [%s] [%d]\n"), tmp, server->hand
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
printf ("MUX ADDHND CLIENT READ %d\n", client->handle.i);
|
|
||||||
#endif
|
|
||||||
if (httpd->opt.scb.mux.addhnd (httpd, mux, client->handle, QSE_HTTPD_MUX_READ, client) <= -1)
|
if (httpd->opt.scb.mux.addhnd (httpd, mux, client->handle, QSE_HTTPD_MUX_READ, client) <= -1)
|
||||||
{
|
{
|
||||||
free_client (httpd, client);
|
free_client (httpd, client);
|
||||||
@ -682,6 +703,7 @@ printf ("MUX ADDHND CLIENT READ %d\n", client->handle.i);
|
|||||||
httpd->opt.rcb.logact (httpd, &msg);
|
httpd->opt.rcb.logact (httpd, &msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user