static bool types_to_remote_types(char * const p_types[], uint4 p_type_count, char**& r_rtypes) { char **t_rtypes; if (!MCMemoryNewArray(p_type_count * 2, t_rtypes)) return false; for(uint32_t i = 0; i < p_type_count; i++) { uint32_t t_part_count; char **t_parts; if (MCCStringSplit(p_types[i], '|', t_parts, t_part_count)) { if (t_part_count > 0) { MCCStringClone(t_parts[0], t_rtypes[i * 2]); if (t_part_count > 1) MCCStringClone(t_parts[1], t_rtypes[i * 2 + 1]); } MCCStringArrayFree(t_parts, t_part_count); } } r_rtypes = t_rtypes; return true; }
MCReferencedImageRep::MCReferencedImageRep(const char *p_file_name, const char *p_search_key) { /* UNCHECKED */ MCCStringClone(p_file_name, m_file_name); /* UNCHECKED */ MCCStringClone(p_search_key, m_search_key); m_url_data = nil; // MW-2013-09-25: [[ Bug 10983 ]] No load has yet been attempted. m_url_load_attempted = false; }
bool MCFileSystemPathResolve(const char *p_path, char*& r_resolved_path) { char t_path[PATH_MAX]; ssize_t t_size; t_size = readlink(p_path, t_path, PATH_MAX); if (t_size == -1 || t_size == PATH_MAX) { if (errno == EINVAL) return MCCStringClone(p_path, r_resolved_path); return false; } t_path[t_size] = '\0'; return MCCStringClone(t_path, r_resolved_path); }
bool MCSessionCreateSession(MCSessionIndexRef p_index, MCStringRef p_session_id, MCSession *&r_session) { bool t_success = true; MCSession *t_session = NULL; 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); t_success = MCMemoryNew(t_session); if (t_success) t_success = MCCStringClone(t_remote_addr ? t_remote_addr : "", t_session->ip); if (t_success) { if (p_session_id != nil && !MCStringIsEmpty(p_session_id)) { t_session->id = strdup(MCStringGetCString(p_session_id)); t_success = true; } else { MCAutoStringRef t_session_id; t_success = MCSessionGenerateID(&t_session_id); t_session->id = strdup(MCStringGetCString(*t_session_id)); } } if (t_success) t_success = MCCStringFormat(t_session->filename, "%s_%s", t_remote_addr ? t_remote_addr : "", t_session->id); if (t_success) t_success = MCSessionIndexAddSession(p_index, t_session); if (t_success) r_session = t_session; else { if (t_session != NULL) MCSessionCloseSession(t_session, false); } return t_success; }
static MCAndroidCustomFont* look_up_custom_font(const char *p_name, bool p_bold, bool p_italic) { char *t_styled_name; t_styled_name = nil; if (!MCCStringClone(p_name, t_styled_name)) return nil; if (p_bold && !MCCStringAppend(t_styled_name, " Bold")) return nil; if (p_italic && !MCCStringAppend(t_styled_name, " Italic")) return nil; // Fist of all, attempt to look the font up by taking into account its name and style. // e.g. textFont:Arial textStyle:Bold - look for a font named Arial Bold. // This will fail for textFonts which include style information e.g. textFont:Arial textStyle:Bold will search for Arial Bold Bold MCAndroidCustomFont *t_font; t_font = look_up_custom_font_by_name(t_styled_name); /*UNCHECKED */ MCCStringFree(t_styled_name); if (t_font != nil) return t_font; // If no font found, look up based purley on the name. This will solve cases where style // information is included in the name e.g. Arial Bold. if (p_bold || p_italic) { t_font = look_up_custom_font_by_name(p_name); if (t_font != nil) return t_font; } // If we've still not found a matching font, look up based on the family and style. // This function will attempt to provide a closest match e.g. Arial Bold is requested but only Arial is installed. t_font = look_up_custom_font_by_family_and_style(p_name, p_bold, p_italic); return t_font; }
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); }
bool MCSystemProcessUrl(const char *p_url, MCSystemUrlOperation p_operations, char *&r_processed_url) { bool t_success = true; char *t_processed = nil; if (t_success && (p_operations & kMCSystemUrlOperationStrip)) { char *t_stripped = nil; t_success = MCSystemStripUrl(t_processed != nil ? t_processed : p_url, t_stripped); if (t_success) { MCCStringFree(t_processed); t_processed = t_stripped; } } // if no processing, just return a copy of the input url if (t_success && t_processed == nil) t_success = MCCStringClone(p_url, t_processed); if (t_success) r_processed_url = t_processed; else MCCStringFree(t_processed); return t_success; }
static bool MCActivityIndicatorTypeToCString(MCSensorType p_indicator, char *&r_string) { #ifdef /* MCActivityIndicatorTypeToCString */ LEGACY_EXEC switch (p_indicator) { case kMCActivityIndicatorWhite: return MCCStringClone("white", r_string); case kMCActivityIndicatorWhiteLarge: return MCCStringClone("large white", r_string); case kMCActivityIndicatorGray: return MCCStringClone("gray", r_string); default: return MCCStringClone("unknown", r_string); } return false; #endif /* MCActivityIndicatorTypeToCString */ }
bool MCDispatch::loadexternal(const char *p_external) { char *t_filename; #if defined(TARGET_SUBPLATFORM_ANDROID) extern bool revandroid_loadExternalLibrary(const char *p_external, char*& r_filename); // MW-2013-08-07: [[ ExternalsApiV5 ]] Make sure we only use the leaf name // of the external when loading. if (strrchr(p_external, '/') != nil) p_external = strrchr(p_external, '/') + 1; if (!revandroid_loadExternalLibrary(p_external, t_filename)) return false; // Don't try and load any drivers as externals. if (strncmp(p_external, "db", 2) == 0) { delete t_filename; return true; } #elif !defined(_SERVER) if (p_external[0] == '/') { if (!MCCStringClone(p_external, t_filename)) return false; } else if (!MCCStringFormat(t_filename, "%.*s/%s", strrchr(MCcmd, '/') - MCcmd, MCcmd, p_external)) return false; #else if (!MCCStringClone(p_external, t_filename)) return false; #endif if (m_externals == nil) m_externals = new MCExternalHandlerList; bool t_loaded; t_loaded = m_externals -> Load(t_filename); delete t_filename; if (m_externals -> IsEmpty()) { delete m_externals; m_externals = nil; } return t_loaded; }
static bool MCBusyIndicatorTypeToCString(MCSensorType p_indicator, char *&r_string) { #ifdef /* MCBusyIndicatorTypeToCString */ LEGACY_EXEC switch (p_indicator) { case kMCBusyIndicatorInLine: return MCCStringClone("in line", r_string); case kMCBusyIndicatorSquare: return MCCStringClone("square", r_string); case kMCBusyIndicatorKeyboard: return MCCStringClone("keyboard", r_string); default: return MCCStringClone("unknown", r_string); } return false; #endif /* MCBusyIndicatorTypeToCString */ }
MCUrlLoadEvent *MCUrlLoadEvent::CreateUrlLoadEvent(MCObjectHandle *p_object, MCNameRef p_message, const char *p_url, MCSystemUrlStatus p_status, void *p_data, uint32_t p_size, const char *p_error) { MCUrlLoadEvent *t_event; t_event = new MCUrlLoadEvent(); if (t_event == nil) return nil; t_event->m_url = nil; t_event->m_object = nil; t_event->m_status = kMCSystemUrlStatusNone; t_event->m_error = nil; t_event->m_message = nil; bool t_success; t_success = true; if (t_success) t_success = MCCStringClone(p_url, t_event->m_url); if (t_success) t_success = MCNameClone(p_message, t_event->m_message); if (t_success && p_status == kMCSystemUrlStatusError) t_success = MCCStringClone(p_error, t_event->m_error); if (t_success) { t_event->m_status = p_status; t_event->m_object = p_object; t_event->m_object->Retain(); if (t_event->m_status == kMCSystemUrlStatusFinished) { t_event->m_data.bytes = p_data; t_event->m_data.size = p_size; } } else { MCCStringFree(t_event->m_url); MCNameDelete(t_event->m_message); MCCStringFree(t_event->m_error); delete t_event; return nil; } return t_event; }
Exec_stat MCHandleStartActivityIndicator(void *p_context, MCParameter *p_parameters) { #ifdef /* MCHandleStartActivityIndicator */ LEGACY_EXEC MCActivityIndicatorType t_indicator_type; t_indicator_type = kMCActivityIndicatorWhite; char *t_style; t_style = nil; MCLocation t_location; t_location.x = -1; t_location.y = -1; MCExecPoint ep(nil, nil, nil); if (p_parameters != nil) { p_parameters->eval(ep); // Provide backwards compatibility here for "whiteLarge" rather than "large white". if (MCCStringEqualCaseless (ep.getsvalue().getstring(), "whiteLarge")) MCCStringClone("large white", t_style); else t_style = ep.getsvalue().clone(); if (t_style != nil) p_parameters = p_parameters->getnext(); } if (p_parameters != nil) { p_parameters->eval(ep); if (ep.getformat() != VF_STRING || ep.ston() == ES_NORMAL) { t_location.x = ep.getint4(); p_parameters = p_parameters->getnext(); if (p_parameters != nil) { p_parameters->eval(ep); if (ep.getformat() != VF_STRING || ep.ston() == ES_NORMAL) { t_location.y = ep.getint4(); p_parameters = p_parameters->getnext(); } } } if (t_location.y == -1) t_location.x = -1; } MCExecContext t_ctxt(ep); t_ctxt . SetTheResultToEmpty(); if (t_style != nil) t_indicator_type = MCActivityIndicatorTypeFromCString(t_style); MCActivityIndicatorExecStart(t_ctxt, t_indicator_type, t_location); return t_ctxt.GetStat(); #endif /* MCHandleStartActivityIndicator */ }
MCUrlProgressEvent *MCUrlProgressEvent::CreateUrlProgressEvent(MCObjectHandle *p_object, const char *p_url, MCSystemUrlStatus p_status, uint32_t p_amount, uint32_t p_total, const char *p_error) { MCUrlProgressEvent *t_event; t_event = new MCUrlProgressEvent(); if (t_event == nil) return nil; t_event->m_url = nil; t_event->m_object = nil; t_event->m_status = kMCSystemUrlStatusNone; t_event->m_error = nil; bool t_success; t_success = true; if (t_success) t_success = MCCStringClone(p_url, t_event->m_url); if (t_success && p_status == kMCSystemUrlStatusError) t_success = MCCStringClone(p_error, t_event->m_error); if (t_success) { t_event->m_status = p_status; t_event->m_object = p_object; t_event->m_object->Retain(); if (t_event->m_status == kMCSystemUrlStatusUploading || t_event->m_status == kMCSystemUrlStatusLoading) { t_event->m_transferred.amount = p_amount; t_event->m_transferred.total = p_total; } } else { MCCStringFree(t_event->m_url); MCCStringFree(t_event->m_error); delete t_event; return nil; } return t_event; }
bool MCS_set_session_name(const char *p_name) { char *t_name = nil; if (!MCCStringClone(p_name, t_name)) return false; MCCStringFree(MCsessionname); MCsessionname = t_name; return true; }
bool MCS_set_session_save_path(const char *p_path) { char *t_save_path = nil; if (!MCCStringClone(p_path, t_save_path)) return false; MCCStringFree(MCsessionsavepath); MCsessionsavepath = t_save_path; return true; }
MCDensityMappedImageRep::MCDensityMappedImageRep(const char *p_filename) { m_sources = nil; m_source_densities = nil; m_source_count = 0; m_last_density = 1.0; m_locked = false; m_filename = nil; /* UNCHECKED */ MCCStringClone(p_filename, m_filename); }
bool MCNativeControl::SetName(const char *p_name) { if (m_name != nil) { MCCStringFree(m_name); m_name = nil; } if (p_name != nil) return MCCStringClone(p_name, m_name); return true; }
bool MCSessionCopySession(MCSession *p_src, MCSession *&r_dst) { bool t_success = true; MCSession *t_session; t_success = MCMemoryNew(t_session); if (t_success) t_success = MCCStringClone(p_src->id, t_session->id); if (t_success) t_success = MCCStringClone(p_src->ip, t_session->ip); if (t_success) t_success = MCCStringClone(p_src->filename, t_session->filename); if (t_success) t_session->expires = p_src->expires; if (t_success) r_dst = t_session; else MCSessionDisposeSession(t_session); return t_success; }
bool MCAdGetAds(MCExecContext& ctxt, char*& r_ads) { bool t_success; t_success = true; for(MCAd *t_ad = s_ads; t_ad != nil && t_success; t_ad = t_ad->GetNext()) if (t_ad->GetName() != nil) { if (r_ads == nil) t_success = MCCStringClone(t_ad->GetName(), r_ads); else t_success = MCCStringAppendFormat(r_ads, "\n%s", t_ad->GetName()); } return t_success; }
bool MCS_set_session_id(const char *p_id) { char *t_id = nil; if (s_current_session != NULL) return false; if (!MCCStringClone(p_id, t_id)) return false; MCCStringFree(MCsessionid); MCsessionid = t_id; return true; }
bool storeURLInfo(const char *p_url, MCSystemUrlCallback p_callback, void *p_context, MCUrlInfo *&r_info) { bool t_success = true; MCUrlInfo *t_info = nil; t_success = MCMemoryNew(t_info); if (t_success) t_success = MCCStringClone(p_url, t_info->url); if (t_success) { t_info->callback = p_callback; t_info->context = p_context; if (s_urlinfo_list == nil) { s_urlinfo_list = t_info; t_info->id = 1; } else { uint32_t t_id = s_urlinfo_list->id + 1; MCUrlInfo *t_list = s_urlinfo_list; while (t_list->next != NULL && t_list->next->id == t_id) { t_list = t_list->next; t_id++; } t_info->next = t_list->next; t_list->next = t_info; t_info->id = t_id; } } if (t_success) r_info = t_info; else { if (t_info != nil) MCCStringFree(t_info->url); MCMemoryDelete(t_info); } return t_success; }
static bool MCS_puturl_callback(void *p_context, MCSystemUrlStatus p_status, const void *p_data) { MCSPutUrlState *context; context = static_cast<MCSPutUrlState*>(p_context); context->status = p_status; if (p_status == kMCSystemUrlStatusError) MCCStringClone((const char*)p_data, context->error); if (p_status == kMCSystemUrlStatusUploading || p_status == kMCSystemUrlStatusUploaded) { context->put_sent = *(uint32_t*)p_data; send_url_progress(context->object, p_status, context->url, context->put_sent, context->put_length, nil); } else send_url_progress(context->object, p_status, context->url, context->put_sent, context->put_length, (const char*)p_data); return true; }
static void MCAndroidCustomFontsList(char *&r_font_names) { bool t_success; t_success = true; char *t_font_names; t_font_names = nil; for (MCAndroidCustomFont *t_font = s_custom_fonts; t_success && t_font != nil; t_font = t_font->next) { if (t_font_names == nil) t_success = MCCStringClone(t_font->name, t_font_names); else t_success = MCCStringAppendFormat(t_font_names, "\n%s", t_font->name); } if (t_success) r_font_names = t_font_names; else /*UNCHECKED */ MCCStringFree(t_font_names); }
JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doAskDialogDone(JNIEnv *env, jobject object, jstring result) { s_in_popup_dialog = false; if (s_popup_dialog_text != nil) { MCCStringFree(s_popup_dialog_text); s_popup_dialog_text = nil; } if (result != nil) { // TODO - java -> native string conversion const char *t_utfchars = nil; t_utfchars = env->GetStringUTFChars(result, nil); if (t_utfchars != nil) MCCStringClone(t_utfchars, s_popup_dialog_text); env->ReleaseStringUTFChars(result, t_utfchars); } MCAndroidBreakWait(); }
bool MCCStringFromJava(JNIEnv *env, jstring p_jstring, char *&r_cstring) { bool t_success = true; if (p_jstring == NULL) { r_cstring = NULL; return true; } const char *t_chars = nil; t_chars = env->GetStringUTFChars(p_jstring, NULL); t_success = t_chars != NULL; if (t_success) t_success = MCCStringClone(t_chars, r_cstring); if (t_chars != NULL) env->ReleaseStringUTFChars(p_jstring, t_chars); return t_success; }
void MCAdExecRegisterWithInneractive(MCExecContext& ctxt, const char *p_key) { MCCStringFree(s_inneractive_ad_key); /* UNCHECKED */ MCCStringClone(p_key, s_inneractive_ad_key); }
bool MCFileSystemPathResolve(const char *p_path, char*& r_resolved_path) { return MCCStringClone(p_path, r_resolved_path); }
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); }
static bool create_custom_font_from_path(const char *p_path, FT_Library p_library, MCAndroidCustomFont *&r_custom_font) { bool t_success; t_success = true; char *t_buffer; t_buffer = nil; uint32_t t_file_size; t_file_size = 0; if (t_success) t_success = load_custom_font_file_into_buffer_from_path(p_path, t_buffer, t_file_size); FT_Face t_font_face; t_font_face = nil; if (t_success) t_success = FT_New_Memory_Face(p_library, (FT_Byte *)t_buffer, t_file_size, 0, &t_font_face) == 0; MCAndroidCustomFont *t_font; t_font = nil; if (t_success) t_success = MCMemoryNew(t_font); if (t_success) t_success = MCCStringClone(p_path, t_font->path); if (t_success) t_success = MCCStringClone(t_font_face->family_name, t_font->family); if (t_success) { if (MCCStringEqualCaseless(t_font_face->style_name, "bold")) t_font->style = kMCAndroidFontStyleBold; else if (MCCStringEqualCaseless(t_font_face->style_name, "italic")) t_font->style = kMCAndroidFontStyleItalic; else if (MCCStringEqualCaseless(t_font_face->style_name, "bold italic")) t_font->style = kMCAndroidFontStyleBoldItalic; else t_font->style = kMCAndroidFontStyleRegular; } if (t_success) { FT_SfntName t_sft_name; for (uint32_t i = 0; i < FT_Get_Sfnt_Name_Count(t_font_face); i++) { // Attempt to fetch the name of the font. The name is name id 4 as defined in https://developer.apple.com/fonts/TTRefMan/RM06/Chap6name.html // It appears that the platform to use here is 1 (Macintosh according to the spec). FT_Get_Sfnt_Name(t_font_face, i, &t_sft_name); if (t_sft_name.name_id == 4 && t_sft_name.platform_id == 1 && t_sft_name.encoding_id == 0 && t_sft_name.language_id == 0 && t_sft_name.string_len != 0) { t_success = MCCStringCloneSubstring((char *)t_sft_name.string, t_sft_name.string_len, t_font->name); break; } } } if (t_success) t_success = t_font->name != nil; if (t_success) r_custom_font = t_font; else delete_custom_font(t_font); if (t_font_face != nil) FT_Done_Face(t_font_face); /*UNCHECKED */ MCMemoryDelete(t_buffer); return t_success; }
static bool MCTextLayoutFontLinkCallback(void *p_context, const char *p_key, DWORD p_type, void *p_value, uint32_t p_value_length) { bool t_success; t_success = true; // Ignore the empty key if (MCCStringEqual(p_key, "")) return true; // Ignore a non REG_MULTI_SZ type if (p_type != REG_MULTI_SZ) return true; // Create a new linked font structure MCTextLayoutLinkedFont *t_font; t_font = nil; if (t_success) t_success = MCMemoryNew(t_font); if (t_success) t_success = MCCStringClone(p_key, t_font -> name); // Attempt to parse the font link string - it should be of type // REG_MULTI_SZ and be a list of entries of the form: // file, face, [ scale, scale ] if (t_success) { char *t_ptr; uint32_t t_len; t_ptr = (char *)p_value; t_len = p_value_length; while(t_success && t_len > 0) { char *t_end; for(t_end = t_ptr; *t_end != '\0' && t_len > 0; t_end += 1, t_len -= 1) ; if (t_end - t_ptr > 0) { char **t_items; uint32_t t_item_count; t_items = nil; t_item_count = 0; if (t_success) t_success = MCCStringSplit(t_ptr, ',', t_items, t_item_count); if (t_item_count >= 2) { if (t_success) t_success = MCMemoryResizeArray(t_font -> entry_count + 1, t_font -> entries, t_font -> entry_count); if (t_success) t_success = MCCStringClone(t_items[1], t_font -> entries[t_font -> entry_count - 1] . face); } for(uint32_t i = 0; i < t_item_count; i++) MCCStringFree(t_items[i]); MCMemoryDeleteArray(t_items); } t_ptr = t_end + 1; t_len -= 1; } } if (t_success) MCListPushFront(s_linked_fonts, t_font); else MCTextLayoutLinkedFontDestroy(t_font); return t_success; }