Use consistent integer types for 64bit compilation

This commit is contained in:
Jeremy Lakeman 2013-07-13 14:47:06 +09:30
parent 3306cda3ab
commit 8ac359e550
14 changed files with 68 additions and 67 deletions

3
cli.h
View File

@ -22,6 +22,7 @@
#include "xprintf.h"
#include "log.h"
#include <stdint.h>
#ifdef HAVE_JNI_H
#include <jni.h>
@ -45,7 +46,7 @@ struct cli_context{
struct cli_schema {
int (*function)(const struct cli_parsed *parsed, struct cli_context *context);
const char *words[COMMAND_LINE_MAX_LABELS];
unsigned long long flags;
uint64_t flags;
#define CLIFLAG_PERMISSIVE_CONFIG (1<<0) /* Accept defective configuration file */
const char *description; // describe this invocation
};

View File

@ -914,11 +914,11 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
// assume we wont hear any responses
int ret=1;
int icount=atoi(count);
time_ms_t timeout_ms = 1000;
int64_t timeout_ms = 1000;
str_to_uint64_interval_ms(opt_timeout, &timeout_ms, NULL);
if (timeout_ms == 0)
timeout_ms = 60 * 60000; // 1 hour...
time_ms_t interval_ms = 1000;
int64_t interval_ms = 1000;
str_to_uint64_interval_ms(opt_interval, &interval_ms, NULL);
overlay_mdp_frame mdp;

View File

@ -4,8 +4,8 @@
// verify a signature against a public sas key.
int crypto_verify_signature(unsigned char *sas_key,
unsigned char *content, unsigned long long content_len,
unsigned char *signature_block, unsigned long long signature_len)
unsigned char *content, int content_len,
unsigned char *signature_block, int signature_len)
{
IN();
@ -52,8 +52,8 @@ int crypto_verify_message(struct subscriber *subscriber, unsigned char *message,
// generate a signature for this raw content, copy the signature to the address requested.
int crypto_create_signature(unsigned char *key,
unsigned char *content, unsigned long long content_len,
unsigned char *signature, unsigned long long *sig_length)
unsigned char *content, int content_len,
unsigned char *signature, int *sig_length)
{
IN();
@ -89,7 +89,7 @@ int crypto_sign_message(struct subscriber *source, unsigned char *content, int b
unsigned char hash[crypto_hash_sha512_BYTES];
crypto_hash_sha512(hash, content, *content_len);
unsigned long long sig_length = SIGNATURE_BYTES;
int sig_length = SIGNATURE_BYTES;
int ret=crypto_create_signature(key, hash, crypto_hash_sha512_BYTES, &content[*content_len], &sig_length);
*content_len+=sig_length;

View File

@ -6,12 +6,12 @@
#define SIGNATURE_BYTES crypto_sign_edwards25519sha512batch_BYTES
int crypto_verify_signature(unsigned char *sas_key,
unsigned char *content, unsigned long long content_len,
unsigned char *signature_block, unsigned long long signature_len);
unsigned char *content, int content_len,
unsigned char *signature_block, int signature_len);
int crypto_verify_message(struct subscriber *subscriber, unsigned char *message, int *message_len);
int crypto_create_signature(unsigned char *key,
unsigned char *content, unsigned long long content_len,
unsigned char *signature, unsigned long long *sig_length);
unsigned char *content, int content_len,
unsigned char *signature, int *sig_length);
int crypto_sign_message(struct subscriber *source, unsigned char *content, int buffer_len, int *content_len);
#endif
#endif

View File

@ -306,7 +306,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
str_toupper_inplace(id);
/* Discard the new manifest unless it is newer than the most recent known version with the same ID */
long long storedversion = -1;
int64_t storedversion = -1;
switch (sqlite_exec_int64(&storedversion, "SELECT version from manifests where id='%s';", id)) {
case -1:
return WHY("Select failed");

View File

@ -134,8 +134,8 @@ typedef struct rhizome_manifest {
/* When finalised, we keep the filehash and maximum priority due to any
group membership handy */
long long fileLength;
long long journalTail;
int64_t fileLength;
int64_t journalTail;
char fileHexHash[SHA512_DIGEST_STRING_LENGTH];
int fileHighestPriority;
@ -156,7 +156,7 @@ typedef struct rhizome_manifest {
int selfSigned;
/* Version of the manifest. Typically the number of milliseconds since 1970. */
long long version;
int64_t version;
int group_count;
char *groups[MAX_MANIFEST_VARS];
@ -175,10 +175,10 @@ typedef struct rhizome_manifest {
#define RHIZOME_SERVICE_FILE "file"
#define RHIZOME_SERVICE_MESHMS "MeshMS1"
extern long long rhizome_space;
extern int64_t rhizome_space;
extern unsigned short rhizome_http_server_port;
int log2ll(unsigned long long x);
int log2ll(uint64_t x);
int rhizome_configure();
int rhizome_enabled();
int rhizome_fetch_delay_ms();
@ -243,11 +243,11 @@ int rhizome_manifest_priority(sqlite_retry_state *retry, const char *id);
int rhizome_read_manifest_file(rhizome_manifest *m, const char *filename, int bufferPAndSize);
int rhizome_hash_file(rhizome_manifest *m, const char *filename,char *hash_out);
char *rhizome_manifest_get(const rhizome_manifest *m, const char *var, char *out, int maxlen);
long long rhizome_manifest_get_ll(rhizome_manifest *m, const char *var);
int rhizome_manifest_set_ll(rhizome_manifest *m,char *var,long long value);
int64_t rhizome_manifest_get_ll(rhizome_manifest *m, const char *var);
int rhizome_manifest_set_ll(rhizome_manifest *m,char *var, int64_t value);
int rhizome_manifest_set(rhizome_manifest *m, const char *var, const char *value);
int rhizome_manifest_del(rhizome_manifest *m, const char *var);
long long rhizome_file_size(char *filename);
int64_t rhizome_file_size(char *filename);
void _rhizome_manifest_free(struct __sourceloc __whence, rhizome_manifest *m);
#define rhizome_manifest_free(m) _rhizome_manifest_free(__WHENCE__,m)
rhizome_manifest *_rhizome_new_manifest(struct __sourceloc __whence);
@ -296,8 +296,8 @@ int _sqlite_exec_void(struct __sourceloc, const char *sqlformat, ...);
int _sqlite_exec_void_loglevel(struct __sourceloc, int log_level, const char *sqlformat, ...);
int _sqlite_exec_void_retry(struct __sourceloc, sqlite_retry_state *retry, const char *sqlformat, ...);
int _sqlite_exec_void_retry_loglevel(struct __sourceloc, int log_level, sqlite_retry_state *retry, const char *sqlformat, ...);
int _sqlite_exec_int64(struct __sourceloc, long long *result, const char *sqlformat, ...);
int _sqlite_exec_int64_retry(struct __sourceloc, sqlite_retry_state *retry, long long *result, const char *sqlformat, ...);
int _sqlite_exec_int64(struct __sourceloc, int64_t *result, const char *sqlformat, ...);
int _sqlite_exec_int64_retry(struct __sourceloc, sqlite_retry_state *retry, int64_t *result, const char *sqlformat, ...);
int _sqlite_exec_strbuf(struct __sourceloc, strbuf sb, const char *sqlformat, ...);
int _sqlite_exec_strbuf_retry(struct __sourceloc, sqlite_retry_state *retry, strbuf sb, const char *sqlformat, ...);
int _sqlite_vexec_strbuf_retry(struct __sourceloc, sqlite_retry_state *retry, strbuf sb, const char *sqlformat, va_list ap);
@ -323,7 +323,7 @@ int rhizome_update_file_priority(const char *fileid);
int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found, int check_author);
int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar);
int64_t rhizome_bar_version(const unsigned char *bar);
unsigned long long rhizome_bar_bidprefix_ll(unsigned char *bar);
uint64_t rhizome_bar_bidprefix_ll(unsigned char *bar);
int rhizome_is_bar_interesting(unsigned char *bar);
int rhizome_list_manifests(struct cli_context *context, const char *service, const char *name,
const char *sender_sid, const char *recipient_sid,
@ -424,7 +424,7 @@ struct rhizome_read{
typedef struct rhizome_http_request {
struct sched_ent alarm;
long long initiate_time; /* time connection was initiated */
time_ms_t initiate_time; /* time connection was initiated */
struct sockaddr_in requestor;
@ -498,8 +498,8 @@ typedef struct rhizome_http_request {
/* The source specification data which are used in different ways by different
request types */
char source[1024];
long long source_index;
long long source_count;
int64_t source_index;
int64_t source_count;
int source_record_size;
unsigned int source_flags;
@ -507,14 +507,14 @@ typedef struct rhizome_http_request {
const char *sql_row;
int64_t rowid;
/* source_index used for offset in blob */
long long blob_end;
int64_t blob_end;
} rhizome_http_request;
struct http_response {
unsigned int result_code;
const char * content_type;
unsigned long long content_length;
uint64_t content_length;
const char * body;
};
@ -528,7 +528,7 @@ int rhizome_server_free_http_request(rhizome_http_request *r);
int rhizome_server_http_send_bytes(rhizome_http_request *r);
int rhizome_server_parse_http_request(rhizome_http_request *r);
int rhizome_server_simple_http_response(rhizome_http_request *r, int result, const char *response);
int rhizome_server_http_response_header(rhizome_http_request *r, int result, const char *mime_type, unsigned long long bytes);
int rhizome_server_http_response_header(rhizome_http_request *r, int result, const char *mime_type, uint64_t bytes);
int rhizome_server_sql_query_fill_buffer(rhizome_http_request *r, char *table, char *column);
int rhizome_http_server_start(int (*http_parse_func)(rhizome_http_request *),
const char *http_parse_func_description,
@ -543,15 +543,15 @@ int is_rhizome_http_server_running();
typedef struct rhizome_direct_bundle_cursor {
/* Where the current fill started */
long long start_size_high;
int64_t start_size_high;
unsigned char start_bid_low[RHIZOME_MANIFEST_ID_BYTES];
/* Limit of where this cursor may traverse */
long long limit_size_high;
int64_t limit_size_high;
unsigned char limit_bid_high[RHIZOME_MANIFEST_ID_BYTES];
long long size_low;
long long size_high;
int64_t size_low;
int64_t size_high;
unsigned char bid_low[RHIZOME_MANIFEST_ID_BYTES];
unsigned char bid_high[RHIZOME_MANIFEST_ID_BYTES];
unsigned char *buffer;
@ -574,7 +574,7 @@ int rhizome_direct_bundle_iterator_fill(rhizome_direct_bundle_cursor *c,
void rhizome_direct_bundle_iterator_free(rhizome_direct_bundle_cursor **c);
int rhizome_direct_get_bars(const unsigned char bid_low[RHIZOME_MANIFEST_ID_BYTES],
unsigned char bid_high[RHIZOME_MANIFEST_ID_BYTES],
long long size_low,long long size_high,
int64_t size_low, int64_t size_high,
const unsigned char bid_max[RHIZOME_MANIFEST_ID_BYTES],
unsigned char *bars_out,
int bars_requested);
@ -664,7 +664,7 @@ int rhizome_fetch_has_queue_space(unsigned char log2_size);
struct http_response_parts {
int code;
char *reason;
long long content_length;
int64_t content_length;
char *content_start;
};

View File

@ -384,7 +384,7 @@ char *rhizome_manifest_get(const rhizome_manifest *m, const char *var, char *out
return NULL;
}
long long rhizome_manifest_get_ll(rhizome_manifest *m, const char *var)
int64_t rhizome_manifest_get_ll(rhizome_manifest *m, const char *var)
{
if (!m)
return -1;
@ -454,7 +454,7 @@ int rhizome_manifest_set(rhizome_manifest *m, const char *var, const char *value
return 0;
}
int rhizome_manifest_set_ll(rhizome_manifest *m,char *var,long long value)
int rhizome_manifest_set_ll(rhizome_manifest *m, char *var, int64_t value)
{
char svalue[100];

View File

@ -74,7 +74,7 @@ sqlite3 *rhizome_db=NULL;
/* XXX Requires a messy join that might be slow. */
int rhizome_manifest_priority(sqlite_retry_state *retry, const char *id)
{
long long result = 0;
int64_t result = 0;
if (sqlite_exec_int64_retry(retry, &result,
"select max(grouplist.priorty) from grouplist,manifests,groupmemberships"
" where manifests.id='%s'"
@ -227,7 +227,7 @@ int rhizome_opendb()
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
long long version;
int64_t version;
if (sqlite_exec_int64_retry(&retry, &version, "PRAGMA user_version;") == -1)
RETURN(-1);
@ -573,7 +573,7 @@ int _sqlite_exec_void_retry_loglevel(struct __sourceloc __whence, int log_level,
return ret;
}
static int _sqlite_vexec_int64(struct __sourceloc __whence, sqlite_retry_state *retry, long long *result, const char *sqlformat, va_list ap)
static int _sqlite_vexec_int64(struct __sourceloc __whence, sqlite_retry_state *retry, int64_t *result, const char *sqlformat, va_list ap)
{
strbuf stmt = strbuf_alloca(8192);
strbuf_vsprintf(stmt, sqlformat, ap);
@ -610,7 +610,7 @@ static int _sqlite_vexec_int64(struct __sourceloc __whence, sqlite_retry_state *
*
* @author Andrew Bettison <andrew@servalproject.com>
*/
int _sqlite_exec_int64(struct __sourceloc __whence, long long *result, const char *sqlformat,...)
int _sqlite_exec_int64(struct __sourceloc __whence, int64_t *result, const char *sqlformat,...)
{
va_list ap;
va_start(ap, sqlformat);
@ -627,7 +627,7 @@ int _sqlite_exec_int64(struct __sourceloc __whence, long long *result, const cha
*
* @author Andrew Bettison <andrew@servalproject.com>
*/
int _sqlite_exec_int64_retry(struct __sourceloc __whence, sqlite_retry_state *retry, long long *result, const char *sqlformat,...)
int _sqlite_exec_int64_retry(struct __sourceloc __whence, sqlite_retry_state *retry, int64_t *result, const char *sqlformat,...)
{
va_list ap;
va_start(ap, sqlformat);
@ -686,11 +686,11 @@ int _sqlite_vexec_strbuf_retry(struct __sourceloc __whence, sqlite_retry_state *
return sqlite_code_ok(stepcode) && ret != -1 ? rowcount : -1;
}
long long rhizome_database_used_bytes()
int64_t rhizome_database_used_bytes()
{
long long db_page_size;
long long db_page_count;
long long db_free_page_count;
int64_t db_page_size;
int64_t db_page_count;
int64_t db_free_page_count;
if ( sqlite_exec_int64(&db_page_size, "PRAGMA page_size;") == -1LL
|| sqlite_exec_int64(&db_page_count, "PRAGMA page_count;") == -1LL
|| sqlite_exec_int64(&db_free_page_count, "PRAGMA free_count;") == -1LL
@ -1190,7 +1190,7 @@ void rhizome_bytes_to_hex_upper(unsigned const char *in, char *out, int byteCoun
int rhizome_update_file_priority(const char *fileid)
{
/* work out the highest priority of any referrer */
long long highestPriority = -1;
int64_t highestPriority = -1;
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
if (sqlite_exec_int64_retry(&retry, &highestPriority,
"SELECT max(grouplist.priority) FROM MANIFESTS,GROUPMEMBERSHIPS,GROUPLIST"

View File

@ -745,7 +745,7 @@ void rhizome_direct_bundle_iterator_free(rhizome_direct_bundle_cursor **c)
*/
int rhizome_direct_get_bars(const unsigned char bid_low[RHIZOME_MANIFEST_ID_BYTES],
unsigned char bid_high[RHIZOME_MANIFEST_ID_BYTES],
long long size_low,long long size_high,
int64_t size_low, int64_t size_high,
const unsigned char bid_max[RHIZOME_MANIFEST_ID_BYTES],
unsigned char *bars_out,
int bars_requested)

View File

@ -311,7 +311,7 @@ int rhizome_any_fetch_queued()
struct rhizome_manifest_version_cache_slot {
unsigned char idprefix[24];
long long version;
int64_t version;
};
struct rhizome_manifest_version_cache_slot rhizome_manifest_version_cache[RHIZOME_VERSION_CACHE_SIZE][RHIZOME_VERSION_CACHE_ASSOCIATIVITY];
@ -364,7 +364,7 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
// TODO, work out why the cache was failing and fix it, then prove that it is faster than accessing the database.
// skip the cache for now
long long dbVersion = -1;
int64_t dbVersion = -1;
if (sqlite_exec_int64(&dbVersion, "SELECT version FROM MANIFESTS WHERE id='%s';", id) == -1)
return WHY("Select failure");
if (dbVersion >= m->version) {
@ -394,7 +394,7 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
}
if (i==24) {
/* Entries match -- so check version */
long long rev = rhizome_manifest_get_ll(m,"version");
int64_t rev = rhizome_manifest_get_ll(m,"version");
if (1) DEBUGF("cached version %lld vs manifest version %lld", entry->version,rev);
if (rev > entry->version) {
/* If we only have an old version, try refreshing the cache
@ -446,8 +446,8 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
and require regular database queries, and that memory allowing, we should use
a fairly large cache here.
*/
long long manifest_version = rhizome_manifest_get_ll(m, "version");
long long count;
int64_t manifest_version = rhizome_manifest_get_ll(m, "version");
int64_t count;
switch (sqlite_exec_int64(&count, "select count(*) from manifests where id='%s' and version>=%lld", id, manifest_version)) {
case -1:
return WHY("database error reading stored manifest version");
@ -455,7 +455,7 @@ int rhizome_manifest_version_cache_lookup(rhizome_manifest *m)
if (count) {
/* Okay, we have a stored version which is newer, so update the cache
using a random replacement strategy. */
long long stored_version;
int64_t stored_version;
if (sqlite_exec_int64(&stored_version, "select version from manifests where id='%s'", id) < 1)
return WHY("database error reading stored manifest version"); // database is broken, we can't confirm that it is here
DEBUGF("stored version=%lld, manifest_version=%lld (not fetching; remembering in cache)",
@ -976,7 +976,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
}
if (config.debug.rhizome_rx) {
long long stored_version;
int64_t stored_version;
if (sqlite_exec_int64(&stored_version, "select version from manifests where id='%s'", bid) > 0)
DEBUGF(" is new (have version %lld)", stored_version);
}

View File

@ -758,7 +758,7 @@ int rhizome_server_simple_http_response(rhizome_http_request *r, int result, con
return rhizome_server_set_response(r, &hr);
}
int rhizome_server_http_response_header(rhizome_http_request *r, int result, const char *mime_type, unsigned long long bytes)
int rhizome_server_http_response_header(rhizome_http_request *r, int result, const char *mime_type, uint64_t bytes)
{
struct http_response hr;
bzero(&hr, sizeof hr);

View File

@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/* Android doesn't have log2(), and we don't really need to do floating point
math to work out how big a file is.
*/
int log2ll(unsigned long long x)
int log2ll(uint64_t x)
{
unsigned char lookup[16]={0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4};
int v=-1;
@ -125,16 +125,16 @@ int64_t rhizome_bar_version(const unsigned char *bar)
/* This function only displays the first 8 bytes, and should not be used
for comparison. */
unsigned long long rhizome_bar_bidprefix_ll(unsigned char *bar)
uint64_t rhizome_bar_bidprefix_ll(unsigned char *bar)
{
long long bidprefix=0;
uint64_t bidprefix=0;
int i;
for(i=0;i<8;i++)
bidprefix|=((unsigned long long)bar[RHIZOME_BAR_PREFIX_OFFSET+7-i])<<(8*i);
bidprefix|=((uint64_t)bar[RHIZOME_BAR_PREFIX_OFFSET+7-i])<<(8*i);
return bidprefix;
}
static int append_bars(struct overlay_buffer *e, sqlite_retry_state *retry, const char *sql, long long *last_rowid){
static int append_bars(struct overlay_buffer *e, sqlite_retry_state *retry, const char *sql, int64_t *last_rowid){
int count=0;
sqlite3_stmt *statement=sqlite_prepare(retry, sql, *last_rowid);
@ -172,7 +172,7 @@ static int append_bars(struct overlay_buffer *e, sqlite_retry_state *retry, cons
/* Periodically queue BAR advertisements
Always advertise the most recent 3 manifests in the table, cycle through the rest of the table, adding 17 BAR's at a time
*/
long long bundles_available=0;
int64_t bundles_available=0;
void overlay_rhizome_advertise(struct sched_ent *alarm){
bundles_available=0;
static int64_t bundle_last_rowid=INT64_MAX;
@ -207,7 +207,7 @@ void overlay_rhizome_advertise(struct sched_ent *alarm){
ob_append_byte(frame->payload, 2);
ob_append_ui16(frame->payload, rhizome_http_server_port);
long long rowid=0;
int64_t rowid=0;
int count = append_bars(frame->payload, &retry,
"SELECT BAR,ROWID FROM MANIFESTS ORDER BY ROWID DESC LIMIT 3",
&rowid);

View File

@ -6,7 +6,7 @@
#define RHIZOME_BUFFER_MAXIMUM_SIZE (1024*1024)
int rhizome_exists(const char *fileHash){
long long gotfile = 0;
int64_t gotfile = 0;
if (sqlite_exec_int64(&gotfile,
"SELECT COUNT(*) FROM FILES WHERE ID='%s' and datavalid=1;",

View File

@ -806,7 +806,7 @@ extern int last_radio_rssi;
extern int last_radio_temperature;
int rhizome_active_fetch_count();
int rhizome_active_fetch_bytes_received(int q);
extern long long bundles_available;
extern int64_t bundles_available;
extern char crash_handler_clue[1024];