/* clipboard serving - what to do when we own the clipboard and somebody
 * else wants the contents
 */
void receivedDataRequest(wimp_message * wmessage) {
	if ( !sqHasClipboard ) return;

	/* somebody requested data & I have the clipboard
	* If an application receiving this message owns the clipboard,
	* it should choose the earliest filetype in the list that it
	* can provide, and if none are possible it should provide the
	* data its original (native) format. Note that the list can be
	* null, to indicate that the native data should be sent.
	*/
	/* reply using the normal Message_DataSave protocol.
	 * Bytes 20 through 35 of the DataSave block should be copied directly
	 * from the corresponding bytes of the Message_DataRequest block,
	 * whilst the estimated size field, filetype and filename must be
	 * filled in.
	 */

	/* We modify the received block and return to sender */
	wmessage->size = 52;
	wmessage->action = message_DATA_SAVE;
	wmessage->your_ref = wmessage->my_ref;
	wmessage->data.data_xfer.est_size = strlen(clipboardBuffer);
	wmessage->data.data_xfer.file_type = (bits) 0xfff;
	strcpy(&(wmessage->data.data_xfer.file_name[0]), "SqClip");
	xwimp_send_message(wimp_USER_MESSAGE, wmessage, wmessage->sender);
}
Esempio n. 2
0
void ro_url_broadcast(const char *url)
{
	inetsuite_full_message_open_url_direct message;
	os_error *error;
	int len = strlen(url) + 1;

	/* If URL is too long, then forget ANT and try URI, instead */
	if (236 < len) {
		ro_uri_launch(url);
		return;
	}

	message.size = ((20+len+3) & ~3);
	message.your_ref = 0;
	message.action = message_INET_SUITE_OPEN_URL;
	strncpy(message.url, url, 235);
	message.url[235] = 0;
	error = xwimp_send_message(wimp_USER_MESSAGE_RECORDED,
			(wimp_message *) &message, 0);
	if (error) {
		LOG(("xwimp_send_message: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
	}
}
void receivedClipboardDataLoad(wimp_message * wmessage) {
/* we got a dataload message, so grab the <Wimp$Scrap> file, then delete it
 * and return a dataloadack to the sender
 */
bits load_addr, exec_addr, file_type;
fileswitch_attr attr;
fileswitch_object_type obj_type;
int length;
	/* find the file size */
	xosfile_read_stamped_no_path(&(wmessage->data.data_xfer.file_name[0]),
		&obj_type, &load_addr, &exec_addr, &length, &attr, &file_type);
	/* if the obj_type is not-found, clear the buffer and return */
	if(obj_type == fileswitch_NOT_FOUND) {
		allocClipboard(1);
		return;
	}
	/* make sure we have enough buffer space for it
	 * fail if not */
	if(!allocClipboard(length+1))
		return;
	/* now load the file */
	xosfile_load_stamped_no_path(&(wmessage->data.data_xfer.file_name[0]),		(byte*)clipboardBuffer, &obj_type,
		&load_addr, &exec_addr, &length, &attr);
	/* delete the file */
	xosfscontrol_wipe(&(wmessage->data.data_xfer.file_name[0]), osfscontrol_WIPE_FORCE, 0,0,0,0);
	/* We modify the received block and return it to sender */
	wmessage->action = message_DATA_LOAD_ACK;
	wmessage->your_ref = wmessage->my_ref;
	xwimp_send_message(wimp_USER_MESSAGE, wmessage, wmessage->sender);
}
void receivedDataSaveAck(wimp_message * wmessage) {
/* we've been asked to save the clipboard contents to the wimpScrap */
	osfile_save_stamped(&(wmessage->data.data_xfer.file_name[0]),
		(bits)0xfff, (byte const *)clipboardBuffer,
		(byte const *)(clipboardBuffer +
			strlen(clipboardBuffer)));
	/* modify the block to be a data load message and return to sender */
	wmessage->action = message_DATA_LOAD;
	wmessage->your_ref = wmessage->my_ref;
	wmessage->data.data_xfer.est_size = strlen(clipboardBuffer);
	xwimp_send_message(wimp_USER_MESSAGE, wmessage, wmessage->sender);
}
Esempio n. 5
0
void ro_uri_message_received(wimp_message *msg)
{
	uri_full_message_process *uri_message = (uri_full_message_process *)msg;
	uri_h uri_handle;
	char* uri_requested;
	int uri_length;
	nsurl *url;
	nserror error;

	uri_handle = uri_message->handle;

	if (nsurl_create(uri_message->uri, &url) != NSERROR_OK) {
		return;
	}

	if (!fetch_can_fetch(url)) {
		nsurl_unref(url);
		return;
	}

	nsurl_unref(url);

	uri_message->your_ref = uri_message->my_ref;
	uri_message->action = message_URI_PROCESS_ACK;

	xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)uri_message,
		uri_message->sender);

	xuri_request_uri(0, 0, 0, uri_handle, &uri_length);
	uri_requested = calloc((unsigned int)uri_length, sizeof(char));
	if (uri_requested == NULL)
		return;

	xuri_request_uri(0, uri_requested, uri_length, uri_handle, NULL);

	error = nsurl_create(uri_requested, &url);
	free(uri_requested);
	if (error == NSERROR_OK) {
		error = browser_window_create(BROWSER_WINDOW_VERIFIABLE |
					      BROWSER_WINDOW_HISTORY,
					      url,
					      NULL,
					      NULL,
					      NULL);
		nsurl_unref(url);
	}
	if (error != NSERROR_OK) {
		warn_user(messages_get_errorcode(error), 0);
	}
}
void ClaimEntity( int flags) {
	wimp_message wmessage;
/* broadcast the Message_ClaimEntity using the flags value to decide whether
 * it is a claim of the caret or the clipboard (or both?)
 * When claiming the input focus or clipboard, a task should check to see if
 * it already owns that entity, and if so, there is no need to issue the
 * broadcast.
 * It should then take care of updating the caret / selection / clipboard
 * to the new value (updating the display in the case of the selection).
 */

	wmessage.size = 24;
	wmessage.sender = (wimp_t)NULL;
	wmessage.my_ref = 0;
	wmessage.your_ref = 0;
	wmessage.action = message_CLAIM_ENTITY;
	wmessage.data.claim_entity.flags = (wimp_claim_flags)flags;
	xwimp_send_message(wimp_USER_MESSAGE, &wmessage, wimp_BROADCAST);

}
void sendDataRequest(wimp_message* wmessage) {
/* We want to fetch the clipboard contents from some other application
 * Broadcast the message_DATA_REQUEST message
 */
	wmessage->size = 52;
	wmessage->sender = (wimp_t)NULL;
	wmessage->my_ref = 0;
	wmessage->your_ref = 0;
	wmessage->action = message_DATA_REQUEST;
	wmessage->data.data_request.w = 0 /* sqWindowHandle */;
	wmessage->data.data_request.i = wimp_ICON_WINDOW;
	wmessage->data.data_request.pos.x = 0;
	wmessage->data.data_request.pos.y = 0;
	wmessage->data.data_request.flags = wimp_DATA_REQUEST_CLIPBOARD;
	wmessage->data.data_request.file_types[0] = 0xFFF; //TEXT
	wmessage->data.data_request.file_types[1] = 0xFFD; // DATA
	wmessage->data.data_request.file_types[2] = -1;
	xwimp_send_message(wimp_USER_MESSAGE, wmessage, wimp_BROADCAST);
	clipboardMessageID = wmessage->my_ref;
}
int receivedClipboardDataSave(wimp_message * wmessage) {
/* When the application that initiated the Paste receives the
 * Message_DataSave, it should check the filetype to ensure that it
 * knows how to deal with it - it may be the clipboard owner's native
 * format. If it cannot, it may back out of the transaction by ignoring
 * the message. Otherwise, it should continue with the DataSave
 * protocol as detailed in the Programmer's Reference Manual.
 */
	if(wmessage->data.data_xfer.file_type != (bits)0xfff) {
		/* if not text type, empty clipboard buffer & return */
		memset(clipboardBuffer,0, (size_t)clipboardByteSize);
		return false;
	}
	/* We modify the received block and return to sender */
	wmessage->size = 60;
	wmessage->action = message_DATA_SAVE_ACK;
	wmessage->your_ref = wmessage->my_ref;
	wmessage->data.data_xfer.est_size = -1;
	wmessage->data.data_xfer.file_type = (bits)0xfff;
	strcpy(&(wmessage->data.data_xfer.file_name[0]), "<Wimp$Scrap>");
	xwimp_send_message(wimp_USER_MESSAGE, wmessage, wmessage->sender);
	return true;
}
Esempio n. 9
0
/**
 * Sends a message and registers a return route for a bounce.
 *
 * \param event		the message event type
 * \param message	the message to register a route back for
 * \param task		the task to send a message to, or 0 for broadcast
 * \param callback	the code to call on a bounce
 * \return true on success, false otherwise
 */
