2013-08-06 03:51:58 +08:00
|
|
|
/*
|
|
|
|
* util.h -- Utilities.
|
|
|
|
*
|
|
|
|
* This file is donated to the Tox Project.
|
|
|
|
* Copyright 2013 plutooo
|
2013-10-25 04:37:39 +08:00
|
|
|
*
|
2013-10-24 02:32:09 +08:00
|
|
|
* Copyright (C) 2013 Tox project All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Tox.
|
|
|
|
*
|
|
|
|
* Tox 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Tox 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 Tox. If not, see <http://www.gnu.org/licenses/>.
|
2013-08-06 03:51:58 +08:00
|
|
|
*/
|
|
|
|
|
2013-09-14 00:05:11 +08:00
|
|
|
#ifndef __UTIL_H__
|
|
|
|
#define __UTIL_H__
|
|
|
|
|
2013-09-11 02:55:05 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2014-11-29 20:42:19 +08:00
|
|
|
#include <pthread.h>
|
2013-09-11 02:55:05 +08:00
|
|
|
|
2014-11-18 07:46:46 +08:00
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b))
|
2014-05-31 23:27:22 +08:00
|
|
|
|
2013-10-25 04:32:28 +08:00
|
|
|
void unix_time_update();
|
|
|
|
uint64_t unix_time();
|
|
|
|
int is_timeout(uint64_t timestamp, uint64_t timeout);
|
|
|
|
|
|
|
|
|
|
|
|
/* id functions */
|
2014-06-11 00:27:05 +08:00
|
|
|
bool id_equal(const uint8_t *dest, const uint8_t *src);
|
|
|
|
uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */
|
2013-10-25 04:32:28 +08:00
|
|
|
|
2014-01-19 22:44:33 +08:00
|
|
|
void host_to_net(uint8_t *num, uint16_t numbytes);
|
|
|
|
#define net_to_host(x, y) host_to_net(x, y)
|
2013-10-25 04:32:28 +08:00
|
|
|
|
2014-10-25 09:04:27 +08:00
|
|
|
uint16_t lendian_to_host16(uint16_t lendian);
|
|
|
|
#define host_tolendian16(x) lendian_to_host16(x)
|
|
|
|
|
|
|
|
void host_to_lendian32(uint8_t *dest, uint32_t num);
|
|
|
|
|
2013-10-25 04:32:28 +08:00
|
|
|
/* state load/save */
|
2014-06-11 02:54:48 +08:00
|
|
|
typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type);
|
2013-09-14 00:05:11 +08:00
|
|
|
int load_state(load_state_callback_func load_state_callback, void *outer,
|
2014-06-11 02:54:48 +08:00
|
|
|
const uint8_t *data, uint32_t length, uint16_t cookie_inner);
|
2013-09-14 00:05:11 +08:00
|
|
|
|
2014-11-30 05:09:24 +08:00
|
|
|
int create_recursive_mutex(pthread_mutex_t *mutex);
|
2014-11-29 20:42:19 +08:00
|
|
|
|
2013-09-14 00:05:11 +08:00
|
|
|
#endif /* __UTIL_H__ */
|