/* * Off-the-Record Messaging library * Copyright (C) 2004-2009 Ian Goldberg, Chris Alexander, Willy Lew, * Nikita Borisov * * * This library is free software; you can redistribute it and/or * modify it under the terms of version 2.1 of the GNU Lesser General * Public License as published by the Free Software Foundation. * * This library 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __TLV_H__ #define __TLV_H__ typedef struct s_OtrlTLV { unsigned short type; unsigned short len; unsigned char *data; struct s_OtrlTLV *next; } OtrlTLV; /* TLV types */ /* This is just padding for the encrypted message, and should be ignored. */ #define OTRL_TLV_PADDING 0x0000 /* The sender has thrown away his OTR session keys with you */ #define OTRL_TLV_DISCONNECTED 0x0001 /* The message contains a step in the Socialist Millionaires' Protocol. */ #define OTRL_TLV_SMP1 0x0002 #define OTRL_TLV_SMP2 0x0003 #define OTRL_TLV_SMP3 0x0004 #define OTRL_TLV_SMP4 0x0005 #define OTRL_TLV_SMP_ABORT 0x0006 /* Like OTRL_TLV_SMP1, but there's a question for the buddy at the * beginning */ #define OTRL_TLV_SMP1Q 0x0007 /* Tell the application the current "extra" symmetric key */ /* XXX: Document this in the protocol spec: * The body of the TLV will begin with a 4-byte indication of what this * symmetric key will be used for (file transfer, voice encryption, * etc.). After that, the contents are use-specific (which file, etc.). * There are no currently defined uses. */ #define OTRL_TLV_SYMKEY 0x0008 /* Use this TLV for in-band file transfer. TODO: Document this in the protocol spec. */ #define OTRL_TLV_INB_FT_RST 0x0010 #define OTRL_TLV_INB_FT_ERR 0x0011 #define OTRL_TLV_INB_FT_ACK 0x0012 #define OTRL_TLV_INB_FT_INIT 0x0013 #define OTRL_TLV_INB_FT_DATA 0x0014 #define OTRL_TLV_INB_FT_FULL 0x0015 /* Make a single TLV, copying the supplied data */ OtrlTLV *otrl_tlv_new(unsigned short type, unsigned short len, const unsigned char *data); /* Construct a chain of TLVs from the given data */ OtrlTLV *otrl_tlv_parse(const unsigned char *serialized, size_t seriallen); /* Deallocate a chain of TLVs */ void otrl_tlv_free(OtrlTLV *tlv); /* Find the serialized length of a chain of TLVs */ size_t otrl_tlv_seriallen(const OtrlTLV *tlv); /* Serialize a chain of TLVs. The supplied buffer must already be large * enough. */ void otrl_tlv_serialize(unsigned char *buf, const OtrlTLV *tlv); /* Return the first TLV with the given type in the chain, or NULL if one * isn't found. (The tlvs argument isn't const because the return type * needs to be non-const.) */ OtrlTLV * otrl_tlv_find(OtrlTLV *tlvs, unsigned short type); // construct INIT TLV from file // return NULL on errors OtrlTLV * otrl_tlv_ft_init(const char * filename, unsigned char id); // return TLV made from chunk of data OtrlTLV * otrl_tlv_ft_data(const char * data, unsigned char id, size_t length, size_t offset); // construct TLV of given type (RST/ACK) with given id OtrlTLV * otrl_tlv_ft_rack(unsigned char id, unsigned short type); //return filename to be transmitted or NULL on errors char * otrl_tlv_ft_get_name(const OtrlTLV *tlv); // return filesize to be transmitted or size of chunk in DATA TLV // return -1 on errors size_t otrl_tlv_ft_get_size(const OtrlTLV *tlv); // get file transfer id from appropriate TLV unsigned char otrl_tlv_ft_get_id(const OtrlTLV *tlv); // get actual data char * otrl_tlv_ft_get_data(const OtrlTLV *tlv); // dump TLV content void otrl_tlv_print(const OtrlTLV *tlv); #endif