⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encrypt.c

📁 一个windows上的加解密程式 提供方便的介面让使用者操作
💻 C
📖 第 1 页 / 共 4 页
字号:
         GE_send_msg_cb(node->gc->account, (char*)who, &tmp_msg, 0);         GE_clear_string(node->msg);         if (tmp_msg != 0) {            g_free(tmp_msg);         }         if (node == last_out_msg) {            last_out_msg = prev;         }         if (prev != 0) { /* a random one matched */            prev->next = node->next;            g_free(node);            node = prev->next;         } else {  /* the first one matched */            first_out_msg = node->next;            g_free(node);            node = first_out_msg;         }      } else { /* didn't match */         prev = node;         node = node->next;      }   }}void GE_delete_stored_msgs(GaimAccount* acct, const char* who) {   msg_node* node = first_out_msg;   msg_node* prev = 0;   gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "delete_stored_msgs\n");   while (node != 0) {      gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption",                 "Looking for stored msg:%s:%s\n",node->who, who);      if ((strcmp(node->who, who) == 0) && (node->gc->account == acct)) {         GE_clear_string(node->msg);         if (node == last_out_msg) {            last_out_msg = prev;         }         if (prev != 0) { /* a random one matched */            prev->next = node->next;            g_free(node);            node = prev->next;         } else {  /* the first one matched */            first_out_msg = node->next;            g_free(node);            node = first_out_msg;         }      } else { /* didn't match */         prev = node;         node = node->next;      }   }}void GE_show_stored_msgs(GaimAccount*acct, const char* who, char** return_msg) {   msg_node* node = first_inc_msg;   msg_node* prev = 0;   char *tmp_msg;   GaimConversation *conv = gaim_find_conversation_with_account(who, acct);   while (node != 0) {      gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "show_stored_msgs:%p:%s:%s:\n", node, node->who, who);		if (strcmp(node->who, who) == 0) {         tmp_msg = g_strdup(node->msg);         got_encrypted_msg(node->gc, who, &tmp_msg);         if (tmp_msg != 0) {            gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "showing msg:%s\n", tmp_msg);				if (return_msg) {               /* We should return the last received message in *return_msg */               if (*return_msg) {                  /* We've already got a queued message to show, so swap, and force display of                     the first one */                  if (!conv) {                     conv = gaim_conversation_new(GAIM_CONV_IM, node->gc->account, who);                  }                  gaim_conv_im_write(GAIM_CONV_IM(conv), who, *return_msg,                                     GAIM_MESSAGE_RECV, time((time_t)NULL));                  gaim_conv_window_flash(gaim_conversation_get_window(conv));                  g_free(*return_msg);                  *return_msg = 0;               } else {                  *return_msg = tmp_msg;               }            } else {               /* Just display it */               if (!conv) {                  conv = gaim_conversation_new(GAIM_CONV_IM, node->gc->account, who);               }               gaim_conv_im_write(GAIM_CONV_IM(conv), who, tmp_msg,                                  GAIM_MESSAGE_RECV, time((time_t)NULL));               gaim_conv_window_flash(gaim_conversation_get_window(conv));               g_free(tmp_msg);            }         }         if (node == last_inc_msg) {            last_inc_msg = prev;         }         if (prev != 0) { /* a random one matched */            prev->next = node->next;            g_free(node);            node = prev->next;         } else {  /* the first one matched */            first_inc_msg = node->next;            g_free(node);            node = first_inc_msg;         }      } else { /* didn't match */         prev = node;         node = node->next;      }   }}static void reap_all_sent_messages(GaimConversation* conv){   GQueue *sent_msg_queue = g_hash_table_lookup(conv->data, "sent messages");   GE_SentMessage *sent_msg_item;   /* gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "ZZZ Reaping all messages: %p\n", conv); */      while (!g_queue_is_empty(sent_msg_queue)) {      sent_msg_item = g_queue_pop_tail(sent_msg_queue);      /* gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "ZZZ Message: %s\n", sent_msg_item->id); */      g_free(sent_msg_item->id);      g_free(sent_msg_item->msg);      g_free(sent_msg_item);   }}static void reap_old_sent_messages(GaimConversation* conv){   GQueue *sent_msg_queue = g_hash_table_lookup(conv->data, "sent messages");      GE_SentMessage *sent_msg_item;   time_t curtime = time(0);      /* gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "ZZZ Reaping old messages: %p\n", conv); */   while (!g_queue_is_empty(sent_msg_queue)) {      sent_msg_item = g_queue_peek_tail(sent_msg_queue);      /* gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "ZZZ Message: %s\n", sent_msg_item->id); */      if (curtime - sent_msg_item->time > 60) { /* message is over 1 minute old */         sent_msg_item = g_queue_pop_tail(sent_msg_queue);         /* gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption", "ZZZ  Deleted\n"); */         g_free(sent_msg_item->id);         g_free(sent_msg_item->msg);         g_free(sent_msg_item);      } else {         /* These were pushed on in order, so if this one is not old, we're done */         break;      }   }}static gboolean GE_got_msg_cb(GaimAccount *acct, char **who, char **message, GaimConvImFlags flags, void *m) {   char *name;   GaimConversation *conv;   gchar *headerpos;    /* Header is allowed to be anywhere in message now */   gchar *notifypos;   gchar *caps_header, *caps_message,    /* temps for ascii_strup() versions of each */         *caps_notify;                   /* since Jabber mucks with case             */   gchar *unescaped_message;             /* temps for html_unescaped       */                                         /* since ICQ will now escape HTML */   int header_size, footer_size;   const gchar* header = g_hash_table_lookup(header_table, gaim_account_get_protocol_id(acct));   const gchar* footer = g_hash_table_lookup(footer_table, gaim_account_get_protocol_id(acct));   const gchar* notify = g_hash_table_lookup(notify_table, gaim_account_get_protocol_id(acct));   if (!header) header = header_default;   if (!footer) footer = "";   header_size = strlen(header);   footer_size = strlen(footer);   /* Since we don't have a periodic callback, we do some housekeeping here */   gaim_conversation_foreach(reap_old_sent_messages);   conv = gaim_find_conversation_with_account(*who, acct);   gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "Finding conversation: %s, %p\n", *who, conv);      name = g_strdup(gaim_normalize(acct, *who));      if (*message != NULL) {      caps_message = g_ascii_strup(*message, -1);      caps_header = g_ascii_strup(header, -1);      unescaped_message = gaim_unescape_html(*message);      headerpos = strstr(caps_message, caps_header);      g_free(caps_header);      if (notify) {         caps_notify = g_ascii_strup(notify, -1);         notifypos = strstr(caps_message, caps_notify);         g_free(caps_notify);      } else {         notifypos = 0;      }      if (headerpos != 0) {         /* adjust to where the header is in the _real_ message, if */         /* we found it in the caps_message                         */         headerpos += (*message) - caps_message;      }      g_free(caps_message);      if (headerpos == 0 && notifypos == 0) {         /* Check for ICQ-escaped header*/         headerpos = strstr(unescaped_message, header);         if (notify) {            notifypos = strstr(unescaped_message, notify);         }         if (headerpos != 0 || notifypos != 0) {            /* ICQ PRPL escaped our HTML header, but we outsmarted it     */            /* replace message with unescaped message.                    */            gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "Escaped header: replacing %s with %s\n",                       *message, unescaped_message);            g_free(*message);            *message = unescaped_message;         } else {            g_free(unescaped_message);         }      }      /* Whew.  Enough of this header-finding.  */            if (headerpos != 0) {         GE_set_capable(acct, name, TRUE);         if (gaim_prefs_get_bool("/plugins/gtk/encrypt/encrypt_response")) {            GE_set_tx_encryption(acct, name, TRUE);         }         if (strncmp(headerpos + header_size, ": Send Key",                     sizeof(": Send Key")-1) == 0) {            GE_send_key(acct, name, 0, 0);            (*message)[0] = 0;            g_free(*message);            *message = NULL;            gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "Sent key per request\n");         } else if (strncmp(headerpos + header_size, ": Key",                            sizeof(": Key") - 1) == 0) {            gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "Got key\n");            GE_received_key(headerpos + header_size + sizeof(": Key") - 1, name, acct,                            conv, message);         } else if (strncmp(headerpos + header_size, ": ErrKey",                            sizeof(": ErrKey") - 1) == 0) {            gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "Got key in response to error\n");            gaim_conversation_write(conv, 0,                                    _("Last outgoing message not received properly- resetting"),                                    GAIM_MESSAGE_SYSTEM, time((time_t)NULL));            gaim_conv_window_flash(gaim_conversation_get_window(conv));            GE_received_key(headerpos + header_size + sizeof(": ErrKey") - 1, name, acct,                            conv, message);         } else if (strncmp(headerpos + header_size, ": Msg",                            sizeof(": Msg") - 1) == 0){            gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption",                       "Got encrypted message: %d\n", strlen(*message));             gaim_debug(GAIM_DEBUG_INFO, "gaim-encryption",                       "Message is:%s:\n", *message);            memmove(*message, headerpos + header_size + sizeof(": Msg") - 1,                    strlen(headerpos + header_size + sizeof(": Msg") -1)+1);            got_encrypted_msg(acct->gc, name, message);            GE_set_rx_encryption(acct, name, TRUE);         } else {            gaim_debug(GAIM_DEBUG_ERROR, "gaim-encryption",                       "Invalid Gaim-Encryption packet type\n");          }                  } else if (notifypos != 0) {         GE_set_rx_encryption(acct, name, FALSE);         GE_set_capable(acct, name, TRUE);         if (gaim_prefs_get_bool("/plugins/gtk/encrypt/encrypt_if_notified")) {            GE_set_tx_encryption(acct, name, TRUE);         }      } else {  /* No encrypt-o-header */         GE_set_rx_encryption(acct, name, FALSE);         gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "No header: %s\n", *message);      }   }   	if (*message) {		return FALSE;	}	else {		return TRUE;	}   g_free(name);}static void got_encrypted_msg(GaimConnection *gc, const char* name, char **message){   unsigned char send_key_sum[KEY_DIGEST_LENGTH], recv_key_sum[KEY_DIGEST_LENGTH];   unsigned char *tmp_msg;   crypt_key *priv_key, *pub_key;   int msg_pos = 0;   GaimConversation* conv;   gaim_debug(GAIM_DEBUG_MISC, "gaim-encryption", "got_encrypted_msg\n");   if ( (sscanf(*message, ": S%10c: R%10c%n", send_key_sum, recv_key_sum, &msg_pos) < 2) ||        (msg_pos == 0) ) {      gaim_debug(GAIM_DEBUG_WARNING, "gaim-encryption", "Garbled msg header\n");      return;   }   priv_key = GE_find_key_by_name(GE_my_priv_ring, gc->account->username, gc->account);   pub_key = GE_get_key(gc, name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -