int gif_writeFunc(GifFileType *p_gif, const GifByteType *p_buffer, int p_byte_count) { MCGIFWriteContext *t_context = (MCGIFWriteContext*)p_gif->UserData; uindex_t t_byte_count = p_byte_count; /* UNCHECKED */ MCS_write(p_buffer, sizeof(GifByteType), t_byte_count, t_context->stream); t_context->byte_count += t_byte_count; return t_byte_count; }
static bool cgi_send_headers(void) { bool t_sent_content; t_sent_content = false; for(uint32_t i = 0; i < MCservercgiheadercount; i++) { if (strncasecmp("Content-Type:", MCservercgiheaders[i], 13) == 0) t_sent_content = true; if (MCS_write(MCservercgiheaders[i], 1, strlen(MCservercgiheaders[i]), IO_stdout) != IO_NORMAL) return false; if (MCS_write("\n", 1, 1, IO_stdout) != IO_NORMAL) return false; } if (!t_sent_content) { char t_content_header[128]; switch(MCserveroutputtextencoding) { case kMCSOutputTextEncodingWindows1252: sprintf(t_content_header, "Content-Type: text/html; charset=windows-1252\n"); break; case kMCSOutputTextEncodingMacRoman: sprintf(t_content_header, "Content-Type: text/html; charset=macintosh\n"); break; case kMCSOutputTextEncodingISO8859_1: sprintf(t_content_header, "Content-Type: text/html; charset=iso-8859-1\n"); break; case kMCSOutputTextEncodingUTF8: sprintf(t_content_header, "Content-Type: text/html; charset=utf-8\n"); break; } if (MCS_write(t_content_header, 1, strlen(t_content_header), IO_stdout) != IO_NORMAL) return false; } if (MCS_write("\n", 1, 1, IO_stdout) != IO_NORMAL) return false; return true; }
bool MCStreamCache::AppendToCache(void *p_buffer, uint32_t p_length, uint32_t &r_written) { bool t_success = true; if (m_cache_length + p_length > m_buffer_limit) { if (m_cache_file == NULL) { t_success = MCMultiPartCreateTempFile(cgi_get_upload_temp_dir(), m_cache_file, m_cache_filename); if (t_success && m_cache_buffer != NULL) t_success = (IO_NORMAL == MCS_write(m_cache_buffer, 1, m_cache_length, m_cache_file)); MCMemoryDeallocate(m_cache_buffer); m_cache_buffer = NULL; } if (t_success) t_success = (IO_NORMAL == MCS_write(p_buffer, 1, p_length, m_cache_file)); m_cache_length += p_length; r_written = p_length; } else { if (m_cache_buffer == NULL) t_success = MCMemoryAllocate(m_buffer_limit, m_cache_buffer); if (t_success) { MCMemoryCopy((uint8_t*)m_cache_buffer + m_cache_length, p_buffer, p_length); m_cache_length += p_length; r_written = p_length; } } 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; }
static bool MCS_downloadurl_callback(void *p_context, MCSystemUrlStatus p_status, const void *p_data) { MCSDownloadUrlState *context; context = static_cast<MCSDownloadUrlState *>(p_context); context -> status = p_status; if (p_status == kMCSystemUrlStatusError) MCresult -> sets((const char *)p_data); else if (p_status == kMCSystemUrlStatusLoading) { context -> length += ((const MCString *)p_data) -> getlength(); MCS_write(((const MCString *)p_data) -> getstring(), ((const MCString *)p_data) -> getlength(), 1, context -> output); } send_url_progress(context -> object, p_status, context -> url, context -> length, context -> total, (const char *)p_data); return true; }
IO_stat IO_write_int1(int1 dest, IO_handle stream) { return MCS_write(&dest, sizeof(int1), 1, stream); }
IO_stat IO_write_int2(int2 dest, IO_handle stream) { swap_int2(&dest); return MCS_write(&dest, sizeof(int2), 1, stream); }
IO_stat IO_write_uint4(uint4 dest, IO_handle stream) { swap_uint4(&dest); return MCS_write(&dest, sizeof(uint4), 1, stream); }
IO_stat IO_write_real4(real4 dest, IO_handle stream) { return MCS_write(&dest, sizeof(real4), 1, stream); }
IO_stat IO_write(const void *ptr, uint4 size, uint4 n, IO_handle stream) { return MCS_write(ptr, size, n, stream); }
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; }