}
unsigned long long conlen = 0;
unsigned long long conincr = 0;
+ bool nolen = false;
char* postbuf = NULL;
while(true) {
int len = recv(sock, buf, BUFFER_SIZE, 0);
int i;
for(i = 0; i < len; i++) {
cbuf[0] = buf[i];
- if(conlen > 0) {
+force_back:;
+ if(conlen > 0 || nolen) {
conlen--;
postbuf[conincr] = cbuf[0];
conincr++;
- if(conlen == 0) {
+ if(conlen == 0 || nolen) {
if(headers != NULL) {
int j;
bool hastype = false;
free(token);
}
if(did_logout){
+ param.login = false;
char* type;
uint64_t len;
char* data = NULL;
send(sock, lenstr, strlen(lenstr), 0);
free(lenstr);
+ send(sock, "\r\n", 2, 0);
+ send(sock, "Set-Cookie: TOKEN=; HttpOnly; MaxAge=0\r\n", 40, 0);
+ send(sock, "\r\n", 2, 0);
+ send(sock, data, len, 0);
+ free(type);
+ } else {
+ send(sock, "HTTP/1.1 200 OK\r\n", 9 + 8, 0);
+ send(sock, "Connection: keep-alive\r\n", 24, 0);
+ send(sock, "Content-Length: 0\r\n", 19, 0);
+ send(sock, "Set-Cookie: TOKEN=; HttpOnly; MaxAge=0\r\n", 40, 0);
+ send(sock, "\r\n", 2, 0);
+ send(sock, "\r\n", 2, 0);
+ }
+ }else{
+ char* type;
+ uint64_t len;
+ char* data = NULL;
+ char* s;
+
+ struct stat st;
+ char* lastmod = NULL;
+ const char* pth = mandshurica_strcat(webroot, "/logout-fail/");
+ if(stat(pth, &st) == 0) {
+ if(S_ISDIR(st.st_mode)) {
+ if(data == NULL) {
+ s = mandshurica_strcat(pth, "/index.html.tmpl");
+ data = config->mandshurica_load(s, &type, &lastmod, &len, param);
+ free(s);
+ }
+ if(data == NULL) {
+ s = mandshurica_strcat(pth, "/index.html");
+ data = config->mandshurica_load(s, &type, &lastmod, &len, param);
+ free(s);
+ }
+ } else {
+ data = config->mandshurica_load(pth, &type, &lastmod, &len, param);
+ }
+ }
+ if(data != NULL) {
+ send(sock, "HTTP/1.1 200 OK\r\n", 9 + 8, 0);
+ send(sock, "Connection: keep-alive\r\n", 24, 0);
+ send(sock, "Content-Type: ", 14, 0);
+ send(sock, type, strlen(type), 0);
+ send(sock, "\r\n", 2, 0);
+ if(lastmod != NULL) {
+ send(sock, "Last-Modified: ", 15, 0);
+ send(sock, lastmod, strlen(lastmod), 0);
+ send(sock, "\r\n", 2, 0);
+ free(lastmod);
+ }
+ send(sock, "Content-Length: ", 16, 0);
+
+ char* lenstr = malloc(513);
+ sprintf(lenstr, "%llu", len);
+ send(sock, lenstr, strlen(lenstr), 0);
+ free(lenstr);
+
send(sock, "\r\n", 2, 0);
send(sock, "\r\n", 2, 0);
send(sock, data, len, 0);
char* token = mandshurica_strdup(httppath);
int res = mod_auth(usr, pwd, &token);
if(res == MS_AUTH_OK) {
+ param.login = true;
char* type;
uint64_t len;
char* data = NULL;
if(headers != NULL) {
int j;
bool haslen = false;
+ nolen = false;
for(j = 0; headers[j] != NULL; j += 2) {
if(mandshurica_strcaseequ(headers[j], "Content-Length")) {
haslen = true;
postbuf = malloc(conlen + 1);
postbuf[conlen] = 0;
count = 0;
+ if(conlen == 0) {
+ nolen = true;
+ cbuf[0] = 0;
+ goto force_back;
+ }
break;
}
}