clean up http support
This commit is contained in:
@@ -571,6 +571,16 @@ struct socket_call {
|
|||||||
struct client *c;
|
struct client *c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
output_data(struct client *c, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
if (c->olen + len < c->olen)
|
||||||
|
abort();
|
||||||
|
c->outmsg = erealloc(c->outmsg, c->olen + len);
|
||||||
|
memcpy(&c->outmsg[c->olen], data, len);
|
||||||
|
c->olen += len;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
socket_complete(heim_sipc_call ctx, int returnvalue, heim_idata *reply)
|
socket_complete(heim_sipc_call ctx, int returnvalue, heim_idata *reply)
|
||||||
{
|
{
|
||||||
@@ -582,31 +592,20 @@ socket_complete(heim_sipc_call ctx, int returnvalue, heim_idata *reply)
|
|||||||
abort();
|
abort();
|
||||||
|
|
||||||
if ((c->flags & WAITING_CLOSE) == 0) {
|
if ((c->flags & WAITING_CLOSE) == 0) {
|
||||||
uint8_t *ptr;
|
|
||||||
uint32_t u32;
|
uint32_t u32;
|
||||||
size_t rlen = reply->length + sizeof(u32);
|
|
||||||
|
|
||||||
if (c->flags & INCLUDE_ERROR_CODE)
|
|
||||||
rlen += sizeof(u32);
|
|
||||||
|
|
||||||
c->outmsg = erealloc(c->outmsg, c->olen + rlen);
|
|
||||||
|
|
||||||
/* length */
|
/* length */
|
||||||
ptr = &c->outmsg[c->olen];
|
|
||||||
u32 = htonl(reply->length);
|
u32 = htonl(reply->length);
|
||||||
memcpy(ptr, &u32, sizeof(u32));
|
output_data(c, &u32, sizeof(u32));
|
||||||
ptr += sizeof(u32);
|
|
||||||
|
|
||||||
/* return value */
|
/* return value */
|
||||||
if (c->flags & INCLUDE_ERROR_CODE) {
|
if (c->flags & INCLUDE_ERROR_CODE) {
|
||||||
u32 = htonl(returnvalue);
|
u32 = htonl(returnvalue);
|
||||||
memcpy(ptr, &u32, sizeof(u32));
|
output_data(c, &u32, sizeof(u32));
|
||||||
ptr += sizeof(u32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* data */
|
/* data */
|
||||||
memcpy(ptr, reply->data, reply->length);
|
output_data(c, reply->data, reply->length);
|
||||||
c->olen += rlen;
|
|
||||||
c->flags |= WAITING_WRITE;
|
c->flags |= WAITING_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,7 +637,7 @@ de_http(char *buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct socket_call *
|
static struct socket_call *
|
||||||
handle_http_tcp(struct client *c)
|
handle_http_tcp(struct client *c)
|
||||||
{
|
{
|
||||||
struct socket_call *cs;
|
struct socket_call *cs;
|
||||||
@@ -647,7 +646,7 @@ handle_http_tcp(struct client *c)
|
|||||||
char *proto;
|
char *proto;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
s = (char *)d->inmsg;
|
s = (char *)c->inmsg;
|
||||||
|
|
||||||
p = strstr(s, "\r\n");
|
p = strstr(s, "\r\n");
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
@@ -665,7 +664,7 @@ handle_http_tcp(struct client *c)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data = malloc(strlen(t));
|
data = malloc(strlen(t));
|
||||||
if (data == NULL) {
|
if (data == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if(*t == '/')
|
if(*t == '/')
|
||||||
@@ -693,12 +692,8 @@ handle_http_tcp(struct client *c)
|
|||||||
"That page doesn't exist, maybe you are looking for "
|
"That page doesn't exist, maybe you are looking for "
|
||||||
"<A HREF=\"http://www.h5l.org/\">Heimdal</A>?\r\n";
|
"<A HREF=\"http://www.h5l.org/\">Heimdal</A>?\r\n";
|
||||||
free(data);
|
free(data);
|
||||||
if (rk_IS_SOCKET_ERROR(send(d->s, proto, strlen(proto), 0))) {
|
output_data(c, proto, strlen(proto));
|
||||||
return NULL;
|
output_data(c, msg, strlen(msg));
|
||||||
}
|
|
||||||
if (rk_IS_SOCKET_ERROR(send(d->s, msg, strlen(msg), 0))) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,16 +711,8 @@ handle_http_tcp(struct client *c)
|
|||||||
"Pragma: no-cache\r\n"
|
"Pragma: no-cache\r\n"
|
||||||
"Content-type: application/octet-stream\r\n"
|
"Content-type: application/octet-stream\r\n"
|
||||||
"Content-transfer-encoding: binary\r\n\r\n";
|
"Content-transfer-encoding: binary\r\n\r\n";
|
||||||
if (rk_IS_SOCKET_ERROR(send(d->s, proto, strlen(proto), 0))) {
|
output_data(c, proto, strlen(proto));
|
||||||
free(data);
|
output_data(c, msg, strlen(msg));
|
||||||
free(cs);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (rk_IS_SOCKET_ERROR(send(d->s, msg, strlen(msg), 0))) {
|
|
||||||
free(data);
|
|
||||||
free(cs);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cs;
|
return cs;
|
||||||
|
Reference in New Issue
Block a user