1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/**
\file apps/irobex_palm3.c
Demonstrates use of PUT command.
OpenOBEX test applications and sample code.
Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved.
OpenOBEX is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with OpenOBEX. If not, see <http://www.gnu.org/>.
*/
/*
The Palm 3 always sends a HEADER_CREATORID (0xcf).
Start without arguments to receive a file.
Start with filename as argument to send a file.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <openobex/obex.h>
#include "obex_put_common.h"
#include "obex_io.h"
#include <stdio.h>
#include <stdlib.h>
#ifndef _WIN32
#include <unistd.h>
#include <string.h>
#endif
#define TRUE 1
#define FALSE 0
obex_t *handle = NULL;
volatile int finished = FALSE;
extern int last_rsp;
/*
* Function usage (void)
*/
static int usage(char *argv[]) {
printf ("Usage: %s [-h id] [name]\n", argv[0]);
printf (" where id is the header_creator_id (default: memo)\n");
return -1;
}
/*
* Function main (argc, )
*
* Starts all the fun!
*
*/
int main(int argc, char *argv[])
{
obex_object_t *object;
int ret, exitval = EXIT_SUCCESS;
uint32_t creator_id = 0;
printf("Send and receive files to Palm3\n");
if ((argc < 1) || (argc > 4)) {
return usage(argv);
}
handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0);
if (argc == 1) {
/* We are server*/
printf("Waiting for files\n");
IrOBEX_ServerRegister(handle, "OBEX");
while (!finished)
OBEX_HandleInput(handle, 1);
}
else {
/* We are a client */
/* Check for parameters */
if(argc > 2) {
if(strcmp("-h", argv[1]) || strlen(argv[2]) != 4)
return usage(argv);
creator_id = argv[2][0] << 24 | argv[2][1] << 16 | argv[2][2] << 8 | argv[2][3];
printf("debug: %s %d;", argv[2], creator_id);
}
/* Try to connect to peer */
ret = IrOBEX_TransportConnect(handle, "OBEX");
if (ret < 0) {
printf("Sorry, unable to connect!\n");
return EXIT_FAILURE;
}
object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT);
ret = do_sync_request(handle, object, FALSE);
if ((last_rsp != OBEX_RSP_SUCCESS) || (ret < 0)) {
printf("Sorry, unable to connect!\n");
return EXIT_FAILURE;
}
if ((object = build_object_from_file(handle, argv[(creator_id ? 3 : 1)], creator_id))) {
ret = do_sync_request(handle, object, FALSE);
if ((last_rsp != OBEX_RSP_SUCCESS) || (ret < 0))
exitval = EXIT_FAILURE;
} else
exitval = EXIT_FAILURE;
object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT);
ret = do_sync_request(handle, object, FALSE);
if ((last_rsp != OBEX_RSP_SUCCESS) || (ret < 0))
exitval = EXIT_FAILURE;
if (exitval == EXIT_SUCCESS)
printf("PUT successful\n");
else
printf("PUT failed\n");
}
// sleep(1);
return exitval;
}
|