void acl_clean_env(char **preserve_list) { #ifdef ACL_UNIX extern char **environ; char **env = environ; #elif defined(ACL_WINDOWS) extern char **_environ; char **env = _environ; #endif ACL_ARGV *save_list; char *value; char **cpp; char *eq; /* * Preserve or specify selected environment variables. */ #define STRING_AND_LENGTH(x, y) (x), (ssize_t) (y) save_list = acl_argv_alloc(10); for (cpp = preserve_list; *cpp; cpp++) if ((eq = strchr(*cpp, '=')) != 0) acl_argv_addn(save_list, STRING_AND_LENGTH(*cpp, eq - *cpp), STRING_AND_LENGTH(eq + 1, strlen(eq + 1)), (char *) 0); else if ((value = acl_safe_getenv(*cpp)) != 0) acl_argv_add(save_list, *cpp, value, (char *) 0); /* * Truncate the process environment, if available. On some systems * (Ultrix!), environ can be a null pointer. */ if (env) env[0] = 0; /* * Restore preserved environment variables. */ for (cpp = save_list->argv; *cpp; cpp += 2) #ifdef ACL_UNIX if (setenv(cpp[0], cpp[1], 1)) #elif defined(ACL_WINDOWS) if (!SetEnvironmentVariable(cpp[0], cpp[1])) #endif acl_msg_error("setenv(%s, %s): %s", cpp[0], cpp[1], acl_last_serror()); /* * Cleanup. */ acl_argv_free(save_list); }
/* Unmount the OS ZIP device if its been used. */ void zip_unmount_os(void) { DEVICELIST *dev; DEVICEPARAM p_close = { STRING_AND_LENGTH("Close"), ParamBoolean, NULL }; if (swzipreaddevice != NULL) { HQASSERT(osdevice != NULL, "osdevice is NULL"); /* Do our best to unmount the os device. */ ClearUndismountableDevice(osdevice); theDevParamBoolean(p_close) = TRUE; if ( (theISetParam(osdevice))(osdevice, &p_close) != ParamAccepted ) { HQFAIL("Unable to set Close parameter on zipped SW folder."); } /* Call the device dismount directly as PS semantics no longer apply. */ if ((dev = find_device((uint8*)"os")) != NULL) { if ((*theIDevDismount( dev ))( dev ) == -1) { HQFAIL("Unable to dismount os device on zipped SW folder."); } } swzipreaddevice = NULL; } }
/* Get the index of the next page in the current FixedDocument to interpret. */ Bool pt_next_page( /*@in@*/ /*@notnull@*/ XPS_PT* pt, /*@in@*/ /*@notnull@*/ int32* p_next_page) { DEVICEPARAM param; HQASSERT((pt != NULL), "pt_next_page: pt pointer NULL"); HQASSERT((pt->scope > PT_SCOPE_JOB), "pt_next_page: document has not yet been started"); /* If there is no device then all pages are rendered */ if ( pt->device == NULL ) { *p_next_page = XPSPT_PAGES_ALL; return TRUE ; } /* Get next page index from the PT device */ if ( !pt_get_param(pt, STRING_AND_LENGTH("NextPage"), ¶m) ) { return FALSE ; } *p_next_page = theDevParamInteger(param); HQASSERT((*p_next_page >= XPSPT_COUNT_PAGES), "pt_next_page: invalid next page value"); return TRUE ; } /* pt_next_page */
/* Perform end of scope RIP configuration. */ Bool pt_config_end( /*@in@*/ /*@notnull@*/ XPS_PT* pt, Bool abortjob) { int32 status; OBJECT end_file = OBJECT_NOTVM_NOTHING; static DEVICEPARAM param = { STRING_AND_LENGTH("AbortJob"), ParamBoolean, NULL }; HQASSERT((pt != NULL), "pt_config_end: pt pointer NULL"); if ( !SystemParams.XPS ) return error_handler(INVALIDACCESS); /* Raise scope of print ticket */ pt->scope--; HQASSERT(((pt->scope >= PT_SCOPE_JOB) && (pt->scope <= PT_SCOPE_PAGE)), "pt_config_end: invalid pt scope"); /* Catch absence of any PT device */ if ( pt->device == NULL ) { return TRUE ; } if ( !abortjob ) { /* Run end config PS */ if ( !pt_open_config_file(pt, (uint8*)"E", SW_RDONLY, READ_FLAG, &end_file) ) { return FALSE ; } theTags(end_file) |= EXECUTABLE; status = setup_pending_exec(&end_file, TRUE); (void)file_close(&end_file); return status ; } else { /* Signal to PT device that job is being aborted */ theDevParamBoolean(param) = TRUE; (void)pt_set_param(pt, ¶m); } return TRUE ; } /* pt_config_end */
/* Make OS device a ZIP device. */ void zip_mount_os(void) { uint8 buffer[256]; uint8* szZipArchiveName; DEVICEPARAM p_readonly = { STRING_AND_LENGTH("ReadOnly"), ParamBoolean, NULL }; DEVICEPARAM p_crc32 = { STRING_AND_LENGTH("CheckCRC32"), ParamBoolean, NULL }; DEVICEPARAM p_filename = { STRING_AND_LENGTH("Filename"), ParamString, NULL }; /* Mount new swzipread device so we can read the zipped SW folder */ swzipreaddevice = device_alloc(STRING_AND_LENGTH(SWZIP_READ_DEV_NAME)) ; if ( !device_connect(swzipreaddevice, SWZIPREAD_DEVICE_TYPE, SWZIP_READ_DEV_NAME, DEVICEUNDISMOUNTABLE|DEVICEENABLED, TRUE)) { device_free(swzipreaddevice) ; swzipreaddevice = NULL ; } else { /* Add ZIP read device. */ device_add(swzipreaddevice); } /* If we have managed to mount an SW ZIP read device, assume that we MUST have a zipped SW folder to use. */ if (swzipreaddevice != NULL) { /* Rename %os% to something else */ theIDevName(osdevice) = (uint8*)SWZIP_WRITE_DEV_NAME; /* Mount new os device as ZIP device */ if ( ! device_connect(osdevice, ZIP_DEVICE_TYPE, "os", DEVICEUNDISMOUNTABLE|DEVICEENABLED, TRUE)) { device_free(swzipreaddevice) ; swzipreaddevice = NULL ; (void)dispatch_SwExit(swexit_error_zipsw_init, "Cannot initialise ZIP os device"); return; } /* Make ZIP OS device first device */ device_add_first(osdevice); /* NOTE: can't do this here since ZIP device calls SwOftenUnsafe which * depends on SystemParams, but that has not been set up yet! * Originally done in doBootup() which was last thing before interpreter * kicks off, so ideally need hook from there! */ /* ZIP device is already mounted enabled - need to turn on checksum checking * and modifiable */ theDevParamBoolean(p_crc32) = TRUE; if ( ((theISetParam(osdevice))(osdevice, &p_crc32) != ParamAccepted)) { (void)dispatch_SwExit(swexit_error_zipsw_config_01, "Failed to configure OS device(1)"); return; } theDevParamBoolean(p_readonly) = FALSE; if ( ((theISetParam(osdevice))(osdevice, &p_readonly) != ParamAccepted )) { (void)dispatch_SwExit(swexit_error_zipsw_config_02, "Failed to configure OS device(2)"); return; } szZipArchiveName = getZipReadArchiveName (buffer, sizeof (buffer)); theDevParamString(p_filename) = szZipArchiveName; theDevParamStringLen(p_filename) = strlen_int32 ((char*) szZipArchiveName); if ( ((theISetParam(osdevice))(osdevice, &p_filename) != ParamAccepted ) ) { (void)dispatch_SwExit(swexit_error_zipsw_config_03, "Failed to configure OS device(3)"); return; } } else { /* We did not manage to mount a SW ZIP read device, so just assume a normal SW folder. Do nothing. */ } } /* zip_mount_os */
/* Send FixedPage media information to the PT device. */ Bool pt_page_details( /*@in@*/ /*@notnull@*/ XPS_PT* pt, double width, double height, /*@in@*/ /*@notnull@*/ RECTANGLE* bleedbox, /*@in@*/ /*@notnull@*/ RECTANGLE* contentbox) { Bool success; OBJECT dev_file = OBJECT_NOTVM_NOTHING; uint8 pt_filename[LONGESTDEVICENAME + 16]; uint8 buffer[16384]; HQASSERT((pt != NULL), "pt_config_end: pt pointer NULL"); HQASSERT((bleedbox != NULL), "pt_config_end: bleedbox pointer NULL"); HQASSERT((contentbox != NULL), "pt_config_end: contentbox pointer NULL"); HQASSERT((pt->scope == PT_SCOPE_PAGE), "pt_config_end: sending media details at wrong scope level"); /* Catch absence of any PT device */ if ( pt->device == NULL ) { /* Cache the page size for minimal page config PS */ pt->width = width; pt->height = height; return TRUE ; } /* Create XML of fixedpage details */ swcopyf(buffer, (uint8*)"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<PageDetails xmlns=\"http://schemas.globalgraphics.com/xps/2005/03/pagedetails\">" " <Page Size=\"%f,%f\" BleedBox=\"%f,%f,%f,%f\" ContentBox=\"%f,%f,%f,%f\"/>" "</PageDetails>", width, height, bleedbox->x, bleedbox->y, bleedbox->w, bleedbox->h, contentbox->x, contentbox->y, contentbox->w, contentbox->h); /* Generate name of fixedpage details file on PT device */ swcopyf(pt_filename, (uint8*)"%%%s%%PD", theIDevName(pt->device)); oString(snewobj) = pt_filename; theLen(snewobj) = CAST_UNSIGNED_TO_UINT16(strlen((char*)pt_filename)); if ( !file_open(&snewobj, SW_WRONLY, WRITE_FLAG, FALSE, 0, &dev_file) ) { return FALSE ; } /* Copy XML in buffer to PT device */ success = file_write(oFile(dev_file), buffer, strlen_int32((char*)buffer)); success = file_close(&dev_file) && success; if ( !success ) { /* The XML error handler needs a file name, but there is no externally * visible file for the page details XML. So the following is a made up * name to uniquely locate the source of the XML that caused the error. */ #define PAGE_DETAILS_NAME "Internal:PageDetails.xml" (void)pt_error_handler(pt, STRING_AND_LENGTH(PAGE_DETAILS_NAME)); } return success ; } /* pt_page_details */
/** * \brief Set up PS error from PT device. * * The PT device parameters are queries to get the XML error details. * * \param[in] pt * XPS PrintTicket handler * \param[in] uri * PT file name * \param[in] uri_len * Length of PT file name * * \returns * \c FALSE. */ static Bool pt_error_handler( /*@in@*/ /*@notnull@*/ XPS_PT* pt, /*@in@*/ /*@notnull@*/ uint8* uri, uint32 uri_len) { int32 errorno; int32 line; int32 column; uint8* detail; int32 detail_len; DEVICEPARAM param; HQASSERT((pt != NULL), "pt_error_handler: NULL pt context pointer"); HQASSERT((uri != NULL), "pt_error_handler: NULL pt uri pointer"); HQASSERT((uri_len > 0), "pt_error_handler: invalid pt uri length"); /* Any error in sending the XML may have resulted in error_handler() being * called, so clear any error ready for a more detailed version. */ error_clear(); /* Get XML parse details from PT device */ errorno = UNDEFINED; if ( pt_get_param(pt, STRING_AND_LENGTH("ErrorNo"), ¶m) ) { if ( param.type == ParamInteger ) { /* Translate pt device error to PS error */ switch ( theDevParamInteger(param) ) { case XPSPT_ERROR_OUTOFMEM: errorno = VMERROR; break; case XPSPT_ERROR_SYNTAX: errorno = SYNTAXERROR; break; case XPSPT_ERROR_RANGECHECK: errorno = RANGECHECK; break; case XPSPT_ERROR_LIMITCHECK: errorno = LIMITCHECK; break; default: HQFAIL("pt_error_handler: unexpected PT device error number"); } } } line = -1; if ( pt_get_param(pt, STRING_AND_LENGTH("ErrorLine"), ¶m) ) { if ( param.type == ParamInteger ) { line = theDevParamInteger(param); } } column = -1; if ( pt_get_param(pt, STRING_AND_LENGTH("ErrorColumn"), ¶m) ) { if ( param.type == ParamInteger ) { column = theDevParamInteger(param); } } detail = NULL; detail_len = 0; if ( pt_get_param(pt, STRING_AND_LENGTH("ErrorMessage"), ¶m) ) { if ( param.type == ParamString ) { detail = theDevParamString(param); detail_len = theDevParamStringLen(param); HQASSERT((detail_len >= 0), "pt_error_handler: Invalid error message length from PT device"); HQASSERT(((detail != NULL) || (detail_len == 0)), "pt_error_handler: Invalid error message from PT device"); } } /** \todo TODO: THIS IS A HACK AND NEEDS IMPROVING */ #define LONGFORM2 ("PartName: %.*s; Line: %d; Column: %d; XMLInfo: %.*s") return detailf_error_handler(errorno, LONGFORM2, uri_len, uri, line, column, detail_len, detail); } /* pt_error_handler */
pt_xml_set_error(XPSPT_ERROR_SYNTAX, (uint8*)"Value data is not a decimal."); return; } if ( !pt_set_value(pt_new, PT_VALUE_DECIMAL, &decimal) ) { pt_xml_set_error(XPSPT_ERROR_OUTOFMEM, (uint8*)"Out of memory adding Value decimal."); return; } break; } /* Note that this element has finished */ pt_end_param(pt_new); } static XML_ELEMENT_CALLBACKS ms_callbacks[] = { {STRING_AND_LENGTH("PrintCapabilities"), NULL, NULL, NULL}, {STRING_AND_LENGTH("PrintTicket"), ms_printticket_start, ms_printticket_end, NULL}, {STRING_AND_LENGTH("Attribute"), NULL, NULL, NULL}, {STRING_AND_LENGTH("AttributeSet"), NULL, NULL, NULL},