Esempio n. 1
0
void PropertiesWindow::OnEndEdit(int mode)
{
	if (_Item)
	{
		for (int i = 0; i < _Properties.GetCount(); ++i)
		{
			String param = _Properties.GetKey(i);
			if (param.Find("Color") >= 0) // if color found
			{
				Color r = _Properties[i].GetData();
				_Item->Set(param, Encode64(StoreAsString(r)));
				continue;
			}
			String value = AsString(_Properties[i].GetData());
			_Item->Set(param, value);
		}

		if (mode)
		{
			_Options.EndEdit();
			_Options.ClearCursor();
			_Item->Set("Type", _Headers.Get(0, 1));
			Generate(_Item, _Index);
		}

		WhenChildZ.Execute();
	}
}
Esempio n. 2
0
/*  DoCreateOnePart (static)
 *
 *  Private function used to pipe a given file through the 1847 creator as
 *  either part 1 or part 2. All De-mime stuff is also done here.
 */
static int DoCreateOnePart(emsMIMEtypeP InPartMimePtr,
					 emsMIMEtypeP OutMimePtr,
					 TrEncType InPartCTE,
					 FILE *fIn,
					 FILE *fOut,
					 int nPart,
					 long nPreLen,
					 long nTotalInLen,
					 createStatePtr pState,
					 emsProgress progress)
{
	BufTypePtr pInBuf = makesize_buf(kBufferSize);

	if (!pInBuf)
		return (FILE1847_FAIL); // Could not create buffer -- error

	int nStatus = FILE1847_OK;

	// Do InPartMimePtr (Content-Type) header
	if ((nStatus == FILE1847_OK) && (InPartMimePtr))
	{
		char *pCT = string_mime_type(InPartMimePtr);
		
		if (pCT)
		{
			if (!DoCreateStringOutput(pCT, nPart, OutMimePtr, pState, fOut))
				nStatus = FILE1847_FAIL;
			else
				if (!DoCreateStringOutput("\r\n", nPart, OutMimePtr, pState, fOut))
					nStatus = FILE1847_FAIL;
		}
		else
			nStatus = FILE1847_FAIL;

		safefree(pCT);
	}

	// Do InPartCTE (Content-Transfer-Encoding) header
	if ((nStatus == FILE1847_OK) && (InPartCTE != CTE_NONE))
	{
		char *pCTE = rfc822_make_cte(InPartCTE);
		
		if (pCTE)
		{
			if (!DoCreateStringOutput(pCTE, nPart, OutMimePtr, pState, fOut))
				nStatus = FILE1847_FAIL;
			else
				if (!DoCreateStringOutput("\r\n", nPart, OutMimePtr, pState, fOut))
					nStatus = FILE1847_FAIL;
		}
		else
			nStatus = FILE1847_FAIL;

		safefree(pCTE);
	}

	// Do blank line -- only if we put out some header already
	if ((nStatus == FILE1847_OK) && ((InPartMimePtr) || (InPartCTE != CTE_NONE)))
	{
		if (!DoCreateStringOutput("\r\n", nPart, OutMimePtr, pState, fOut))
			nStatus = FILE1847_FAIL;
	}

	char *preEncBuffer = NULL;
	unsigned int preEncBufLen;

	Enc64Ptr e64state = NULL; // Used by Encode64()
	EncQPPtr eQPstate = NULL; // Used by EucodeQP()

	if (nStatus == FILE1847_OK)
	{
		switch (InPartCTE)
		{
			// BASE64
			case CTE_Base64:
			{
				// BASE64 expands about 1/3
				preEncBufLen = ((kBufferSize * 6) / 10);
				preEncBuffer = (char *) malloc(preEncBufLen);

				if (!preEncBuffer)
					nStatus = FILE1847_FAIL; // Could not create buffer

				e64state = (Enc64Ptr) malloc(sizeof(Enc64)); // Used by Encode64()
				e64state->partialCount = e64state->bytesOnLine = 0;
			}
			break;

			// QUOTED-PRINTABLE
			case CTE_QP:
			{
				// QP expands max of 3 times
				preEncBufLen = (kBufferSize / 4);
				preEncBuffer = (char *) malloc(preEncBufLen);

				if (!preEncBuffer)
					nStatus = FILE1847_FAIL; // Could not create buffer

				eQPstate = (EncQPPtr) malloc(sizeof(EncQP)); // Used by Encode64()
				eQPstate->nCurLineLen = 0;
				eQPstate->cLastChar = '\0';
			}
			break;

			// Otherwise, no encoding
			default:
			{
				preEncBufLen = 0;
			}
			break;
		}
	}

	size_t nReadLen = 0;
	int nPercentComplete = 0;
	emsProgressData progData;

	progData.size = sizeof(emsProgressData);
	progData.value = 0L;
	progData.message = NULL;

	// Do pInPartFilename
	while ((nStatus == FILE1847_OK) && (!feof(fIn)) && (!ferror(fIn)))
	{
		emptybuf_buf(pInBuf);

		switch (InPartCTE)
		{
			case CTE_Base64:
			{
				nReadLen = fread(preEncBuffer, sizeof(char), preEncBufLen, fIn);
				nReadLen = Encode64(preEncBuffer, nReadLen, getbuf_buf(pInBuf), e64state);
			}
			break;

			case CTE_QP:
			{
				nReadLen = fread(preEncBuffer, sizeof(char), preEncBufLen, fIn);
				nReadLen = EncodeQP(preEncBuffer, nReadLen, getbuf_buf(pInBuf), eQPstate);
			}
			break;

			default: /* 7bit, 8bit, binary, none */
			{
				nReadLen = fread(getbuf_buf(pInBuf), sizeof(char), bufsize_buf(pInBuf), fIn);
			}
			break;
		}

		if (nReadLen > 0)
		{
			setlen_buf(pInBuf, nReadLen);

			if (!DoCreatePartsOutput(OutMimePtr,
					((nPart == 1) ? pInBuf : NULL), /* Part 1 */
					((nPart == 2) ? pInBuf : NULL), /* Part 2 */
					pState,
					fOut))
				nStatus = FILE1847_FAIL;
		}

		if ((nStatus == FILE1847_OK) && (progress))
		{
			// Update the progress and check for abort
			nPercentComplete = (int) (((((double)ftell(fIn) + nPreLen))/nTotalInLen) * 100.0);
			progData.value = (long) nPercentComplete;
			if (progress(&progData) ? 1 : 0)
				nStatus = FILE1847_ABORT;
		}
	}

	if (nStatus == FILE1847_OK)
	{
		// Finish part -- if needed
		switch (InPartCTE)
		{
			case CTE_Base64:
			{
				nReadLen = Encode64(NULL, 0, getbuf_buf(pInBuf), e64state);
			}
			break;

			case CTE_QP:
			{
				nReadLen = EncodeQP(NULL, 0, getbuf_buf(pInBuf), eQPstate);
			}
			break;

			default: /* 7bit, 8bit, binary, none */
			{
				nReadLen = 0;
			}
			break;
		}

		if (nReadLen > 0)
		{
			setlen_buf(pInBuf, nReadLen);

			if (!DoCreatePartsOutput(OutMimePtr,
					((nPart == 1) ? pInBuf : NULL), /* Part 1 */
					((nPart == 2) ? pInBuf : NULL), /* Part 2 */
					pState,
					fOut))
				nStatus = FILE1847_FAIL;
		}
	}

	safefree(e64state);
	safefree(eQPstate);
	safefree(preEncBuffer);
	delete_buf(pInBuf);

	return (nStatus);
}
Esempio n. 3
0
void PropertiesWindow::Generate(FormObject* pI, int index)
{
	if (!pI) return;

	_Properties.Clear();
	_Options.Clear();

	_Item  = pI;
	_Index = index;

	String type = pI->Get("Type");
	if (type.IsEmpty()) return;

	Property("Variable", t_("Variable:"), "EditField", Array<String>() << pI->Get("Variable"));

	if (_Headers.GetRowCount() != 1)
	{
		_Headers.Clear();
		_Headers.AddRow(t_("Type:"), type);
	}

	Property("Font.Height", t_("Font height:"), "EditInt", Array<String>()
		<< AsString(pI->GetNumber("Font.Height", 0, 0, 500)));

	if (type == "EditField")
	{
		Property("Style", t_("Style:"), "DropList", Array<String>()
			<< pI->Get("Style") << "Text Field" << "Password");
		Property("TextAlign", t_("Text align:"), "DropList",
			Array<String>() << pI->Get("TextAlign") << "Left" << "Right");
		Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip"));
		Property("NotNull", t_("Not null:"), "Option", Array<String>() << pI->Get("NotNull",
			"0"));
	}

	if (type == "EditInt")
	{
		Property("Min", t_("Min:"), "EditInt", Array<String>() << pI->Get("Min"));
		Property("Max", t_("Max:"), "EditInt", Array<String>() << pI->Get("Max"));
		Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip"));
		Property("NotNull", t_("Not null:"), "Option", Array<String>() << pI->Get("NotNull",
			"0"));
	}

	if (type == "Label")
	{
		Color src = DefaultInk();
		LoadFromString( src, Decode64(pI->Get("Font.Color", Encode64(StoreAsString(src)))) );
		Property("Label", t_("Label:"), "EditField", Array<String>() << pI->Get("Label"));
		Property("Text.Align", t_("Text align:"), "DropList",
			Array<String>() << pI->Get("Text.Align") << "Left" << "Center" << "Right");
		Property("Font.Color", t_("Font color:"), "EditColor", src);
	}

	if (type == "Button")
	{
		Property("Label", t_("Label:"), "EditField", Array<String>() << pI->Get("Label"));
		Property("Action", t_("Action:"), "EditField", Array<String>() << pI->Get("Action"));
		Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip"));
	}

	if (type == "Form")
	{
		Property("Form.PathType", t_("Type of path:"), "DropList",
			Array<String>() << pI->Get("Form.PathType") << "Relative" << "Absolute");
		Property("Form.Path", t_("Path:"), "EditField", Array<String>() << pI->Get("Form.Path"));
		Property("Form.Layout", t_("Layout:"), "EditField", Array<String>() << pI->Get("Form.Layout"));
	}

	if (type == "TabCtrl")
	{
		Property("Tab.Content", t_("Tabs:"), "EditTabs", Array<String>()
			<< pI->Get("Tab.Content", "[Tabs];"));
	}

	if (type == "GridCtrl")
	{
		Property("Grid.Columns", t_("Columns:"), "EditColumns", Array<String>()
			<< pI->Get("Grid.Columns", "[Columns];"));
	}

	Property("Frame", t_("Frame:"), "DropList",
		Array<String>()
			<< pI->Get("Frame")
			<< "Default frame"
			<< "Null frame"
			<< "Top separator frame"
			<< "Left separator frame"
			<< "Right separator frame"
			<< "Bottom separator frame"
			<< "Field frame"
			<< "Inset frame"
			<< "Outset frame"
			<< "Thin inset frame"
			<< "Thin outset frame"
			<< "Black frame"
			<< "Button frame");

	_Options.HideRow(0);
	_Headers.SetCursor(0);
	_Headers.StartEdit();
	_Options.SetCursor(0);
}
Esempio n. 4
0
BUF *HttpRequestEx2(URL_DATA *data, INTERNET_SETTING *setting,
				   UINT timeout_connect, UINT timeout_comm,
				   UINT *error_code, bool check_ssl_trust, char *post_data,
				   WPC_RECV_CALLBACK *recv_callback, void *recv_callback_param, void *sha1_cert_hash,
				   bool *cancel, UINT max_recv_size, char *header_name, char *header_value)
{
	WPC_CONNECT con;
	SOCK *s;
	HTTP_HEADER *h;
	bool use_http_proxy = false;
	char target[MAX_SIZE * 4];
	char *send_str;
	BUF *send_buf;
	BUF *recv_buf;
	UINT http_error_code;
	char len_str[100];
	UINT content_len;
	void *socket_buffer;
	UINT socket_buffer_size = WPC_RECV_BUF_SIZE;
	UINT num_continue = 0;
	INTERNET_SETTING wt_setting;
	// Validate arguments
	if (data == NULL)
	{
		return NULL;
	}
	if (setting == NULL)
	{
		Zero(&wt_setting, sizeof(wt_setting));
		setting = &wt_setting;
	}
	if (error_code == NULL)
	{
		static UINT ret = 0;
		error_code = &ret;
	}
	if (timeout_comm == 0)
	{
		timeout_comm = WPC_TIMEOUT;
	}

	// Connection
	Zero(&con, sizeof(con));
	StrCpy(con.HostName, sizeof(con.HostName), data->HostName);
	con.Port = data->Port;
	con.ProxyType = setting->ProxyType;
	StrCpy(con.ProxyHostName, sizeof(con.ProxyHostName), setting->ProxyHostName);
	con.ProxyPort = setting->ProxyPort;
	StrCpy(con.ProxyUsername, sizeof(con.ProxyUsername), setting->ProxyUsername);
	StrCpy(con.ProxyPassword, sizeof(con.ProxyPassword), setting->ProxyPassword);

	if (setting->ProxyType != PROXY_HTTP || data->Secure)
	{
		use_http_proxy = false;
		StrCpy(target, sizeof(target), data->Target);
	}
	else
	{
		use_http_proxy = true;
		CreateUrl(target, sizeof(target), data);
	}

	if (use_http_proxy == false)
	{
		// If the connection is not via HTTP Proxy, or is a SSL connection even via HTTP Proxy
		s = WpcSockConnectEx(&con, error_code, timeout_connect, cancel);
	}
	else
	{
		// If the connection is not SSL via HTTP Proxy
		s = TcpConnectEx3(con.ProxyHostName, con.ProxyPort, timeout_connect, cancel, NULL, true, NULL, false, false, NULL);
		if (s == NULL)
		{
			*error_code = ERR_PROXY_CONNECT_FAILED;
		}
	}

	if (s == NULL)
	{
		return NULL;
	}

	if (data->Secure)
	{
		// Start the SSL communication
		if (StartSSLEx(s, NULL, NULL, true, 0, NULL) == false)
		{
			// SSL connection failed
			*error_code = ERR_PROTOCOL_ERROR;
			Disconnect(s);
			ReleaseSock(s);
			return NULL;
		}

		if (sha1_cert_hash != NULL)
		{
			UCHAR hash[SHA1_SIZE];
			Zero(hash, sizeof(hash));
			GetXDigest(s->RemoteX, hash, true);

			if (Cmp(hash, sha1_cert_hash, SHA1_SIZE) != 0)
			{
				// Destination certificate hash mismatch
				*error_code = ERR_CERT_NOT_TRUSTED;
				Disconnect(s);
				ReleaseSock(s);
				return NULL;
			}
		}
	}

	// Timeout setting
	SetTimeout(s, timeout_comm);

	// Generate a request
	h = NewHttpHeader(data->Method, target, use_http_proxy ? "HTTP/1.0" : "HTTP/1.1");
	AddHttpValue(h, NewHttpValue("Keep-Alive", HTTP_KEEP_ALIVE));
	AddHttpValue(h, NewHttpValue("Connection", "Keep-Alive"));
	AddHttpValue(h, NewHttpValue("Accept-Language", "ja"));
	AddHttpValue(h, NewHttpValue("User-Agent", WPC_USER_AGENT));
	AddHttpValue(h, NewHttpValue("Pragma", "no-cache"));
	AddHttpValue(h, NewHttpValue("Cache-Control", "no-cache"));
	AddHttpValue(h, NewHttpValue("Host", data->HeaderHostName));

	if (IsEmptyStr(header_name) == false && IsEmptyStr(header_value) == false)
	{
		AddHttpValue(h, NewHttpValue(header_name, header_value));
	}

	if (IsEmptyStr(data->Referer) == false)
	{
		AddHttpValue(h, NewHttpValue("Referer", data->Referer));
	}

	if (StrCmpi(data->Method, WPC_HTTP_POST_NAME) == 0)
	{
		ToStr(len_str, StrLen(post_data));
		AddHttpValue(h, NewHttpValue("Content-Type", "application/x-www-form-urlencoded"));
		AddHttpValue(h, NewHttpValue("Content-Length", len_str));
	}

	if (IsEmptyStr(data->AdditionalHeaderName) == false && IsEmptyStr(data->AdditionalHeaderValue) == false)
	{
		AddHttpValue(h, NewHttpValue(data->AdditionalHeaderName, data->AdditionalHeaderValue));
	}

	if (use_http_proxy)
	{
		AddHttpValue(h, NewHttpValue("Proxy-Connection", "Keep-Alive"));

		if (IsEmptyStr(setting->ProxyUsername) == false || IsEmptyStr(setting->ProxyPassword) == false)
		{
			char auth_tmp_str[MAX_SIZE], auth_b64_str[MAX_SIZE * 2];
			char basic_str[MAX_SIZE * 2];

			// Generate the authentication string
			Format(auth_tmp_str, sizeof(auth_tmp_str), "%s:%s",
				setting->ProxyUsername, setting->ProxyPassword);

			// Base64 encode
			Zero(auth_b64_str, sizeof(auth_b64_str));
			Encode64(auth_b64_str, auth_tmp_str);
			Format(basic_str, sizeof(basic_str), "Basic %s", auth_b64_str);

			AddHttpValue(h, NewHttpValue("Proxy-Authorization", basic_str));
		}
	}

	send_str = HttpHeaderToStr(h);
	FreeHttpHeader(h);

	send_buf = NewBuf();
	WriteBuf(send_buf, send_str, StrLen(send_str));
	Free(send_str);

	// Append to the sending data in the case of POST
	if (StrCmpi(data->Method, WPC_HTTP_POST_NAME) == 0)
	{
		WriteBuf(send_buf, post_data, StrLen(post_data));
	}

	// Send
	if (SendAll(s, send_buf->Buf, send_buf->Size, s->SecureMode) == false)
	{
		Disconnect(s);
		ReleaseSock(s);
		FreeBuf(send_buf);

		*error_code = ERR_DISCONNECTED;

		return NULL;
	}

	FreeBuf(send_buf);

CONT:
	// Receive
	h = RecvHttpHeader(s);
	if (h == NULL)
	{
		Disconnect(s);
		ReleaseSock(s);

		*error_code = ERR_DISCONNECTED;

		return NULL;
	}

	http_error_code = 0;
	if (StrLen(h->Method) == 8)
	{
		if (Cmp(h->Method, "HTTP/1.", 7) == 0)
		{
			http_error_code = ToInt(h->Target);
		}
	}

	*error_code = ERR_NO_ERROR;

	switch (http_error_code)
	{
	case 401:
	case 407:
		// Proxy authentication error
		*error_code = ERR_PROXY_AUTH_FAILED;
		break;

	case 404:
		// 404 File Not Found
		*error_code = ERR_OBJECT_NOT_FOUND;
		break;

	case 100:
		// Continue
		num_continue++;
		if (num_continue >= 10)
		{
			goto DEF;
		}
		FreeHttpHeader(h);
		goto CONT;

	case 200:
		// Success
		break;

	default:
		// Protocol error
DEF:
		*error_code = ERR_PROTOCOL_ERROR;
		break;
	}

	if (*error_code != ERR_NO_ERROR)
	{
		// An error has occured
		Disconnect(s);
		ReleaseSock(s);
		FreeHttpHeader(h);
		return NULL;
	}

	// Get the length of the content
	content_len = GetContentLength(h);
	if (max_recv_size != 0)
	{
		content_len = MIN(content_len, max_recv_size);
	}

	FreeHttpHeader(h);

	socket_buffer = Malloc(socket_buffer_size);

	// Receive the content
	recv_buf = NewBuf();

	while (true)
	{
		UINT recvsize = MIN(socket_buffer_size, content_len - recv_buf->Size);
		UINT size;

		if (recv_callback != NULL)
		{
			if (recv_callback(recv_callback_param,
				content_len, recv_buf->Size, recv_buf) == false)
			{
				// Cancel the reception
				*error_code = ERR_USER_CANCEL;
				goto RECV_CANCEL;
			}
		}

		if (recvsize == 0)
		{
			break;
		}

		size = Recv(s, socket_buffer, recvsize, s->SecureMode);
		if (size == 0)
		{
			// Disconnected
			*error_code = ERR_DISCONNECTED;

RECV_CANCEL:
			FreeBuf(recv_buf);
			Free(socket_buffer);
			Disconnect(s);
			ReleaseSock(s);

			return NULL;
		}

		WriteBuf(recv_buf, socket_buffer, size);
	}

	SeekBuf(recv_buf, 0, 0);
	Free(socket_buffer);

	Disconnect(s);
	ReleaseSock(s);

	// Transmission
	return recv_buf;
}