예제 #1
0
파일: client.c 프로젝트: Wonfee/obexftp
/**
	Send an OBEX PUT, optionally with (some) SETPATHs for a local file.

	\param cli an obexftp_client_t created by obexftp_open().
	\param filename local file to send
	\param remotename remote name to write

	\return the result of the OBEX PUT (and SETPATH) request(s).

	\note Puts to filename's basename if remotename is NULL or ends with a slash.
 */
int obexftp_put_file(obexftp_client_t *cli, const char *filename, const char *remotename)
{
	obex_object_t *object;
	int ret;

	return_val_if_fail(cli != NULL, -EINVAL);
	return_val_if_fail(filename != NULL, -EINVAL);

	if (cli->out_data) {
		DEBUG(1, "%s: Warning: buffer still active?\n", __func__);
	}
	cli->infocb(OBEXFTP_EV_SENDING, filename, 0, cli->infocb_data);

	// TODO: if remotename ends with a slash: add basename
	if (!remotename) {
		remotename = strrchr(filename, '/');
		if (remotename)
			remotename++;
		else
			remotename = filename;
	}

	if (OBEXFTP_USE_SPLIT_SETPATH(cli->quirks) && remotename && strchr(remotename, '/')) {
		char *basepath, *basename;
		split_file_path(remotename, &basepath, &basename);
		ret = obexftp_setpath(cli, basepath, 0);
		if(ret < 0) {
			cli->infocb(OBEXFTP_EV_ERR, basepath, 0, cli->infocb_data);
			return ret;
		}

		DEBUG(2, "%s() Sending %s -> %s\n", __func__, filename, basename);
		object = build_object_from_file (cli->obexhandle, cli->connection_id, filename, basename);
		free(basepath);
		free(basename);
	} else {
		DEBUG(2, "%s() Sending %s -> %s\n", __func__, filename, remotename);
		object = build_object_from_file (cli->obexhandle, cli->connection_id, filename, remotename);
	}
	
	cli->fd = open(filename, O_RDONLY | O_BINARY, 0);
	if(cli->fd < 0)
		ret = -1;
	else {
		cli->out_data = NULL; /* dont free, isnt ours */
		cache_purge(&cli->cache, NULL);
		ret = cli_sync_request(cli, object);
	}
	
	/* close(cli->fd); */

	if(ret < 0)
		cli->infocb(OBEXFTP_EV_ERR, filename, 0, cli->infocb_data);
	else
		cli->infocb(OBEXFTP_EV_OK, filename, 0, cli->infocb_data);

	return ret;
}
예제 #2
0
//
// Do an OBEX PUT.
//
static int ircp_put_file(ircp_client_t *cli, char *localname, char *remotename)
{
	obex_object_t *object;
	int ret;

	cli->infocb(IRCP_EV_SENDING, localname);

	DEBUG(4, "Sending %s -> %s\n", localname, remotename);
	ircp_return_val_if_fail(cli != NULL, -1);

	object = build_object_from_file(cli->obexhandle, localname, remotename);
	
	cli->fd = open(localname, O_RDONLY, 0);
	if(cli->fd < 0)
		ret = -1;
	else
		ret = cli_sync_request(cli, object);
	
	close(cli->fd);
		
	if(ret < 0)
		cli->infocb(IRCP_EV_ERR, localname);
	else
		cli->infocb(IRCP_EV_OK, localname);

	return ret;
}
예제 #3
0
파일: build.c 프로젝트: tuxdna/anjuta
BuildContext*
build_compile_file (BasicAutotoolsPlugin *plugin, GFile *file)
{
	BuildContext *context = NULL;
	BuildProgram *prog;
	GFile *object;
	gchar *target_name;

	g_return_val_if_fail (file != NULL, FALSE);

	object = build_object_from_file (plugin, file);
	if (object != NULL)
	{
		GFile *build_dir;
		BuildConfiguration *config;
		GList *vars;

		config = build_configuration_list_get_selected (plugin->configurations);
		vars = build_configuration_get_variables (config);

		/* Find target directory */
		build_dir = build_file_from_file (plugin, object, &target_name);

		prog = build_program_new_with_command (build_dir, "%s %s",
	    	                                   CHOOSE_COMMAND(plugin, COMPILE),
	        	                               (target_name == NULL) ? "" : target_name);
		g_free (target_name);
		g_object_unref (build_dir);

		build_program_add_env_list (prog, vars);

		context = build_save_and_execute_command (plugin, prog, TRUE, NULL);
		g_object_unref (object);
	}
	else
	{
		/* FIXME: Prompt the user to create a Makefile with a wizard
		   (if there is no Makefile in the directory) or to add a target
		   rule in the above hash table, eg. editing the preferences, if
		   there is target extension defined for that file extension.
		*/
		GtkWindow *window;
		gchar *filename;

		filename = g_file_get_path (file);
		window = GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell);
		anjuta_util_dialog_error (window, _("Cannot compile \"%s\": No compile rule defined for this file type."), filename);
		g_free (filename);
	}

	return context;
}
예제 #4
0
파일: obex_tcp.c 프로젝트: namili/openobex
static int get_peer_addr(char *name, struct sockaddr_storage *peer) 
{
	struct addrinfo hint = {
		.ai_family = AF_UNSPEC,
		.ai_socktype = SOCK_STREAM,
		.ai_protocol = 0,
		.ai_flags = AI_ADDRCONFIG

	};
	struct addrinfo *info;

	int err = getaddrinfo(name, NULL, &hint, &info);
	if (err)
		return err;
	memcpy(peer, info->ai_addr, info->ai_addrlen);
	freeaddrinfo(info);
	return 0;
}