bool ro_message_send_message(wimp_event_no event, wimp_message *message,
		wimp_t task, void (*callback)(wimp_message *message))
{
	os_error *error;

	assert(message);

	/* send a message */
	error = xwimp_send_message(event, message, task);
	if (error) {
		LOG("xwimp_send_message: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("WimpError", error->errmess);
		return false;
	}

	/* register the default bounce handler */
	if (callback) {
		assert(event == wimp_USER_MESSAGE_RECORDED);
		return ro_message_register_handler(message, message->action,
				callback);
	}
	return true;
}
Esempio n. 10
0
void ro_url_message_received(wimp_message *message)
{
	char *url;
	int i;
	inetsuite_message_open_url *url_message =
			(inetsuite_message_open_url*) &message->data;
	os_error *error;
	nsurl *nsurl;
	nserror errorns;

	/* If the url_message->indirect.tag is non-zero,
	 * then the message data is contained within the message block.
	 */
	if (url_message->indirect.tag != 0) {
		url = strndup(url_message->url, 236);
		if (!url) {
			warn_user("NoMemory", 0);
			return;
		}
		/* terminate at first control character */
		for (i = 0; !iscntrl(url[i]); i++)
			;
		url[i] = 0;

	} else {
		if (!url_message->indirect.url.offset) {
			LOG(("no URL in message"));
			return;
		}
		if (28 < message->size &&
				url_message->indirect.body_file.offset) {
			LOG(("POST for URL message not implemented"));
			return;
		}
		if (url_message->indirect.url.offset < 28 ||
				236 <= url_message->indirect.url.offset) {
			LOG(("external pointers in URL message unimplemented"));
			/* these messages have never been seen in the wild,
			 * and there is the problem of invalid addresses which
			 * would cause an abort */
			return;
		}

		url = strndup((char *) url_message +
				url_message->indirect.url.offset,
				236 - url_message->indirect.url.offset);
		if (!url) {
			warn_user("NoMemory", 0);
			return;
		}
		for (i = 0; !iscntrl(url[i]); i++)
			;
		url[i] = 0;
	}

	if (nsurl_create(url, &nsurl) != NSERROR_OK) {
		free(url);
		return;
	}

	if (!fetch_can_fetch(nsurl)) {
		nsurl_unref(nsurl);
		free(url);
		return;
	}

	free(url);

	/* send ack */
	message->your_ref = message->my_ref;
	error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, message,
			message->sender);
	if (error) {
		LOG(("xwimp_send_message: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
	}

	/* create new browser window */
	errorns = browser_window_create(BW_CREATE_HISTORY,
				      nsurl,
				      NULL,
				      NULL,
				      NULL);


	nsurl_unref(nsurl);
	if (errorns != NSERROR_OK) {
		warn_user(messages_get_errorcode(errorns), 0);
	}
}