/* xtype - return type of a thing */ LVAL xtype(void) { LVAL arg; if (!(arg = xlgetarg())) return (NIL); switch (ntype(arg)) { case SUBR: return (a_subr); case FSUBR: return (a_fsubr); case CONS: return (a_cons); case SYMBOL: return (a_symbol); case FIXNUM: return (a_fixnum); case FLONUM: return (a_flonum); case STRING: return (a_string); case OBJECT: return (a_object); case STREAM: return (a_stream); case VECTOR: return (a_vector); case CLOSURE: return (a_closure); case CHAR: return (a_char); case USTREAM: return (a_ustream); case EXTERN: return (exttype(arg)); default: xlfail("bad node type"); return NIL; /* never happens */ } }
int BlogDispatch(BlogRef const blog, SLNSessionRef const session, HTTPConnectionRef const conn, HTTPMethod const method, strarg_t const URI, HTTPHeadersRef const headers) { int rc = -1; rc = rc >= 0 ? rc : GET_query(blog, session, conn, method, URI, headers); rc = rc >= 0 ? rc : GET_compose(blog, session, conn, method, URI, headers); rc = rc >= 0 ? rc : GET_upload(blog, session, conn, method, URI, headers); rc = rc >= 0 ? rc : POST_post(blog, session, conn, method, URI, headers); rc = rc >= 0 ? rc : GET_account(blog, session, conn, method, URI, headers); rc = rc >= 0 ? rc : POST_auth(blog, session, conn, method, URI, headers); if(403 == rc) { HTTPConnectionSendRedirect(conn, 303, "/account"); return 0; } if(rc >= 0) return rc; // TODO: Pretty 404 pages, etc. if(HTTP_GET != method && HTTP_HEAD != method) return -1; str_t path[PATH_MAX]; size_t const len = strlen(URI); if(0 == len) return 400; strarg_t const qs = strchr(URI, '?'); size_t const pathlen = qs ? qs-URI : len; str_t *URI_raw = QSUnescape(URI, pathlen, false); if('/' == URI[len-1]) { str_t const index[] = "index.html"; rc = snprintf(path, sizeof(path), "%s/static/%s%s", blog->dir, URI_raw, index); } else { rc = snprintf(path, sizeof(path), "%s/static/%s", blog->dir, URI_raw); } FREE(&URI_raw); if(rc >= sizeof(path)) return 414; // Request-URI Too Large if(rc < 0) return 500; if(strstr(path, "..")) return 403; // Security critical. strarg_t const ext = strrchr(path, '.'); strarg_t const type = exttype(ext); rc = HTTPConnectionSendFile(conn, path, type, -1); if(UV_EISDIR == rc) { str_t location[URI_MAX]; rc = snprintf(location, sizeof(location), "%s/", URI); if(rc >= sizeof(location)) return 414; // Request-URI Too Large if(rc < 0) return 500; HTTPConnectionSendRedirect(conn, 301, location); return 0; } if(rc < 0 && UV_EPIPE != rc) { alogf("Error sending file %s: %s\n", URI, uv_strerror(rc)); } return 0; }
/***********************************************************************//** * @brief Save FITS image * * @param[in] datatype Datatype of pixels to be saved * @param[in] pixels Pixel array to be saved * * @exception GException::fits_file_not_open * No FITS file has been opened. * @exception GException::fits_error * FITS error. * * Save image pixels into FITS file. In case that the HDU does not exist it * is created. In case that the pixel array is empty no data are saved; all * image pixels will be empty in this case. ***************************************************************************/ void GFitsImage::save_image(int datatype, const void* pixels) { // Throw an exception if FITS file is not open if (FPTR(m_fitsfile)->Fptr == NULL) { throw GException::fits_file_not_open(G_SAVE_IMAGE, "Open file before saving the image."); } // Move to HDU. We use here an explicit cfitsio moveto function since we // want to recover the error code ... int status = 0; int type = 0; status = __ffmahd(FPTR(m_fitsfile), m_hdunum+1, &type, &status); // If move was successful but HDU type in file differs from HDU type // of object then replace the HDU in the file if (status == 0 && type != exttype()) { status = __ffdhdu(FPTR(m_fitsfile), NULL, &status); if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } status = __ffiimg(FPTR(m_fitsfile), m_bitpix, m_naxis, m_naxes, &status); //status = __ffiimgll(FPTR(m_fitsfile), m_bitpix, m_naxis, m_naxes, &status); if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } } // If HDU does not yet exist in file then create it now if (status == 107) { status = 0; status = __ffcrim(FPTR(m_fitsfile), m_bitpix, m_naxis, m_naxes, &status); if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } } else if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } // If HDU seems to be empty then create it now. This is only needed for the // primary HDU, since __ffmahd gives no error if the primary HDU is empty. // By checking the number of keywords in the HDU we detect an empty HDU ... int num = 0; status = __ffghsp(FPTR(m_fitsfile), &num, NULL, &status); if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } if (num == 0) { status = __ffcrim(FPTR(m_fitsfile), m_bitpix, m_naxis, m_naxes, &status); if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } } // Make sure that the image on disk has the right size by resizing it status = __ffrsim(FPTR(m_fitsfile), m_bitpix, m_naxis, m_naxes, &status); if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } // Save the image pixels (if there are some ...) if (m_naxis > 0 && pixels != NULL) { long* fpixel = new long[m_naxis]; long* lpixel = new long[m_naxis]; for (int i = 0; i < m_naxis; ++i) { fpixel[i] = 1; lpixel[i] = m_naxes[i]; } status = __ffpss(FPTR(m_fitsfile), datatype, fpixel, lpixel, (void*)pixels, &status); delete [] fpixel; delete [] lpixel; if (status != 0) { throw GException::fits_error(G_SAVE_IMAGE, status); } } // Return return; }