int Ns_ConnReadHeaders(Ns_Conn *conn, Ns_Set *set, int *nreadPtr) { Ns_DString ds; Conn *connPtr = (Conn *) conn; NsServer *servPtr = connPtr->servPtr; int status, nread, nline, maxhdr; Ns_DStringInit(&ds); nread = 0; maxhdr = connPtr->drvPtr->maxinput; status = NS_OK; while (nread < maxhdr && status == NS_OK) { Ns_DStringTrunc(&ds, 0); status = Ns_ConnReadLine(conn, &ds, &nline); if (status == NS_OK) { nread += nline; if (nread > maxhdr) { status = NS_ERROR; } else { if (ds.string[0] == '\0') { break; } status = Ns_ParseHeader(set, ds.string, servPtr->opts.hdrcase); } } } if (nreadPtr != NULL) { *nreadPtr = nread; } Ns_DStringFree(&ds); return status; }
static void SetUrl(Ns_Request *request, char *url, Tcl_Encoding encoding) { Ns_Conn *conn; Ns_DString ds1, ds2; char *p; Ns_DStringInit(&ds1); Ns_DStringInit(&ds2); /* * Look for a query string at the end of the URL. */ p = strchr(url, '?'); if (p != NULL) { *p++ = '\0'; if (request->query != NULL) { ns_free(request->query); } request->query = ns_strdup(p); } /* * Decode and normalize the URL. If the encoding isn't specified, * use the encoding of the current connection, if any. */ if (encoding == NULL && (conn = Ns_GetConn()) != NULL) { encoding = Ns_ConnGetUrlEncoding(conn); } p = Ns_DecodeUrlWithEncoding(&ds1, url, encoding); if (p == NULL) { p = url; } Ns_NormalizePath(&ds2, p); Ns_DStringTrunc(&ds1, 0); /* * Append a trailing slash to the normalized URL if the original URL * ended in slash that wasn't also the leading slash. */ while (*url == '/') { ++url; } if (*url != '\0' && url[strlen(url) - 1] == '/') { Ns_DStringAppend(&ds2, "/"); } request->url = ns_strdup(ds2.string); Ns_DStringFree(&ds2); /* * Build the urlv and set urlc. */ p = ns_strdup(request->url + 1); Ns_DStringNAppend(&ds1, (char *) &p, sizeof(char *)); while (*p != '\0') { if (*p == '/') { *p++ = '\0'; if (*p == '\0') { /* * Stop on a trailing slash. */ break; } Ns_DStringNAppend(&ds1, (char *) &p, sizeof(char *)); } ++p; } request->urlc = ds1.length / (sizeof(char *)); p = NULL; Ns_DStringNAppend(&ds1, (char *) &p, sizeof(char *)); request->urlv = (char **) ns_malloc((size_t)ds1.length); memcpy(request->urlv, ds1.string, (size_t)ds1.length); Ns_DStringFree(&ds1); }