/*
 * Function main (argc, )
 *
 *    Starts all the fun!
 *
 */
int main(int argc, char *argv[])
{
	struct sockaddr_storage peer;

	obex_object_t *object;
	int ret;

	printf("Send and receive files over TCP OBEX\n");
	if ( ((argc < 3) || (argc > 3)) && (argc != 1) )	{
		printf ("Usage: %s [name] [peer]\n", argv[0]); 
		return -1;
	}

	handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0);

	if (argc == 1)	{
		printf("Waiting for files\n");
		ret = TcpOBEX_ServerRegister(handle, NULL, 0);
		if(ret < 0) {
                        printf("Cannot listen to socket\n");
			exit(ret);
		}

		while (!finished) {
			ret = OBEX_HandleInput(handle, 10);
			if (ret == 0) {
				printf("Timeout waiting for connection\n");
				break;
			} else if (ret < 0) {
			        printf("Error waiting for connection\n");
				break;
			}
		}
	}
	else {
		/* We are a client */

		ret = get_peer_addr(argv[2], &peer);
		if (ret) {
			perror("Bad name");
			exit(1);
		}
		ret = TcpOBEX_TransportConnect(handle, (struct sockaddr *) &peer,
					  sizeof(peer));

		if (ret < 0) {
			printf("Sorry, unable to connect!\n");
			exit(1);
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
		ret = do_sync_request(handle, object, 0);

		if( (object = build_object_from_file(handle, argv[1], 0)) )	{
			ret = do_sync_request(handle, object, 0);
		}
		else	{
			perror("PUT failed");
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
		ret = do_sync_request(handle, object, 0);

		printf("PUT successful\n");
	}
	return 0;
}
예제 #5
0
/*
 * Function main (argc, )
 *
 *    Starts all the fun!
 *
 */
int main(int argc, char *argv[])
{
	struct sockaddr_in peer;

	obex_object_t *object;
	int ret;

	printf("Send and receive files over TCP OBEX\n");
	if ( ((argc < 3) || (argc > 3)) && (argc != 1) )	{
		printf ("Usage: %s [name] [peer]\n", argv[0]); 
		return -1;
	}

	handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0);

	if (argc == 1)	{
		printf("Waiting for files\n");
		ret = InOBEX_ServerRegister(handle);
		if(ret < 0) {
                        printf("Cannot listen to socket\n");
			exit(ret);
		}

		while (!finished) {
			ret = OBEX_HandleInput(handle, 10);
			if (ret == 0) {
				printf("Timeout waiting for connection\n");
				break;
			} else if (ret < 0) {
			        printf("Error waiting for connection\n");
				break;
			}
		}
	}
	else {
		/* We are a client */

		get_peer_addr(argv[2], &peer);
		ret = OBEX_TransportConnect(handle, (struct sockaddr *) &peer,
					  sizeof(struct sockaddr_in));

		if (ret < 0) {
			printf("Sorry, unable to connect!\n");
			exit(ret);
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
		ret = do_sync_request(handle, object, 0);

		if( (object = build_object_from_file(handle, argv[1], 0)) )	{
			ret = do_sync_request(handle, object, 0);
		}
		else	{
			perror("PUT failed");
		}

		object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
		ret = do_sync_request(handle, object, 0);

		printf("PUT successful\n");
	}
	return 0;
}