mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Refactor log.h constants.h serval.h
Move DEBUG_ and LOG_LEVEL_ macro constants from constants.h into log.h. Move dumpResponses() out of log.c, so that log.h is almost ready for re-use (still depends on conf.h). Remove unused and now obsolete catv() function -- replaced with toprint() and alloca_toprint(). Add copyright/licence comments, fix up some copyright attributions. Add #ifndef..#define..#endif __SERVALD_FOO_H to header files: log.h serval.h constants.h
This commit is contained in:
parent
d63318cd2f
commit
f002f5b9fd
60
constants.h
60
constants.h
@ -1,5 +1,23 @@
|
||||
#ifndef _CONSTANTS_H
|
||||
#define _CONSTANTS_H
|
||||
/*
|
||||
Copyright (C) 2012 Serval Project Inc.
|
||||
|
||||
This program 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 this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SERVALD_CONSTANTS_H
|
||||
#define __SERVALD_CONSTANTS_H
|
||||
|
||||
/* Packet format:
|
||||
|
||||
@ -91,42 +109,6 @@
|
||||
#define ACTION_PAD 0xfe
|
||||
#define ACTION_EOT 0xff
|
||||
|
||||
#define DEBUG_ALL (~0)
|
||||
#define DEBUG_PACKETRX (1 << 0)
|
||||
#define DEBUG_OVERLAYINTERFACES (1 << 1)
|
||||
#define DEBUG_VERBOSE (1 << 2)
|
||||
#define DEBUG_VERBOSE_IO (1 << 3)
|
||||
#define DEBUG_PEERS (1 << 4)
|
||||
#define DEBUG_DNARESPONSES (1 << 5)
|
||||
#define DEBUG_DNAHELPER (1 << 6)
|
||||
#define DEBUG_SIMULATION (1 << 7)
|
||||
#define DEBUG_RHIZOME_RX (1 << 8)
|
||||
#define DEBUG_PACKETFORMATS (1 << 9)
|
||||
#define DEBUG_GATEWAY (1 << 10)
|
||||
#define DEBUG_KEYRING (1 << 11)
|
||||
#define DEBUG_IO (1 << 12)
|
||||
#define DEBUG_OVERLAYFRAMES (1 << 13)
|
||||
#define DEBUG_OVERLAYABBREVIATIONS (1 << 14)
|
||||
#define DEBUG_OVERLAYROUTING (1 << 15)
|
||||
#define DEBUG_SECURITY (1 << 16)
|
||||
#define DEBUG_RHIZOME (1 << 17)
|
||||
#define DEBUG_OVERLAYROUTEMONITOR (1 << 18)
|
||||
#define DEBUG_QUEUES (1 << 19)
|
||||
#define DEBUG_BROADCASTS (1 << 20)
|
||||
#define DEBUG_RHIZOME_TX (1 << 21)
|
||||
#define DEBUG_PACKETTX (1 << 22)
|
||||
#define DEBUG_PACKETCONSTRUCTION (1 << 23)
|
||||
#define DEBUG_MANIFESTS (1 << 24)
|
||||
#define DEBUG_MDPREQUESTS (1 << 25)
|
||||
#define DEBUG_TIMING (1 << 26)
|
||||
|
||||
#define LOG_LEVEL_SILENT (-1)
|
||||
#define LOG_LEVEL_DEBUG (0)
|
||||
#define LOG_LEVEL_INFO (1)
|
||||
#define LOG_LEVEL_WARN (2)
|
||||
#define LOG_LEVEL_ERROR (3)
|
||||
#define LOG_LEVEL_FATAL (4)
|
||||
|
||||
#define OVERLAY_MAX_INTERFACES 16
|
||||
|
||||
#define CRYPT_CIPHERED 1
|
||||
@ -378,4 +360,4 @@
|
||||
#define DEFAULT_MONITOR_SOCKET_NAME "org.servalproject.servald.monitor.socket"
|
||||
#define DEFAULT_MDP_SOCKET_NAME "org.servalproject.servald.mdp.socket"
|
||||
|
||||
#endif
|
||||
#endif // __SERVALD_CONSTANTS_H
|
||||
|
36
log.c
36
log.c
@ -1,6 +1,6 @@
|
||||
/*
|
||||
Serval Distributed Numbering Architecture (DNA)
|
||||
Copyright (C) 2010 Paul Gardner-Stephen
|
||||
Serval logging.
|
||||
Copyright (C) 2012 Serval Project Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -253,38 +253,6 @@ int dump(char *name, unsigned char *addr, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *catv(const char *data, char *buf, size_t len)
|
||||
{
|
||||
strbuf b = strbuf_local(buf, len);
|
||||
for (; *data && !strbuf_overrun(b); ++data) {
|
||||
if (*data == '\n') strbuf_puts(b, "\\n");
|
||||
else if (*data == '\r') strbuf_puts(b, "\\r");
|
||||
else if (*data == '\t') strbuf_puts(b, "\\t");
|
||||
else if (*data == '\\') strbuf_puts(b, "\\\\");
|
||||
else if (isprint(*data)) strbuf_putc(b, *data);
|
||||
else strbuf_sprintf(b, "\\x%02x", *data);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
int dumpResponses(struct response_set *responses)
|
||||
{
|
||||
struct response *r;
|
||||
if (!responses) {
|
||||
DEBUG("Response set is NULL");
|
||||
return 0;
|
||||
}
|
||||
DEBUGF("Response set claims to contain %d entries.", responses->response_count);
|
||||
r = responses->responses;
|
||||
while(r) {
|
||||
DEBUGF(" response code 0x%02x", r->code);
|
||||
if (r->next && r->next->prev != r)
|
||||
DEBUG(" !! response chain is broken");
|
||||
r = r->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int debugFlagMask(const char *flagname) {
|
||||
if (!strcasecmp(flagname,"all")) return DEBUG_ALL;
|
||||
else if (!strcasecmp(flagname,"interfaces")) return DEBUG_OVERLAYINTERFACES;
|
||||
|
81
log.h
81
log.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2010-2012 Paul Gardner-Stephen, Serval Project.
|
||||
Copyright (C) 2012 Serval Project Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -16,29 +16,63 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SERVALD_LOG_H
|
||||
#define __SERVALD_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
|
||||
extern unsigned int debug;
|
||||
|
||||
#define DEBUG_ALL (~0)
|
||||
#define DEBUG_PACKETRX (1 << 0)
|
||||
#define DEBUG_OVERLAYINTERFACES (1 << 1)
|
||||
#define DEBUG_VERBOSE (1 << 2)
|
||||
#define DEBUG_VERBOSE_IO (1 << 3)
|
||||
#define DEBUG_PEERS (1 << 4)
|
||||
#define DEBUG_DNARESPONSES (1 << 5)
|
||||
#define DEBUG_DNAHELPER (1 << 6)
|
||||
#define DEBUG_SIMULATION (1 << 7)
|
||||
#define DEBUG_RHIZOME_RX (1 << 8)
|
||||
#define DEBUG_PACKETFORMATS (1 << 9)
|
||||
#define DEBUG_GATEWAY (1 << 10)
|
||||
#define DEBUG_KEYRING (1 << 11)
|
||||
#define DEBUG_IO (1 << 12)
|
||||
#define DEBUG_OVERLAYFRAMES (1 << 13)
|
||||
#define DEBUG_OVERLAYABBREVIATIONS (1 << 14)
|
||||
#define DEBUG_OVERLAYROUTING (1 << 15)
|
||||
#define DEBUG_SECURITY (1 << 16)
|
||||
#define DEBUG_RHIZOME (1 << 17)
|
||||
#define DEBUG_OVERLAYROUTEMONITOR (1 << 18)
|
||||
#define DEBUG_QUEUES (1 << 19)
|
||||
#define DEBUG_BROADCASTS (1 << 20)
|
||||
#define DEBUG_RHIZOME_TX (1 << 21)
|
||||
#define DEBUG_PACKETTX (1 << 22)
|
||||
#define DEBUG_PACKETCONSTRUCTION (1 << 23)
|
||||
#define DEBUG_MANIFESTS (1 << 24)
|
||||
#define DEBUG_MDPREQUESTS (1 << 25)
|
||||
#define DEBUG_TIMING (1 << 26)
|
||||
|
||||
#define LOG_LEVEL_SILENT (-1)
|
||||
#define LOG_LEVEL_DEBUG (0)
|
||||
#define LOG_LEVEL_INFO (1)
|
||||
#define LOG_LEVEL_WARN (2)
|
||||
#define LOG_LEVEL_ERROR (3)
|
||||
#define LOG_LEVEL_FATAL (4)
|
||||
|
||||
void set_logging(FILE *f);
|
||||
FILE *open_logging();
|
||||
void close_logging();
|
||||
void logArgv(int level, const char *file, unsigned int line, const char *function, const char *label, int argc, const char *const *argv);
|
||||
void logMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, ...);
|
||||
void vlogMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, va_list);
|
||||
unsigned int debugFlagMask(const char *flagname);
|
||||
char *catv(const char *data, char *buf, size_t len);
|
||||
int dump(char *name, unsigned char *addr, size_t len);
|
||||
char *toprint(char *dstStr, ssize_t dstChars, const char *srcBuf, size_t srcBytes);
|
||||
void logArgv(int level, const char *file, unsigned int line, const char *function, const char *label, int argc, const char *const *argv);
|
||||
size_t toprint_strlen(ssize_t dstStrLen, const char *srcBuf, size_t srcBytes);
|
||||
ssize_t get_self_executable_path(char *buf, size_t len);
|
||||
int log_backtrace(const char *file, unsigned int line, const char *function);
|
||||
|
||||
#define alloca_toprint(dstlen,buf,len) toprint((char *)alloca(toprint_strlen((dstlen), (buf), (len)) + 1), (dstlen), (buf), (len))
|
||||
|
||||
#define LOGF(L,F,...) (logMessage(L, __FILE__, __LINE__, __FUNCTION__, F, ##__VA_ARGS__))
|
||||
#define LOGF_perror(L,F,...) logMessage_perror(L, __FILE__, __LINE__, __FUNCTION__, F, ##__VA_ARGS__)
|
||||
@ -74,31 +108,4 @@ int log_backtrace(const char *file, unsigned int line, const char *function);
|
||||
|
||||
#define BACKTRACE log_backtrace(__FILE__, __LINE__, __FUNCTION__)
|
||||
|
||||
struct response {
|
||||
int code;
|
||||
unsigned char sid[SID_SIZE];
|
||||
struct in_addr sender;
|
||||
int recvttl;
|
||||
unsigned char *response;
|
||||
int response_len;
|
||||
int var_id;
|
||||
int var_instance;
|
||||
int value_len;
|
||||
int value_offset;
|
||||
int value_bytes;
|
||||
struct response *next,*prev;
|
||||
|
||||
/* who sent it? */
|
||||
unsigned short peer_id;
|
||||
/* have we checked it to see if it allows us to stop requesting? */
|
||||
unsigned char checked;
|
||||
};
|
||||
|
||||
struct response_set {
|
||||
struct response *responses;
|
||||
struct response *last_response;
|
||||
int response_count;
|
||||
|
||||
/* Bit mask of peers who have replied */
|
||||
unsigned char *reply_bitmask;
|
||||
};
|
||||
#endif // __SERVALD_LOG_H
|
||||
|
18
responses.c
18
responses.c
@ -19,6 +19,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "serval.h"
|
||||
|
||||
int dumpResponses(struct response_set *responses)
|
||||
{
|
||||
struct response *r;
|
||||
if (!responses) {
|
||||
DEBUG("Response set is NULL");
|
||||
return 0;
|
||||
}
|
||||
DEBUGF("Response set claims to contain %d entries.", responses->response_count);
|
||||
r = responses->responses;
|
||||
while(r) {
|
||||
DEBUGF(" response code 0x%02x", r->code);
|
||||
if (r->next && r->next->prev != r)
|
||||
DEBUG(" !! response chain is broken");
|
||||
r = r->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clearResponse(struct response **response)
|
||||
{
|
||||
while(*response)
|
||||
|
65
serval.h
65
serval.h
@ -1,6 +1,7 @@
|
||||
/*
|
||||
Serval Distributed Numbering Architecture (DNA)
|
||||
Copyright (C) 2010 Paul Gardner-Stephen
|
||||
Serval Daemon
|
||||
Copyright (C) 2010-2012 Paul Gardner-Stephen
|
||||
Copyright (C) 2012 Serval Project Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -17,6 +18,8 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SERVALD_SERVALD_H
|
||||
#define __SERVALD_SERVALD_H
|
||||
|
||||
// #define MALLOC_PARANOIA
|
||||
|
||||
@ -559,19 +562,55 @@ int packetSetSidFromId(unsigned char *packet,int packet_maxlen,int *packet_len,
|
||||
keyring_identity *id);
|
||||
int packetFinalise(unsigned char *packet,int packet_maxlen,int recvttl,
|
||||
int *packet_len,int cryptoflags);
|
||||
int extractResponses(struct in_addr sender,unsigned char *buffer,int len,struct response_set *responses);
|
||||
int packetGetID(unsigned char *packet,int len,char *did,char *sid);
|
||||
int getPeerList();
|
||||
|
||||
struct response {
|
||||
int code;
|
||||
unsigned char sid[SID_SIZE];
|
||||
struct in_addr sender;
|
||||
int recvttl;
|
||||
unsigned char *response;
|
||||
int response_len;
|
||||
int var_id;
|
||||
int var_instance;
|
||||
int value_len;
|
||||
int value_offset;
|
||||
int value_bytes;
|
||||
struct response *next,*prev;
|
||||
|
||||
/* who sent it? */
|
||||
unsigned short peer_id;
|
||||
/* have we checked it to see if it allows us to stop requesting? */
|
||||
unsigned char checked;
|
||||
};
|
||||
|
||||
struct response_set {
|
||||
struct response *responses;
|
||||
struct response *last_response;
|
||||
int response_count;
|
||||
|
||||
/* Bit mask of peers who have replied */
|
||||
unsigned char *reply_bitmask;
|
||||
};
|
||||
|
||||
int clearResponse(struct response **response);
|
||||
int clearResponses(struct response_set *responses);
|
||||
int fixResponses(struct response_set *responses);
|
||||
int dumpResponses(struct response_set *responses);
|
||||
int eraseLastResponse(struct response_set *responses);
|
||||
int responseFromPeerP(struct response_set *responses,int peerId);
|
||||
int responseFromPeer(struct response_set *responses,int peerId);
|
||||
int extractResponses(struct in_addr sender,unsigned char *buffer,int len,struct response_set *responses);
|
||||
|
||||
int sendToPeers(unsigned char *packet,int packet_len,int method,int peerId,struct response_set *responses);
|
||||
int getReplyPackets(int method,int peer,int batchP,struct response_set *responses,
|
||||
unsigned char *transaction_id,struct sockaddr *recvaddr,int timeout);
|
||||
int clearResponse(struct response **response);
|
||||
int packageVariableSegment(unsigned char *data,int *dlen,
|
||||
struct response *h,
|
||||
int offset,int buffer_size);
|
||||
int packageVariableSegment(unsigned char *data, int *dlen, struct response *h, int offset, int buffer_size);
|
||||
int unpackageVariableSegment(unsigned char *data, int dlen, int flags, struct response *r);
|
||||
|
||||
int packetDecipher(unsigned char *packet,int len,int cipher);
|
||||
int safeZeroField(unsigned char *packet,int start,int count);
|
||||
int unpackageVariableSegment(unsigned char *data,int dlen,int flags,struct response *r);
|
||||
int extractSid(const unsigned char *packet,int *ofs, char *sid);
|
||||
int hlrSetVariable(unsigned char *hlr,int hofs,int varid,int varinstance,
|
||||
unsigned char *value,int len);
|
||||
@ -585,18 +624,12 @@ int extractRequest(unsigned char *packet,int *packet_ofs,int packet_len,
|
||||
int *start_offset,int *max_offset,int *flags);
|
||||
int hlrGetVariable(unsigned char *hlr,int hofs,int varid,int varinstance,
|
||||
unsigned char *value,int *len);
|
||||
int dumpResponses(struct response_set *responses);
|
||||
int eraseLastResponse(struct response_set *responses);
|
||||
int dropPacketP(size_t packet_len);
|
||||
int clearResponses(struct response_set *responses);
|
||||
int responseFromPeerP(struct response_set *responses,int peerId);
|
||||
int responseFromPeer(struct response_set *responses,int peerId);
|
||||
int additionalPeer(char *peer);
|
||||
int readRoutingTable(struct in_addr peers[],int *peer_count,int peer_max);
|
||||
int readBatmanPeerFile(char *file_path,struct in_addr peers[],int *peer_count,int peer_max);
|
||||
int getBatmanPeerList(char *socket_path,struct in_addr peers[],int *peer_count,int peer_max);
|
||||
int hlrDump(unsigned char *hlr,int hofs);
|
||||
int fixResponses(struct response_set *responses);
|
||||
int importHlr(char *textfile);
|
||||
int exportHlr(unsigned char *hlr,char *text);
|
||||
int openHlrFile(char *backing_file,int size);
|
||||
@ -615,8 +648,6 @@ int readArpTable(struct in_addr peers[],int *peer_count,int peer_max);
|
||||
int overlay_frame_process(struct overlay_interface *interface,overlay_frame *f);
|
||||
int overlay_frame_resolve_addresses(overlay_frame *f);
|
||||
|
||||
#define alloca_toprint(dstlen,buf,len) toprint((char *)alloca(toprint_strlen((dstlen), (buf), (len)) + 1), (dstlen), (buf), (len))
|
||||
|
||||
#define alloca_tohex(buf,len) tohex((char *)alloca((len)*2+1), (buf), (len))
|
||||
#define alloca_tohex_sid(sid) alloca_tohex((sid), SID_SIZE)
|
||||
|
||||
@ -1198,3 +1229,5 @@ void dump_stack();
|
||||
|
||||
#define OUT() fd_func_exit(&_this_call);
|
||||
#define RETURN(X) { OUT() return(X); }
|
||||
|
||||
#endif // __SERVALD_SERVALD_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user