Merge branch 'master' of git://github.com/irungentoo/ProjectTox-Core into auto_tests

This commit is contained in:
charmlesscoin 2013-08-07 15:22:57 -04:00
commit 0f664f3122
7 changed files with 79 additions and 17 deletions

View File

@ -116,7 +116,7 @@ int m_addfriend(uint8_t *client_id, uint8_t *data, uint16_t length)
return FAERR_ALREADYSENT;
uint32_t i;
for (i = 0; i < numfriends && i < MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
if (friendlist[i].status == NOFRIEND) {
DHT_addfriend(client_id);
friendlist[i].status = FRIEND_ADDED;
@ -141,7 +141,7 @@ int m_addfriend_norequest(uint8_t * client_id)
if (getfriend_id(client_id) != -1)
return -1;
uint32_t i;
for (i = 0; i < numfriends && i < MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
for (i = 0; i <= numfriends && i <= MAX_NUM_FRIENDS; ++i) { /*TODO: dynamic memory allocation to allow for more than MAX_NUM_FRIENDS friends */
if(friendlist[i].status == NOFRIEND) {
DHT_addfriend(client_id);
friendlist[i].status = FRIEND_REQUESTED;

View File

@ -138,7 +138,8 @@ int main(int argc, char *argv[])
if ( file==NULL ){return 1;}
uint8_t * buffer = malloc(Messenger_size());
Messenger_save(buffer);
fwrite(buffer, 1, Messenger_size(), file);
size_t write_result = fwrite(buffer, 1, Messenger_size(), file);
if (write_result < Messenger_size()) {return 1;}
free(buffer);
fclose(file);
}

View File

@ -51,6 +51,7 @@ unsigned char * hex_string_to_bin(char hex_string[]);
DEBUG_PRINT(__VA_ARGS__, ' '); \
} while (0)
#undef ERROR
#define ERROR(exit_status, ...) do { \
fprintf(stderr, "error in "); \
DEBUG_PRINT(__VA_ARGS__, ' '); \
@ -58,6 +59,7 @@ unsigned char * hex_string_to_bin(char hex_string[]);
} while (0)
#else
#define WARNING(...)
#undef ERROR
#define ERROR(...)
#endif // DEBUG

View File

@ -275,7 +275,7 @@ void change_status(int savetofile)
}
status[i-3] = 0;
m_set_userstatus(status, strlen((char*)status));
m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status));
char numstring[100];
sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
printf(numstring);
@ -407,7 +407,7 @@ int main(int argc, char *argv[])
while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) {
sscanf(line, "%s", (char*)status);
}
m_set_userstatus(status, strlen((char*)status)+1);
m_set_userstatus(USERSTATUS_KIND_RETAIN, status, strlen((char*)status)+1);
statusloaded = 1;
printf("%s\n", status);
fclose(status_file);

View File

@ -32,7 +32,7 @@
void do_header();
void print_message(int friendnumber, uint8_t * string, uint16_t length);
void print_nickchange(int friendnumber, uint8_t *string, uint16_t length);
void print_statuschange(int friendnumber, uint8_t *string, uint16_t length);
void print_statuschange(int friendnumber,USERSTATUS_KIND kind, uint8_t *string, uint16_t length);
void load_key();
void add_friend();
void list_friends();

View File

@ -249,6 +249,7 @@ static void load_data(char *path)
static void draw_bar()
{
static int odd = 0;
int blinkrate = 30;
attron(COLOR_PAIR(4));
mvhline(LINES - 2, 0, '_', COLS);
@ -266,14 +267,13 @@ static void draw_bar()
if (i == active_window)
attron(A_BOLD);
odd = (odd+1) % 10;
if (windows[i].blink && (odd < 5)) {
odd = (odd+1) % blinkrate;
if (windows[i].blink && (odd < (blinkrate/2))) {
attron(COLOR_PAIR(3));
}
printw(" %s", windows[i].title);
if (windows[i].blink && (odd < 5)) {
attron(COLOR_PAIR(3));
if (windows[i].blink && (odd < (blinkrate/2))) {
attroff(COLOR_PAIR(3));
}
if (i == active_window) {
attroff(A_BOLD);
@ -375,9 +375,8 @@ int main(int argc, char *argv[])
ch = getch();
if (ch == '\t' || ch == KEY_BTAB)
set_active_window(ch);
else if (ch != ERR) {
else if (ch != ERR)
a->onKey(a, ch);
}
}
return 0;
}

View File

@ -52,6 +52,17 @@ static void execute(ToxWindow *self, char *u_cmd)
cmd[i - newlines] = u_cmd[i];
}
int leading_spc = 0;
for (i = 0; i < 256 && isspace(cmd[i]); ++i)
leading_spc++;
memmove(cmd, cmd + leading_spc, 256 - leading_spc);
int cmd_end = strlen(cmd);
while (cmd_end > 0 && cmd_end--)
if (!isspace(cmd[cmd_end]))
break;
cmd[cmd_end + 1] = '\0';
if (!strcmp(cmd, "quit") || !strcmp(cmd, "exit") || !strcmp(cmd, "q")) {
endwin();
exit(0);
@ -164,6 +175,54 @@ static void execute(ToxWindow *self, char *u_cmd)
}
else if (!strncmp(cmd, "status ", strlen("status "))) {
char *status = strchr(cmd, ' ');
char *msg;
char *status_text;
if (status == NULL) {
wprintw(self->window, "Invalid syntax.\n");
return;
}
status++;
USERSTATUS_KIND status_kind;
if (!strncmp(status, "online", strlen("online"))) {
status_kind = USERSTATUS_KIND_ONLINE;
status_text = "ONLINE";
}
else if (!strncmp(status, "away", strlen("away"))) {
status_kind = USERSTATUS_KIND_AWAY;
status_text = "AWAY";
}
else if (!strncmp(status, "busy", strlen("busy"))) {
status_kind = USERSTATUS_KIND_BUSY;
status_text = "BUSY";
}
else if (!strncmp(status, "offline", strlen("offline"))) {
status_kind = USERSTATUS_KIND_OFFLINE;
status_text = "OFFLINE";
}
else
{
wprintw(self->window, "Invalid status.\n");
return;
}
msg = strchr(status, ' ');
if (msg == NULL) {
m_set_userstatus_kind(status_kind);
wprintw(self->window, "Status set to: %s\n", status_text);
}
else {
msg++;
m_set_userstatus(status_kind, (uint8_t*) msg, strlen(msg)+1);
wprintw(self->window, "Status set to: %s, %s\n", status_text, msg);
}
}
else if (!strncmp(cmd, "statusmsg ", strlen("statumsg "))) {
char *msg = strchr(cmd, ' ');
if (msg == NULL) {
wprintw(self->window, "Invalid syntax.\n");
@ -306,7 +365,8 @@ static void print_usage(ToxWindow *self)
wprintw(self->window, " connect <ip> <port> <key> : Connect to DHT server\n");
wprintw(self->window, " add <id> <message> : Add friend\n");
wprintw(self->window, " status <message> : Set your status\n");
wprintw(self->window, " status <type> <message> : Set your status\n");
wprintw(self->window, " statusmsg <message> : Set your status\n");
wprintw(self->window, " nick <nickname> : Set your nickname\n");
wprintw(self->window, " accept <number> : Accept friend request\n");
wprintw(self->window, " myid : Print your ID\n");