static int sendResponse(Session *sn, Request *rq, HTTPResponse *resp) { pb_param *pb_entry; /* * collect up the headers */ pb_entry = pblock_remove(CONTENT_TYPE,rq->srvhdrs); /* remove default */ param_free(pb_entry); /* aB. Need to free parameters we remove from pblocks !!! */ st_perform(resp->headers,gethdr,rq); /* * ensure a content length */ if (pblock_findval(CONTENT_LENGTH, rq->srvhdrs) == NULL) { char length[64]; util_itoa(resp->content_length,length); pblock_nvinsert(CONTENT_LENGTH,length, rq->srvhdrs); } protocol_status(sn, rq, resp->status, resp->statusMsg); if (protocol_start_response(sn, rq) == REQ_NOACTION) { WOLog(WO_ERR,"protocol_start_response() returned REQ_NOACTION (!?)"); return REQ_PROCEED; } if (resp->content_length) if (net_write(sn->csd, resp->content, resp->content_length) == IO_ERROR) { WOLog(WO_ERR,"Failed to send content to client"); return REQ_EXIT; } return REQ_PROCEED; }
/* * @saltSize(OUT) number of bytes of generated salt * @return the salt in binary format */ char* newSalt(int& saltSize) { static const int SALT_SIZE = 8; //Number of bytes of salt for SSHA char tmpbuf[512]; time_t current_time; time(¤t_time); util_itoa(current_time,tmpbuf); char *salt = (char*)MALLOC(SALT_SIZE); //salt = new char [SALT_SIZE](); memset(salt,0,SALT_SIZE); memcpy(salt,tmpbuf,SALT_SIZE); //salt generated saltSize = SALT_SIZE; return salt; }
Result Context::createIntegerResult(PRInt64 i) { if (i == 0) return Result(RESULT_INTEGER, PR_FALSE, 0, NULL, "0", 1); if (i == 1) return Result(RESULT_INTEGER, PR_TRUE, 1, NULL, "1", 1); const int size = sizeof("-9223372036854775808"); char *p = (char *) pool_malloc(pool, size); if (p == NULL) return Result::out_of_memory; int len; if (i < INT_MAX || i > INT_MAX) { len = PR_snprintf(p, size, "%lld", i); } else { len = util_itoa(i, p); } return Result(RESULT_INTEGER, (i != 0), i, pool, p, len); }
/* * Copy Headers into the request. * * This is kind of like an easter egg hunt, CGI equivilant headers are * stashed all over in different pblocks. Do the best we can without * missing any... */ static void copyHeaders(pblock *pb, Session *sn, Request *rq, HTTPRequest *req) { int i; const char *hdrval; char *portstr; const char *server; /* * the following line will generate a compiler warning. uncomment if * Netscape ever implements it. request_loadheaders(sn,rq); */ /* * first, blindly copy the request headers */ for (i=0; i < rq->headers->hsize; i++) { struct pb_entry *entry = rq->headers->ht[i]; while (entry != NULL) { pb_param *hdr = entry->param; if (hdr != NULL) req_addHeader(req, hdr->name, hdr->value, 0); entry = entry->next; } } for (i=0; i < rq->vars->hsize; i++) { struct pb_entry *entry = rq->vars->ht[i]; while (entry != NULL) { pb_param *hdr = entry->param; if (hdr != NULL) { /* * BEGIN Support for getting the client's certificate as one liner. */ if (strcmp((const char *)hdr->name, "auth-cert") == 0 && hdr->value != NULL) { const char *val = (const char *)make_cert_one_line((char *)hdr->value); if(val != NULL){ req_addHeader(req, "SSL_CLIENT_CERT", val, 0); //WOLog(WO_DBG, "Adding server variable %s", hdr->name); //WOLog(WO_DBG, "With value %s", hdr->value); } /* * END Support for getting the client's certificate. */ else { req_addHeader(req, hdr->name, hdr->value, 0); //WOLog(WO_DBG, "Adding server variable %s", hdr->name); //WOLog(WO_DBG, "With value %s", hdr->value); } } } entry = entry->next; } } if (req->method == HTTP_POST_METHOD) req_addHeader(req,"REQUEST_METHOD","POST", 0); else if (req->method == HTTP_HEAD_METHOD) req_addHeader(req,"REQUEST_METHOD","HEAD", 0); else req_addHeader(req,"REQUEST_METHOD","GET", 0); /* * collect up the server specific headers */ cpyhdr("ip", sn->client, req, "REMOTE_ADDR"); cpyhdr("query", rq->reqpb, req, "QUERY_STRING"); cpyhdr("protocol", rq->reqpb, req, "SERVER_PROTOCOL"); hdrval = session_maxdns(sn); if (!hdrval) hdrval = session_dns(sn); if (hdrval) req_addHeader(req, "REMOTE_HOST", hdrval, 0); req_addHeader(req, "SERVER_SOFTWARE", system_version(), 0); portstr = (char *)WOMALLOC(32); if (portstr) { util_itoa(server_portnum, portstr); req_addHeader(req, "SERVER_PORT", portstr, STR_FREEVALUE); } /* * Netscape claims to have fixed this in 3, if it causes a problem * comment it out */ server = server_hostname; if (server != NULL) req_addHeader(req, "SERVER_NAME", server, 0); return; }