Ticket #1150: otr_info-2015010800.patch
File otr_info-2015010800.patch, 6.6 KB (added by , at 2015-01-08T02:43:53Z) |
---|
-
otr.c
a b int otr_update_modeflags(irc_t *irc, irc_user_t *u); 192 192 /* show general info about the OTR subsystem; called by 'otr info' */ 193 193 void show_general_otr_info(irc_t *irc); 194 194 195 /* show info about a given OTR context */ 196 void show_otr_context_info(irc_t *irc, ConnContext *ctx); 195 /* show info about a given OTR context and subcontexts/instances. bestctx 196 may be either NULL or preferred destination context (this is hilighted 197 in the output as being the target for a message) */ 198 void show_otr_context_info(irc_t *irc, ConnContext *ctx, ConnContext *bestctx); 197 199 198 200 /* show the list of fingerprints associated with a given context */ 199 201 void show_fingerprints(irc_t *irc, ConnContext *ctx); … … void cmd_otr_info(irc_t *irc, char **args) 1070 1072 } else { 1071 1073 char *arg = g_strdup(args[1]); 1072 1074 char *myhandle, *handle=NULL, *protocol; 1073 ConnContext * ctx;1075 ConnContext *bestctx=NULL, *ctx; 1074 1076 1075 1077 /* interpret arg as 'user/protocol/account' if possible */ 1076 1078 protocol = strchr(arg, '/'); … … void cmd_otr_info(irc_t *irc, char **args) 1102 1104 g_free(arg); 1103 1105 return; 1104 1106 } 1107 /* This does no harm if it returns NULL */ 1108 bestctx = otrl_context_find(irc->otr->us, u->bu->handle, u->bu->ic->acc->user, 1109 u->bu->ic->acc->prpl->name, OTRL_INSTAG_BEST, 0, NULL, NULL, NULL); 1105 1110 } 1106 1111 1107 1112 /* show how we resolved the (nick) argument, if we did */ 1108 1113 if(handle!=arg) { 1109 irc_rootmsg(irc, "%s is %s/%s; we are %s/%s to them", args[1], 1110 ctx->username, ctx->protocol, ctx->accountname, ctx->protocol); 1114 irc_rootmsg(irc, "%s:", args[1]); 1115 irc_rootmsg(irc, " they are: %s/%s", ctx->username, ctx->protocol); 1116 irc_rootmsg(irc, " we are: %s/%s", ctx->accountname, ctx->protocol); 1111 1117 } 1112 show_otr_context_info(irc, ctx );1118 show_otr_context_info(irc, ctx, bestctx); 1113 1119 g_free(arg); 1114 1120 } 1115 1121 } … … void show_fingerprints(irc_t *irc, ConnContext *ctx) 1523 1529 const char *trust; 1524 1530 int count=0; 1525 1531 1526 for(fp=&ctx->fingerprint_root; fp; fp=fp->next) { 1527 if(!fp->fingerprint) 1532 /* Is this a subcontext? If so, only list the active fingerprint */ 1533 if(ctx->m_context != ctx) { 1534 fp = ctx->active_fingerprint; 1535 } else { 1536 fp = &ctx->fingerprint_root; 1537 } 1538 1539 while(fp) { 1540 if(!fp->fingerprint) { 1541 fp = fp->next; 1528 1542 continue; 1543 } 1529 1544 count++; 1530 1545 otrl_privkey_hash_to_human(human, fp->fingerprint); 1531 1546 if(!fp->trust || fp->trust[0] == '\0') { … … void show_fingerprints(irc_t *irc, ConnContext *ctx) 1534 1549 trust=fp->trust; 1535 1550 } 1536 1551 if(fp == ctx->active_fingerprint) { 1537 irc_rootmsg(irc, " \x02%s (%s)\x02", human, trust);1552 irc_rootmsg(irc, " \x02%s (%s)\x02", human, trust); 1538 1553 } else { 1539 irc_rootmsg(irc, " %s (%s)", human, trust);1554 irc_rootmsg(irc, " %s (%s)", human, trust); 1540 1555 } 1556 1557 /* Break if this is a subcontext - we only print active fp */ 1558 if (ctx->m_context != ctx) 1559 break; 1560 fp = fp->next; 1541 1561 } 1542 1562 if(count==0) 1543 irc_rootmsg(irc, " (none)");1563 irc_rootmsg(irc, " (none)"); 1544 1564 } 1545 1565 1546 1566 Fingerprint *match_fingerprint(irc_t *irc, ConnContext *ctx, const char **args) … … void show_general_otr_info(irc_t *irc) 1715 1735 1716 1736 /* list all contexts */ 1717 1737 /* XXX remove this, or split off as its own command */ 1718 /* XXX show instags? */1719 1738 irc_rootmsg(irc, "%s", ""); 1720 1739 irc_rootmsg(irc, "\x1f" "connection contexts:\x1f (bold=currently encrypted)"); 1721 for(ctx=irc->otr->us->context_root; ctx; ctx=ctx->next) {\ 1740 1741 ctx=irc->otr->us->context_root; 1742 while(ctx) { 1743 ConnContext *subctx; 1722 1744 irc_user_t *u; 1723 1745 char *userstring; 1746 char encrypted=0; 1724 1747 1725 1748 u = peeruser(irc, ctx->username, ctx->protocol); 1726 1749 if(u) … … void show_general_otr_info(irc_t *irc) 1729 1752 else 1730 1753 userstring = g_strdup_printf("%s/%s/%s", 1731 1754 ctx->username, ctx->protocol, ctx->accountname); 1732 1733 if(ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 1755 1756 subctx = ctx; 1757 while(subctx && subctx->m_context == ctx) { 1758 if(subctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) 1759 encrypted = 1; 1760 subctx = subctx->next; 1761 } 1762 1763 if(encrypted) { 1734 1764 irc_rootmsg(irc, " \x02%s\x02", userstring); 1735 1765 } else { 1736 1766 irc_rootmsg(irc, " %s", userstring); 1737 1767 } 1768 1769 /* Skip subcontexts/instances from output */ 1770 ctx = subctx; 1738 1771 1739 1772 g_free(userstring); 1740 1773 } 1774 1741 1775 if(ctx == irc->otr->us->context_root) 1742 1776 irc_rootmsg(irc, " (none)"); 1743 1777 } 1744 1778 1745 void show_otr_context_info(irc_t *irc, ConnContext *ctx )1779 void show_otr_context_info(irc_t *irc, ConnContext *ctx, ConnContext *bestctx) 1746 1780 { 1747 // XXX show all instags/subcontexts 1781 ConnContext *subctx; 1782 int instcount=0; 1748 1783 1749 switch(ctx->otr_offer) { 1750 case OFFER_NOT: 1751 irc_rootmsg(irc, " otr offer status: none sent"); 1752 break; 1753 case OFFER_SENT: 1754 irc_rootmsg(irc, " otr offer status: awaiting reply"); 1755 break; 1756 case OFFER_ACCEPTED: 1757 irc_rootmsg(irc, " otr offer status: accepted our offer"); 1758 break; 1759 case OFFER_REJECTED: 1760 irc_rootmsg(irc, " otr offer status: ignored our offer"); 1761 break; 1762 default: 1763 irc_rootmsg(irc, " otr offer status: %d", ctx->otr_offer); 1764 } 1784 subctx = ctx; 1785 while(subctx && subctx->m_context == ctx) { 1786 if(subctx->m_context == subctx) { 1787 if(subctx == bestctx) { 1788 irc_rootmsg(irc, " \x02master context (target):\x02"); 1789 } else { 1790 irc_rootmsg(irc, " master context:"); 1791 } 1792 irc_rootmsg(irc, " known fingerprints (bold = active for v1 or v2):"); 1793 } else { 1794 if(subctx == bestctx) { 1795 irc_rootmsg(irc, " \x02instance %d (target):\x02", instcount); 1796 } else { 1797 irc_rootmsg(irc, " instance %d:", instcount); 1798 } 1799 irc_rootmsg(irc, " active fingerprint:"); 1800 instcount++; 1801 } 1765 1802 1766 switch(ctx->msgstate) { 1767 case OTRL_MSGSTATE_PLAINTEXT: 1768 irc_rootmsg(irc, " connection state: cleartext"); 1769 break; 1770 case OTRL_MSGSTATE_ENCRYPTED: 1771 irc_rootmsg(irc, " connection state: encrypted (v%d)", ctx->protocol_version); 1772 break; 1773 case OTRL_MSGSTATE_FINISHED: 1774 irc_rootmsg(irc, " connection state: shut down"); 1775 break; 1776 default: 1777 irc_rootmsg(irc, " connection state: %d", ctx->msgstate); 1778 } 1803 show_fingerprints(irc, subctx); 1804 1805 switch(subctx->msgstate) { 1806 case OTRL_MSGSTATE_PLAINTEXT: 1807 irc_rootmsg(irc, " connection state: cleartext"); 1808 break; 1809 case OTRL_MSGSTATE_ENCRYPTED: 1810 irc_rootmsg(irc, " connection state: encrypted (v%d)", subctx->protocol_version); 1811 break; 1812 case OTRL_MSGSTATE_FINISHED: 1813 irc_rootmsg(irc, " connection state: shut down"); 1814 break; 1815 default: 1816 irc_rootmsg(irc, " connection state: %d", subctx->msgstate); 1817 } 1779 1818 1780 irc_rootmsg(irc, " fingerprints: (bold=active)");1781 show_fingerprints(irc, ctx);1819 subctx = subctx->next; 1820 } 1782 1821 } 1783 1822 1784 1823 int keygen_in_progress(irc_t *irc, const char *handle, const char *protocol)