Merge pull request #87 from TrevorDorl/master

Adds the option 'nokey' to disable loading and saving keys, for debuggin...
This commit is contained in:
irungentoo 2013-07-22 10:33:18 -07:00
commit b368a6b4b8

View File

@ -1,7 +1,7 @@
#include "nTox.h" #include "nTox.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <string.h>
#ifdef WIN32 #ifdef WIN32
#define c_sleep(x) Sleep(1*x) #define c_sleep(x) Sleep(1*x)
#else #else
@ -212,25 +212,15 @@ void print_statuschange(int friendnumber, uint8_t *string, uint16_t length) {
free(name); free(name);
new_lines(msg); new_lines(msg);
} }
int main(int argc, char *argv[]) int load_key(){
{
if (argc < 4) {
printf("[!] Usage: %s [IP] [port] [public_key]\n", argv[0]);
exit(0);
}
int c;
int on = 0;
initMessenger();
FILE *data_file = NULL; FILE *data_file = NULL;
//if keyfiles exist
if ((data_file = fopen("data","r"))) { if ((data_file = fopen("data","r"))) {
//load keys //load keys
fseek(data_file, 0, SEEK_END); fseek(data_file, 0, SEEK_END);
int size = ftell(data_file); int size = ftell(data_file);
fseek(data_file, 0, SEEK_SET); fseek(data_file, 0, SEEK_SET);
uint8_t data[size]; uint8_t data[size];
if(fread(data, sizeof(uint8_t), size, data_file) != size) if(fread(data, sizeof(uint8_t), size, data_file) != size){
{
printf("Error reading file\n"); printf("Error reading file\n");
exit(0); exit(0);
} }
@ -241,13 +231,31 @@ int main(int argc, char *argv[])
uint8_t data[size]; uint8_t data[size];
Messenger_save(data); Messenger_save(data);
data_file = fopen("data","w"); data_file = fopen("data","w");
if(fwrite(data, sizeof(uint8_t), size, data_file) != size) if(fwrite(data, sizeof(uint8_t), size, data_file) != size){
{
printf("Error writing file\n"); printf("Error writing file\n");
exit(0); exit(0);
} }
} }
fclose(data_file); fclose(data_file);
return 0;
}
int main(int argc, char *argv[])
{
if (argc < 4) {
printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]);
exit(0);
}
int c;
int on = 0;
initMessenger();
//if keyfiles exist
if(argc > 4){
if(strncmp(argv[4], "nokey", 6) < 0){
load_key();
}
} else {
load_key();
}
m_callback_friendrequest(print_request); m_callback_friendrequest(print_request);
m_callback_friendmessage(print_message); m_callback_friendmessage(print_message);
m_callback_namechange(print_nickchange); m_callback_namechange(print_nickchange);