const char *MCS_get_session_name(void) { if (MCsessionname != NULL && MCCStringLength(MCsessionname) > 0) return MCsessionname; return "LCSESSION"; }
static bool MCTextLayoutFontWithLink(MCTextLayoutFont *p_base, MCTextLayoutLinkedFontEntry *p_link, MCTextLayoutFont*& r_font) { LOGFONTA t_logfont; t_logfont = p_base -> info; MCMemoryCopy(&t_logfont . lfFaceName, p_link -> face, MCMax(MCCStringLength(p_link -> face) + 1, sizeof(t_logfont . lfFaceName))); MCTextLayoutFont *t_font; t_font = MCTextLayoutFontFind(t_logfont); if (t_font != nil) { r_font = t_font; return true; } HFONT t_hfont; t_hfont = CreateFontIndirectA(&t_logfont); if (t_hfont == nil) return false; bool t_success; t_success = MCTextLayoutFontFromHFONT(t_hfont, t_font); DeleteObject(t_hfont); r_font = t_font; return t_success; }
bool MCSessionGenerateID(MCStringRef &r_id) { // php calculates session ids by hashing a string composed of REMOTE_ADDR, time in seconds & milliseconds, and a random value MCAutoStringRef t_remote_addr_string; char *t_remote_addr; t_remote_addr = NULL; if (MCS_getenv(MCSTR("REMOTE_ADDR"), &t_remote_addr_string)) MCCStringClone(MCStringGetCString(*t_remote_addr_string), t_remote_addr); time_t t_time; time(&t_time); MCAutoDataRef t_randombytes; // MW-2013-05-21; [[ RandomBytes ]] Use system primitive rather than SSL // directly. /* UNCHECKED */ MCU_random_bytes(64, &t_randombytes); md5_state_t t_state; md5_byte_t t_digest[16]; md5_init(&t_state); if (t_remote_addr != NULL) md5_append(&t_state, (md5_byte_t *)t_remote_addr, MCCStringLength(t_remote_addr)); md5_append(&t_state, (md5_byte_t *)&t_time, sizeof(t_time)); md5_append(&t_state, (md5_byte_t *)MCDataGetBytePtr(*t_randombytes), 64); md5_finish(&t_state, t_digest); return byte_to_hex((uint8_t*)t_digest, 16, r_id); }
ATSUFontID coretext_font_to_atsufontid(void *p_font) { bool t_success; t_success = true; CTFontRef t_ctfont; t_ctfont = NULL; if (t_success) { t_ctfont = (CTFontRef)p_font; t_success = t_ctfont != NULL; } char t_name[256]; if (t_success) { CFStringRef t_cfname; t_cfname = CTFontCopyPostScriptName(t_ctfont); t_success = t_cfname != NULL && CFStringGetCString(t_cfname, t_name, 256, kCFStringEncodingMacRoman); if (t_cfname != NULL) CFRelease(t_cfname); } ATSUFontID t_font_id; t_font_id = 0; if (t_success) { uint32_t t_name_length; t_name_length = MCCStringLength(t_name); t_success = ATSUFindFontFromName(t_name, t_name_length, kFontPostscriptName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &t_font_id) == noErr; } return t_font_id; }
MCGFloat __MCGContextMeasurePlatformText(MCGContextRef self, const unichar_t *p_text, uindex_t p_length, const MCGFont &p_font, const MCGAffineTransform &p_transform) { //if (!MCGContextIsValid(self)) // return 0.0; bool t_success; t_success = true; char *t_text; t_text = nil; if (t_success) t_success = MCCStringFromUnicodeSubstring(p_text, p_length / 2, t_text); MCGFloat t_width; t_width = 0.0; if (t_success) { SkPaint t_paint; t_paint . setTextSize(p_font . size); SkTypeface *t_typeface; t_typeface = (SkTypeface *) p_font . fid; t_paint . setTypeface(t_typeface); // MM-2013-12-05: [[ Bug 11527 ]] Make sure we calculate the UTF-8 string length correctly. uindex_t t_length; t_length = MCCStringLength(t_text); t_width = (MCGFloat) t_paint . measureText(t_text, t_length); } MCCStringFree(t_text); //self -> is_valid = t_success; return t_width; }
bool write_cstring(MCSystemFileHandle *p_file, const char *p_string) { uint32_t t_strlen = MCCStringLength(p_string); if (!write_uint32(p_file, t_strlen)) return false; return p_file->Write(p_string, t_strlen); }
bool MCExecPointSetRect(MCExecPoint &ep, int2 p_left, int2 p_top, int2 p_right, int2 p_bottom) { char *t_buffer = nil; if (!MCCStringFormat(t_buffer, "%d,%d,%d,%d", p_left, p_top, p_right, p_bottom)) return false; ep.grabbuffer(t_buffer, MCCStringLength(t_buffer)); return true; }
void MCAdExecCreateAd(MCExecContext& ctxt, const char *p_name, MCAdType p_type, MCAdTopLeft p_top_left, MCVariableValue *p_meta_data) { bool t_success; t_success = true; if (s_inneractive_ad_key == nil || MCCStringLength(s_inneractive_ad_key) == 0) { ctxt.SetTheResultToStaticCString("not registered with ad service"); t_success = false;; } MCAd *t_ad; t_ad = nil; if (t_success) if (MCAd::FindByNameOrId(p_name, t_ad)) { ctxt.SetTheResultToStaticCString("ad already exists"); t_success = false; } if (t_success) { uint32_t t_timeout; if (t_success) { t_timeout = 0; if (p_meta_data != nil && p_meta_data->fetch_element_if_exists(ctxt.GetEP(), "refresh", false)) t_timeout = ctxt.GetEP().getint4(); if (p_type == kMCAdTypeFullscreen) t_timeout = 0; else if (t_timeout < 30 || t_timeout > 500) t_timeout = 120; } if (t_success) t_success = MCSystemInneractiveAdCreate(ctxt, t_ad, p_type, p_top_left, t_timeout, p_meta_data); if (t_success) t_success = t_ad->Create(); if (t_success) { t_ad->SetNext(s_ads); t_ad->SetName(p_name); t_ad->SetOwner(ctxt.GetObjectHandle()); s_ads = t_ad; } else if (t_ad != nil) t_ad->Release(); } if (!t_success) ctxt.SetTheResultToStaticCString("could not create ad"); }
bool MCSystemStripUrl(const char *p_url, char *&r_stripped) { uindex_t t_start = 0; uindex_t t_end = MCCStringLength(p_url); while (t_start < t_end && is_whitespace(p_url[t_start])) t_start++; while (t_end > t_start && is_whitespace(p_url[t_end - 1])) t_end--; return MCCStringCloneSubstring(p_url + t_start, t_end - t_start, r_stripped); }
const char *MCS_get_session_save_path(void) { if (MCsessionsavepath != NULL && MCCStringLength(MCsessionsavepath) > 0) return MCsessionsavepath; if (s_session_temp_dir != NULL) return s_session_temp_dir; if (MCS_get_temporary_folder(s_session_temp_dir)) return s_session_temp_dir; return NULL; }
void MCAdSetVisibleOfAd(MCExecContext& ctxt, const char *p_name, bool p_visible) { if (s_inneractive_ad_key == nil || MCCStringLength(s_inneractive_ad_key) == 0) { ctxt.SetTheResultToStaticCString("not registered with ad service"); return; } MCAd *t_ad; t_ad = nil; if (!MCAd::FindByNameOrId(p_name, t_ad)) ctxt.SetTheResultToStaticCString("could not find ad"); else t_ad->SetVisible(p_visible); }
static Exec_stat cgi_compute_cookie_var(void *p_context, MCVariable *p_var) { bool t_success = true; char *t_cookie_string; t_cookie_string = MCS_getenv("HTTP_COOKIE"); MCExecPoint ep; if (t_cookie_string == NULL) return ES_NORMAL; cgi_store_cookie_urlencoded(ep, s_cgi_cookie, t_cookie_string, t_cookie_string + MCCStringLength(t_cookie_string), true); return ES_NORMAL; }
bool MCNativeControl::FormatColor(MCExecPoint& ep, uint16_t p_red, uint16_t p_green, uint16_t p_blue, uint16_t p_alpha) { char *t_colorstring = nil; p_red >>= 8; p_green >>= 8; p_blue >>= 8; p_alpha >>= 8; if (p_alpha != 255) MCCStringFormat(t_colorstring, "%u,%u,%u,%u", p_red, p_green, p_blue, p_alpha); else MCCStringFormat(t_colorstring, "%u,%u,%u", p_red, p_green, p_blue); ep.grabbuffer(t_colorstring, MCCStringLength(t_colorstring)); return true; }
static bool cgi_multipart_get_boundary(char *&r_boundary) { bool t_success = true; char *t_content_type; t_content_type = MCS_getenv("CONTENT_TYPE"); char *t_params = NULL; uint32_t t_index = 0; char **t_names = NULL; char **t_values = NULL; uint32_t t_param_count = 0; t_success = MCCStringFirstIndexOf(t_content_type, ';', t_index); if (t_success) t_success = MCMultiPartParseHeaderParams(t_content_type + t_index + 1, t_names, t_values, t_param_count); r_boundary = NULL; if (t_success) { for (uint32_t i = 0; i < t_param_count; i++) { if (MCCStringEqualCaseless(t_names[i], "boundary") && MCCStringLength(t_values[i]) > 0) { r_boundary = t_values[i]; t_values[i] = NULL; break; } } } if (t_success) t_success = r_boundary != NULL; for (uint32_t i = 0; i < t_param_count; i++) { MCCStringFree(t_names[i]); MCCStringFree(t_values[i]); } MCMemoryDeleteArray(t_names); MCMemoryDeleteArray(t_values); return t_success; }
static bool cgi_send_cookies(void) { bool t_success = true; char *t_cookie_header = NULL; MCExecPoint ep; for (uint32_t i = 0; t_success && i < MCservercgicookiecount; i++) { t_success = MCCStringFormat(t_cookie_header, "Set-Cookie: %s=%s", MCservercgicookies[i].name, MCservercgicookies[i].value); if (t_success && MCservercgicookies[i].expires != 0) { ep.setuint(MCservercgicookies[i].expires); t_success = MCD_convert(ep, CF_SECONDS, CF_UNDEFINED, CF_INTERNET_DATE, CF_UNDEFINED); if (t_success) { MCString t_date; t_date = ep.getsvalue(); t_success = MCCStringAppendFormat(t_cookie_header, "; Expires=%.*s", t_date.getlength(), t_date.getstring()); } } if (t_success && MCservercgicookies[i].path != NULL) t_success = MCCStringAppendFormat(t_cookie_header, "; Path=%s", MCservercgicookies[i].path); if (t_success && MCservercgicookies[i].domain != NULL) t_success = MCCStringAppendFormat(t_cookie_header, "; Domain=%s", MCservercgicookies[i].domain); if (t_success && MCservercgicookies[i].secure) t_success = MCCStringAppend(t_cookie_header, "; Secure"); if (t_success && MCservercgicookies[i].http_only) t_success = MCCStringAppend(t_cookie_header, "; HttpOnly"); if (t_success) t_success = MCCStringAppend(t_cookie_header, "\n"); if (t_success) t_success = IO_NORMAL == MCS_write(t_cookie_header, 1, MCCStringLength(t_cookie_header), IO_stdout); MCCStringFree(t_cookie_header); t_cookie_header = NULL; } return t_success; }
bool MCAdGetTopLeftOfAd(MCExecContext& ctxt, const char *p_name, MCAdTopLeft &r_top_left) { if (s_inneractive_ad_key == nil || MCCStringLength(s_inneractive_ad_key) == 0) { ctxt.SetTheResultToStaticCString("not registered with ad service"); return false; } MCAd *t_ad; t_ad = nil; if (!MCAd::FindByNameOrId(p_name, t_ad)) { ctxt.SetTheResultToStaticCString("could not find ad"); return false; } else { r_top_left = t_ad->GetTopLeft(); return true; } }
void MCGContextDrawPlatformText(MCGContextRef self, const unichar_t *p_text, uindex_t p_length, MCGPoint p_location, const MCGFont &p_font) { if (!MCGContextIsValid(self)) return; bool t_success; t_success = true; char *t_text; t_text = nil; if (t_success) t_success = MCCStringFromUnicodeSubstring(p_text, p_length / 2, t_text); if (t_success) { SkPaint t_paint; t_paint . setStyle(SkPaint::kFill_Style); t_paint . setAntiAlias(true); t_paint . setColor(MCGColorToSkColor(self -> state -> fill_color)); t_paint . setTextSize(p_font . size); SkXfermode *t_blend_mode; t_blend_mode = MCGBlendModeToSkXfermode(self -> state -> blend_mode); t_paint . setXfermode(t_blend_mode); if (t_blend_mode != NULL) t_blend_mode -> unref(); SkTypeface *t_typeface; t_typeface = (SkTypeface *) p_font . fid; t_paint . setTypeface(t_typeface); // MM-2013-12-05: [[ Bug 11527 ]] Make sure we calculate the UTF-8 string length correctly. uindex_t t_length; t_length = MCCStringLength(t_text); self -> layer -> canvas -> drawText(t_text, t_length, MCGCoordToSkCoord(p_location . x), MCGCoordToSkCoord(p_location . y), t_paint); } MCCStringFree(t_text); self -> is_valid = t_success; }
static void compute_simulator_redirect(const char *p_input, char*& r_output) { if (s_redirects == nil) { r_output = (char *)p_input; return; } char *t_resolved_input; t_resolved_input = nil; if (*p_input != '/') { char *t_cwd; t_cwd = getcwd(nil, 0); MCCStringFormat(t_resolved_input, "%s/%s", t_cwd, p_input); free(t_cwd); } else MCCStringClone(p_input, t_resolved_input); char **t_components; uint32_t t_component_count; MCCStringSplit(t_resolved_input, '/', t_components, t_component_count); MCCStringFree(t_resolved_input); uint32_t t_count; t_count = 1; for(uint32_t j = 1; j < t_component_count; j++) { if (MCCStringEqual(t_components[j], ".") || MCCStringEqual(t_components[j], "")) { MCCStringFree(t_components[j]); continue; } if (MCCStringEqual(t_components[j], "..")) { MCCStringFree(t_components[j]); if (t_count > 1) { MCCStringFree(t_components[t_count - 1]); t_count -= 1; } continue; } t_components[t_count] = t_components[j]; t_count += 1; } MCCStringCombine(t_components, t_count, '/', t_resolved_input); MCCStringArrayFree(t_components, t_count); r_output = t_resolved_input; if (MCCStringBeginsWith(t_resolved_input, s_redirect_base)) { const char *t_input_leaf; t_input_leaf = t_resolved_input + strlen(s_redirect_base) + 1; for(uint32_t i = 0; i < s_redirect_count; i++) { if (MCCStringEqual(s_redirects[i] . src, t_input_leaf)) { r_output = strdup(s_redirects[i] . dst); break; } if (MCCStringBeginsWith(t_input_leaf, s_redirects[i] . src) && t_input_leaf[MCCStringLength(s_redirects[i] . src)] == '/') { MCCStringFormat(r_output, "%s%s", s_redirects[i] . dst, t_input_leaf + MCCStringLength(s_redirects[i] . src)); break; } } } if (r_output != t_resolved_input) MCCStringFree(t_resolved_input); }
// This method constructs and then writes out a capsule to the given output file. // The capsule contents is derived from the deploy parameters structure. // The offset in the file after writing is returned in x_offset. bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_output, uint32_t& x_offset) { bool t_success; t_success = true; // Open the stackfile. MCDeployFileRef t_stackfile; t_stackfile = NULL; if (t_success && !MCDeployFileOpen(p_params . stackfile, "rb", t_stackfile)) t_success = MCDeployThrow(kMCDeployErrorNoStackfile); // Open the spill file, if required MCDeployFileRef t_spill; t_spill = NULL; if (t_success && p_params . spill != nil && !MCDeployFileOpen(p_params . spill, "wb+", t_spill)) t_success = MCDeployThrow(kMCDeployErrorNoSpill); // First create our deployment capsule MCDeployCapsuleRef t_capsule; t_capsule = nil; if (t_success) t_success = MCDeployCapsuleCreate(t_capsule); // Next, the first thing to do is to add the the header section. if (t_success) t_success = MCDeployWriteCapsuleDefineStandaloneSections(p_params, t_capsule); // Add any redirects if (t_success) for(uint32_t i = 0; i < p_params . redirect_count && t_success; i++) t_success = MCDeployCapsuleDefine(t_capsule, kMCCapsuleSectionTypeRedirect, p_params . redirects[i], MCCStringLength(p_params . redirects[i]) + 1); // Now we add the main stack if (t_success) t_success = MCDeployCapsuleDefineFromFile(t_capsule, kMCCapsuleSectionTypeStack, t_stackfile); // Now we add the auxillary stackfiles, if any MCDeployFileRef *t_aux_stackfiles; t_aux_stackfiles = nil; if (t_success) t_success = MCMemoryNewArray(p_params . auxillary_stackfile_count, t_aux_stackfiles); if (t_success) for(uint32_t i = 0; i < p_params . auxillary_stackfile_count && t_success; i++) { if (t_success && !MCDeployFileOpen(p_params . auxillary_stackfiles[i], "rb", t_aux_stackfiles[i])) t_success = MCDeployThrow(kMCDeployErrorNoAuxStackfile); if (t_success) t_success = MCDeployCapsuleDefineFromFile(t_capsule, kMCCapsuleSectionTypeAuxillaryStack, t_aux_stackfiles[i]); } // Now add the externals, if any if (t_success) for(uint32_t i = 0; i < p_params . external_count && t_success; i++) t_success = MCDeployCapsuleDefine(t_capsule, kMCCapsuleSectionTypeExternal, p_params . externals[i], MCCStringLength(p_params . externals[i]) + 1); // Now add the startup script, if any. if (t_success && p_params . startup_script != nil) t_success = MCDeployCapsuleDefine(t_capsule, kMCCapsuleSectionTypeStartupScript, p_params . startup_script, MCCStringLength(p_params . startup_script) + 1); // Now a digest if (t_success) t_success = MCDeployCapsuleChecksum(t_capsule); // Finally the epilogue if (t_success) t_success = MCDeployCapsuleDefine(t_capsule, kMCCapsuleSectionTypeEpilogue, nil, 0); // Now we write it if (t_success) t_success = MCDeployCapsuleGenerate(t_capsule, p_output, t_spill, x_offset); MCDeployCapsuleDestroy(t_capsule); for(uint32_t i = 0; i < p_params . auxillary_stackfile_count; i++) MCDeployFileClose(t_aux_stackfiles[i]); MCMemoryDeleteArray(t_aux_stackfiles); MCDeployFileClose(t_spill); MCDeployFileClose(t_stackfile); return t_success; }
// This call is primarily designed to be used by the plugin installer. As this // is generally installed 'per-user', we simply scan '/proc' for processes owned // by the calling user. bool MCSystemListProcesses(MCSystemListProcessesCallback p_callback, void* p_context) { bool t_success; t_success = true; DIR *t_dir; t_dir = nil; if (t_success) { t_dir = opendir("/proc"); if (t_dir == nil) t_success = false; } if (t_success) { dirent *t_entry; while(t_success) { // Fetch the next entry t_entry = readdir(t_dir); if (t_entry == nil) break; // Work out if the entry is a process id int32_t t_pid; MCAutoStringRef t_dname; /* UNCHECKED */ MCStringCreateWithCString(t_entry -> d_name, &t_dname); if (!MCU_strtol(*t_dname, t_pid)) continue; // Work out the full path ("/proc/<int>") and stat so we can // check ownership. char t_path[6 + I4L + 1]; struct stat64 t_stat; sprintf(t_path, "/proc/%u", t_pid); stat64(t_path, &t_stat); if (t_stat . st_uid != getuid()) continue; // We have a viable process to report. First fetch its path MCAutoStringRef t_exe_link, t_exe_path; /* UNCHECKED */ MCStringFormat(&t_exe_link, "/proc/%u/exe", t_pid); if (!MCS_resolvepath(*t_exe_link, &t_exe_path)) { t_success = false; break; } // Next fetch its 'description' from the first line of the status // file. char t_status_file[6 + I4L + 7 + 1]; char t_status[256]; FILE *t_stream; sprintf(t_status_file, "/proc/%u/status", t_pid); t_stream = fopen(t_status_file, "r"); if (t_stream != nil) { if (fgets(t_status, 256, t_stream) != nil) { char *t_tab; t_tab = strchr(t_status, '\t'); if (t_tab != nil) MCMemoryMove(t_status, t_tab + 1, MCCStringLength(t_tab + 1)); } else t_status[0] = '\0'; fclose(t_stream); } else t_status[0] = '\0'; MCAutoStringRef t_status_str; /* UNCHECKED */ MCStringCreateWithSysString(t_status, &t_status_str); t_success = p_callback(p_context, t_pid, *t_exe_path, *t_status_str); } } if (t_dir != nil) closedir(t_dir); return t_success; }
static bool cgi_multipart_body_callback(void *p_context, const char *p_data, uint32_t p_data_length, bool p_finished, bool p_truncated) { cgi_multipart_context_t *t_context = (cgi_multipart_context_t*)p_context; bool t_success = true; if (cgi_context_is_form_data(t_context)) { if (t_context->post_binary_variable != NULL) { t_success = t_context->post_binary_variable->append_string(MCString(p_data, p_data_length)); if (t_success && p_finished) { uint32_t t_native_length; char *t_native = NULL; MCString t_value; t_value = t_context->post_binary_variable->get_string(); if (cgi_native_from_encoding(MCserveroutputtextencoding, t_value.getstring(), t_value.getlength(), t_native, t_native_length)) t_context->post_variable -> assign_buffer(t_native, t_native_length); } } } else if (cgi_context_is_file(t_context)) { if (t_context->file_status == kMCFileStatusOK) { if (IO_NORMAL == MCS_write(p_data, 1, p_data_length, t_context->file_handle)) t_context->file_size += p_data_length; else t_context->file_status = kMCFileStatusIOError; } if (t_success && (p_finished || p_truncated)) { MCExecPoint ep; MCVariableValue *t_file_varvalue = NULL; cgi_fetch_variable_value_for_key(s_cgi_files, t_context->name, MCCStringLength(t_context->name), ep, t_context->file_variable); if (t_context->file_status == kMCFileStatusOK && t_context->file_size == 0) t_context->file_status = kMCFileStatusFailed; if (p_truncated) t_context->file_status = kMCFileStatusStopped; ep.setsvalue(MCString(t_context->file_name)); t_context->file_variable->store_element(ep, MCString("name")); ep.setsvalue(MCString(t_context->type)); t_context->file_variable->store_element(ep, MCString("type")); ep.setsvalue(MCString(t_context->temp_name)); t_context->file_variable->store_element(ep, MCString("filename")); ep.setuint(t_context->file_size); t_context->file_variable->store_element(ep, MCString("size")); if (t_context->file_status != kMCFileStatusOK) { ep.setsvalue(MCMultiPartGetErrorMessage(t_context->file_status)); t_context->file_variable->store_element(ep, MCString("error")); } } } if (t_success && p_finished) { // clear context for next part cgi_dispose_multipart_context(t_context); } return t_success; }
// This method reads a stack from the given stream. The stack is set to // have parent MCDispatch, and filename MCcmd. It is designed to be used // for embedded stacks/deployed stacks/revlet stacks. IO_stat MCDispatch::readstartupstack(IO_handle stream, MCStack*& r_stack) { char version[8]; uint1 charset, type; char *newsf; if (readheader(stream, version) != IO_NORMAL || IO_read_uint1(&charset, stream) != IO_NORMAL || IO_read_uint1(&type, stream) != IO_NORMAL || IO_read_string(newsf, stream) != IO_NORMAL) return IO_ERROR; // MW-2008-10-20: [[ ParentScripts ]] Set the boolean flag that tells us whether // parentscript resolution is required to false. s_loaded_parent_script_reference = false; MCtranslatechars = charset != CHARSET; delete newsf; // stackfiles is obsolete MCStack *t_stack = nil; /* UNCHECKED */ MCStackSecurityCreateStack(t_stack); t_stack -> setparent(this); // MM-2013-10-30: [[ Bug 11333 ]] Set the filename of android mainstack to apk/mainstack (previously was just apk). // This solves relative file path referencing issues. #ifdef TARGET_SUBPLATFORM_ANDROID char *t_filename; /* UNCHECKED */ MCMemoryNewArray(MCCStringLength(MCcmd) + 11, t_filename); MCCStringFormat(t_filename, "%s/mainstack", MCcmd); t_stack -> setfilename(t_filename); #else t_stack -> setfilename(strclone(MCcmd)); #endif if (IO_read_uint1(&type, stream) != IO_NORMAL || type != OT_STACK && type != OT_ENCRYPT_STACK || t_stack->load(stream, version, type) != IO_NORMAL) { delete t_stack; return IO_ERROR; } if (t_stack->load_substacks(stream, version) != IO_NORMAL || IO_read_uint1(&type, stream) != IO_NORMAL || type != OT_END) { delete t_stack; return IO_ERROR; } // We are reading the startup stack, so this becomes the root of the // stack list. stacks = t_stack; r_stack = t_stack; #ifndef _MOBILE // Make sure parent script references are up to date. if (s_loaded_parent_script_reference) t_stack -> resolveparentscripts(); #else // Mark the stack as needed parentscript resolution. This is done after // aux stacks have been loaded. if (s_loaded_parent_script_reference) t_stack -> setextendedstate(True, ECS_USES_PARENTSCRIPTS); #endif return IO_NORMAL; }
bool MCImageSplitScaledFilename(const char *p_filename, char *&r_base, char *&r_extension, bool &r_has_scale, MCGFloat &r_scale) { if (p_filename == nil) return false; bool t_success; t_success = true; MCGFloat t_scale; bool t_has_scale = false; uint32_t t_length; t_length = MCCStringLength(p_filename); uint32_t t_index, t_name_start, t_label_start, t_label_search_start, t_ext_start; if (MCCStringLastIndexOf(p_filename, '/', t_index)) t_name_start = t_index + 1; else t_name_start = 0; if (MCCStringLastIndexOf(p_filename + t_name_start, '.', t_index)) t_ext_start = t_name_start + t_index; else t_ext_start = t_length; // find first '@' char before the extension part t_label_start = t_label_search_start = t_name_start; while (MCCStringFirstIndexOf(p_filename + t_label_search_start, '@', t_index)) { if (t_label_start + t_index > t_ext_start) break; t_label_start += t_index; t_label_search_start = t_label_start + 1; } // check label begins with '@' if (p_filename[t_label_start] != '@') { // no scale label t_label_start = t_ext_start; } else { t_has_scale = MCImageGetScaleForLabel(p_filename + t_label_start, t_ext_start - t_label_start, t_scale); if (!t_has_scale) { // @... is not a recognised scale t_label_start = t_ext_start; } } char *t_base, *t_extension; t_base = t_extension = nil; t_success = MCCStringCloneSubstring(p_filename, t_label_start, t_base) && MCCStringCloneSubstring(p_filename + t_ext_start, t_length - t_ext_start, t_extension); if (t_success) { r_base = t_base; r_extension = t_extension; r_has_scale = t_has_scale; r_scale = t_has_scale ? t_scale : 1.0; } else { MCCStringFree(t_base); MCCStringFree(t_extension); } return t_success; }
static bool cgi_multipart_header_callback(void *p_context, MCMultiPartHeader *p_header) { bool t_success = true; cgi_multipart_context_t *t_context = (cgi_multipart_context_t*)p_context; if (p_header != NULL) { if (MCCStringEqualCaseless(p_header->name, "Content-Disposition")) { if (MCCStringEqualCaseless(p_header->value, "form-data")) t_context->disposition = kMCDispositionFormData; else if (MCCStringEqualCaseless(p_header->value, "file")) t_context->disposition = kMCDispositionFile; else t_context->disposition = kMCDispositionUnknown; for (uint32_t i = 0; i < p_header->param_count; i++) { if (MCCStringEqualCaseless(p_header->param_name[i], "name")) grab_string(t_context->name, p_header->param_value[i]); else if (MCCStringEqualCaseless(p_header->param_name[i], "filename")) grab_string(t_context->file_name, p_header->param_value[i]); } } else if (MCCStringEqualCaseless(p_header->name, "Content-Type")) { grab_string(t_context->type, p_header->value); for (uint32_t i = 0; i < p_header->param_count; i++) { if (MCCStringEqualCaseless(p_header->param_name[i], "boundary")) grab_string(t_context->boundary, p_header->param_value[i]); } } } else { if (cgi_context_is_form_data(t_context)) { MCExecPoint ep; t_success = t_context->name != NULL; if (t_success) { cgi_fetch_variable_value_for_key(s_cgi_post, t_context->name, MCCStringLength(t_context->name), ep, t_context->post_variable); t_context->post_variable->assign_empty(); cgi_fetch_variable_value_for_key(s_cgi_post_binary, t_context->name, MCCStringLength(t_context->name), ep, t_context->post_binary_variable); t_context->post_binary_variable->assign_empty(); } } else if (cgi_context_is_file(t_context)) { const char *t_temp_dir = cgi_get_upload_temp_dir(); const char *t_error = NULL; if (t_temp_dir == NULL || !MCS_exists(t_temp_dir, False)) { t_context->file_status = kMCFileStatusNoUploadFolder; } else if (!MCMultiPartCreateTempFile(cgi_get_upload_temp_dir(), t_context->file_handle, t_context->temp_name)) { t_context->file_status = kMCFileStatusIOError; } } } return t_success; }