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
|
/**
\file obex_header.c
OBEX header releated functions.
OpenOBEX library - Free implementation of the Object Exchange protocol.
Copyright (c) 1999-2000 Pontus Fuchs, All Rights Reserved.
Copyright (c) 1999 Dag Brattli, All Rights Reserved.
OpenOBEX is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with OpenOBEX. If not, see <http://www.gnu.org/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "obex_main.h"
#include "obex_header.h"
#include <string.h>
#include <stdio.h>
/*
* Function insert_uint_header (buf, identifier, value)
*
* Insert a four byte unsigned integer in network byte order
* identifier if the header ID which is supposed to consist of
* both the header enconding and type
*/
int insert_uint_header(buf_t *msg, uint8_t identifier, uint32_t value)
{
struct obex_uint_hdr *hdr;
DEBUG(4, "\n");
obex_return_val_if_fail(msg != NULL, -1);
hdr = (struct obex_uint_hdr *) buf_reserve_end(msg, sizeof(struct obex_uint_hdr));
hdr->hi = identifier;
hdr->hv = htonl(value);
return sizeof(struct obex_uint_hdr);
}
/*
* Function insert_ubyte_header (buf, identifier, value)
*
* Insert a byte unsigned header.
*/
int insert_ubyte_header(buf_t *msg, uint8_t identifier, uint8_t value)
{
struct obex_ubyte_hdr *hdr;
DEBUG(4, "\n");
obex_return_val_if_fail(msg != NULL, -1);
hdr = (struct obex_ubyte_hdr *) buf_reserve_end(msg, sizeof(struct obex_ubyte_hdr));
hdr->hi = identifier;
hdr->hv = value;
return sizeof(struct obex_ubyte_hdr);
}
/*
* Function insert_unicode_header (buf, opcode, text)
*
* Insert a char string into the buffer
*
*/
int insert_unicode_header(buf_t *msg, uint8_t opcode, const uint8_t *text,
int size)
{
struct obex_unicode_hdr *hdr;
DEBUG(4, "\n");
obex_return_val_if_fail(msg != NULL, -1);
obex_return_val_if_fail(text != NULL || size == 0, -1);
hdr = (struct obex_unicode_hdr *) buf_reserve_end(msg, size + sizeof(struct obex_unicode_hdr));
hdr->hi = opcode;
hdr->hl = htons((uint16_t)(size + sizeof(struct obex_unicode_hdr)));
memcpy(hdr->hv, text, size);
return size + sizeof(struct obex_unicode_hdr);
}
/*
* Function insert_byte_stream_header (buf, opcode, stream, size)
*
* Insert a byte stream into the buffer
*
*/
int insert_byte_stream_header(buf_t *msg, uint8_t opcode,
const uint8_t *stream, int size)
{
struct obex_byte_stream_hdr *hdr;
DEBUG(4, "\n");
obex_return_val_if_fail(msg != NULL, -1);
obex_return_val_if_fail(stream != NULL || size == 0, -1);
hdr = (struct obex_byte_stream_hdr *) buf_reserve_end(msg, size + sizeof(struct obex_byte_stream_hdr));
if (hdr == 0) {
DEBUG(4, "put failed!\n");
return 0;
}
hdr->hi = opcode;
hdr->hl = htons(size + sizeof(struct obex_byte_stream_hdr));
memcpy(hdr->hv, stream, size);
return size + sizeof(struct obex_byte_stream_hdr);
}
|