static int encrypt(int nick_count, char *nicks[]) { char message[8192]; while (fgets(message, sizeof(message), stdin)) { // Remove newline character char *newline = strchr(message, '\n'); if (newline) *newline = '\0'; bool error = false; for (int i = 0; i < nick_count; i++) { char *encrypted = fish_encrypt_for_nick(nicks[i], message); if (encrypted) { fprintf(stderr, "Encrypted [%s]: >>>%s<<<\n", nicks[i], encrypted); free(encrypted); } else { error = true; } } if (error) { fprintf(stderr, "Some of the recipients were't found in the key store!\n"); return 1; } } return 0; }
/** * Called when a message is to be sent. */ static int handle_outgoing(char *word[], char *word_eol[], void *userdata) { const char *own_nick; // Encrypt the message if possible const char *channel = hexchat_get_info(ph, "channel"); char *encrypted = fish_encrypt_for_nick(channel, word_eol[1]); if (!encrypted) return HEXCHAT_EAT_NONE; // Display message own_nick = hexchat_get_info(ph, "nick"); hexchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL); // Send message hexchat_commandf(ph, "PRIVMSG %s :+OK %s", channel, encrypted); free(encrypted); return HEXCHAT_EAT_HEXCHAT; }