#define initrd_len __use_data16 ( initrd_len ) /** Internal copy of the command line */ static char *cmdline_copy; /** Free command line image */ static void cmdline_image_free ( struct refcnt *refcnt ) { struct image *image = container_of ( refcnt, struct image, refcnt ); DBGC ( image, "RUNTIME freeing command line\n" ); free ( cmdline_copy ); } /** Embedded script representing the command line */ static struct image cmdline_image = { .refcnt = REF_INIT ( cmdline_image_free ), .name = "<CMDLINE>", .type = &script_image_type, }; /** Colour for debug messages */ #define colour &cmdline_image /** * Strip unwanted cruft from command line * * @v cmdline Command line * @v cruft Initial substring of cruft to strip */ static void cmdline_strip ( char *cmdline, const char *cruft ) { char *strip;
static uri_desc_t * http_mkresponse(uri_desc_t *req, uri_desc_t *res, char *proto, int sz) { http_t *qhttp = req->scheme; http_t *shttp = res->scheme; uri_desc_t *uri = kmem_cache_alloc(nl7c_uri_kmc, KM_SLEEP); char *alloc; char *cp; char *ep = &proto[sz]; uri_rd_t *rdp; int cnt; char hdr_etag[] = "ETag: "; /* Any optional header(s) */ if (shttp->etag.cp != NULL) { /* Response has an ETag:, count it */ sz += sizeof (hdr_etag) - 1 + (shttp->etag.ep - shttp->etag.cp) + 2; } sz += 2; alloc = kmem_alloc(sz, KM_SLEEP); /* Minimum temp uri initialization as needed by uri_response() */ REF_INIT(uri, 1, nl7c_uri_inactive, nl7c_uri_kmc); uri->hash = URI_TEMP; uri->tail = NULL; uri->scheme = NULL; uri->reqmp = NULL; uri->count = 0; cv_init(&uri->waiting, NULL, CV_DEFAULT, NULL); mutex_init(&uri->proclock, NULL, MUTEX_DEFAULT, NULL); URI_RD_ADD(uri, rdp, sz, -1); rdp->data.kmem = alloc; atomic_add_64(&nl7c_uri_bytes, sz); cp = alloc; if (qhttp->major == 1) { /* * Full response format. * * Copy to first sub char '#'. */ while (proto < ep) { if (*proto == '#') break; *cp++ = *proto++; } /* Process the HTTP version substitutions */ if (*proto != '#') goto bad; *cp++ = '0' + qhttp->major; proto++; while (proto < ep) { if (*proto == '#') break; *cp++ = *proto++; } if (*proto != '#') goto bad; *cp++ = '0' + qhttp->minor; proto++; /* Copy to the next sub char '#' */ while (proto < ep) { if (*proto == '#') break; *cp++ = *proto++; } /* Process the "Date: " substitution */ if (*proto != '#') goto bad; http_today(cp); /* Skip to the next nonsub char '#' */ while (proto < ep) { if (*proto != '#') break; cp++; proto++; } /* Copy to the next sub char '#' */ while (proto < ep) { if (*proto == '#') break; *cp++ = *proto++; } /* Process the NCA version substitutions */ if (*proto != '#') goto bad; *cp++ = '0' + nca_major_version; proto++; while (proto < ep) { if (*proto == '#') break; *cp++ = *proto++; } if (*proto != '#') goto bad; *cp++ = '0' + nca_minor_version; proto++; /* Copy remainder of HTTP header */ while (proto < ep) { *cp++ = *proto++; } } else { goto bad; } /* Any optional header(s) */ if (shttp->etag.cp != NULL) { /* Response has an ETag:, add it */ cnt = sizeof (hdr_etag) - 1; bcopy(hdr_etag, cp, cnt); cp += cnt; cnt = (shttp->etag.ep - shttp->etag.cp); bcopy(shttp->etag.cp, cp, cnt); cp += cnt; *cp++ = '\r'; *cp++ = '\n'; } /* Last, add empty line */ uri->eoh = cp; *cp++ = '\r'; *cp = '\n'; return (uri); bad: /* * Free any resources allocated here, note that while we could * use the uri_inactive() to free the uri by doing a REF_RELE() * we instead free it here as the URI may be in less then a fully * initialized state. */ kmem_free(alloc, sz); kmem_cache_free(nl7c_uri_kmc, uri); return (NULL); }