QString OtrInternal::encryptMessage(const QString& from, const QString& to, const QString& message, TreeModelItem &item) { QString protocol = item.m_protocol_name; char* encMessage = NULL; gcry_error_t err; err = otrl_message_sending(m_userstate, &m_uiOps, this, from.toStdString().c_str(), protocol.toStdString().c_str(), to.toStdString().c_str(), message.toUtf8().data(), NULL, &encMessage, NULL, NULL); if (err != 0) { QMessageBox mb(QMessageBox::Critical, tr("qutim-otr"), tr("Encrypting message from %1 to %2 failed.").arg(QString(from)).arg(QString(to)) + "\n" + tr("The message was not sent."), QMessageBox::Ok, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); mb.exec(); return QString(); } if (encMessage != NULL) { QString retMessage(QString::fromUtf8(encMessage)); otrl_message_free(encMessage); return retMessage; } return message; }
char* pass_otr_out_msg(uint32_t id, char* account, char* protocol, char* message) { char *new_message = NULL; gcry_error_t err; pthread_mutex_lock(&log_mutex); fprintf(logfd, "Passing to OTR message_sending %s to account %s protocol %s\n", message, account, protocol); fflush(logfd); pthread_mutex_unlock(&log_mutex); #ifdef OTR40 #ifdef FRAG40 err = otrl_message_sending(us, &ops, NULL, our_account, protocol, account, OTRL_INSTAG_BEST, message, NULL, &new_message, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, NULL, NULL); #else err = otrl_message_sending(us, &ops, NULL, our_account, protocol, account, OTRL_INSTAG_BEST, message, NULL, &new_message, OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL); #endif #endif #if defined OTR30 || defined OTR31 || defined OTR32 err = otrl_message_sending(us, &ops, NULL, our_account, protocol, account, message, NULL, &new_message, NULL, NULL); #endif if (new_message) { char *ourm = strdup(new_message); write_query_response(id, new_message); /* send modified message back */ otrl_message_free(new_message); new_message = ourm; } if (err) { /* Do not send out plain text */ char *ourm = strdup(""); new_message = ourm; } return new_message; }
static void sending(const char *from, const char *to, const char *msg) { gcry_error_t err; OtrlTLV *tlvs = NULL; char *newmsg; err = otrl_message_sending(us, &ops, NULL, from, PROTO, to, msg, tlvs, &newmsg, NULL, NULL, NULL); if (!err) { inject(from, to, newmsg ? newmsg : msg); } otrl_message_free(newmsg); otrl_tlv_free(tlvs); }
/** * Encrypt a message bevore sending. */ const char* OtrConnection::encryptMessage(const char* from, const char* to, const char* message) { char* encMessage = NULL; gcry_error_t err; err = otrl_message_sending( userstate, &ui_ops, this, from, "prpl-jabber", to, message, NULL, &encMessage, NULL, NULL); if (encMessage != NULL) { message = encMessage; } return message; }
gcry_error_t otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char *const to, const char *const message, char **newmessage) { gcry_error_t err; err = otrl_message_sending( user_state, ops, NULL, jid, "xmpp", to, message, 0, newmessage, NULL, NULL); return err; }
QString OtrInternal::encryptMessage(const QString& account, const QString& contact, const QString& message) { char* encMessage = NULL; gcry_error_t err; err = otrl_message_sending(m_userstate, &m_uiOps, this, account.toUtf8().constData(), OTR_PROTOCOL_STRING, contact.toUtf8().constData(), #if (OTRL_VERSION_MAJOR >= 4) OTRL_INSTAG_BEST, #endif message.toUtf8().constData(), NULL, &encMessage, #if (OTRL_VERSION_MAJOR >= 4) OTRL_FRAGMENT_SEND_SKIP, NULL, #endif NULL, NULL); if (err) { QString err_message = QObject::tr("Encrypting message to %1 " "failed.\nThe message was not sent.") .arg(contact); if (!m_callback->displayOtrMessage(account, contact, err_message)) { m_callback->notifyUser(account, contact, err_message, psiotr::OTR_NOTIFY_ERROR); } return QString(); } if (encMessage) { QString retMessage(QString::fromUtf8(encMessage)); otrl_message_free(encMessage); return retMessage; } return message; }
/* * Hand the given message to OTR. * * Return 0 if the message was successfully handled or else a negative value. */ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg) { gcry_error_t err; char *accname = NULL; ConnContext *ctx = NULL; assert(irssi); accname = create_account_name(irssi); if (!accname) { goto error; } IRSSI_DEBUG("Sending message..."); err = otrl_message_sending(user_state_global->otr_state, &otr_ops, irssi, accname, OTR_PROTOCOL_ID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg, OTRL_FRAGMENT_SEND_ALL_BUT_LAST, &ctx, add_peer_context_cb, irssi); if (err) { IRSSI_NOTICE(irssi, to, "Send failed."); goto error; } IRSSI_DEBUG("Message sent..."); /* Add peer context to OTR context if none exists. */ if (ctx && !ctx->app_data) { add_peer_context_cb(irssi, ctx); } free(accname); return 0; error: free(accname); return -1; }
gcry_error_t otrlib_encrypt_message(OtrlUserState user_state, OtrlMessageAppOps *ops, char *jid, const char * const to, const char * const message, char **newmessage) { gcry_error_t err; err = otrl_message_sending( user_state, ops, NULL, jid, "xmpp", to, OTRL_INSTAG_MASTER, message, 0, newmessage, OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL); return err; }
int totrEncryptMessage(int windowID, char* subwindow, char* event, void* data, void* userData) { edit_event_t* msg = reinterpret_cast<edit_event_t*>(data); TotrAppData* eopts = reinterpret_cast<TotrAppData*>(userData); char* message = NULL; char* newmessage = NULL; char* account_name = NULL; int res = -1; int connection_id = -1; ConnContext* conn = userstate->context_root; //CAtlRegExp<> reStart, reEnd; //CAtlREMatchContext<> mcStart, mcEnd; BOOL resStart = FALSE; BOOL resEnd = FALSE; if(!msg || !reinterpret_cast<char*>(msg->data) || stricmp(event, "edit_sendText") != 0 || !strlen(reinterpret_cast<char*>(msg->data)) || (reinterpret_cast<char*>(msg->data)[0]) == '/') return 0; /* Bail out of parsing any messages starting with / * Too bad we can't tell if this is a real command * or not without doing some interpretive lists. * Even then, such lists would not include other * plugins that impliment their own / commands. * * May need to exclude everything and include * /me. Unsure of that. */ while(conn) { if(conn->app_data != NULL) { TotrAppData *appdata = reinterpret_cast<TotrAppData*>(conn->app_data); if(appdata->window_id == msg->window_id) { connection_id = appdata->connection_id; break; } } conn = conn->next; } if(connection_id == -1) return 0; account_name = accountNameLookup(conn->protocol, connection_id); if(!account_name) return 0; /* Cleanse our text string of the <cursor/> tag Trillian puts in */ message = _strdup(reinterpret_cast<char*>(msg->data)); stripCursorTag(message,reinterpret_cast<char*>(msg->data)); #if 0 char *search = strstr((char *) msg->data, "<cursor/>"); if (search) { char *c = NULL, *s = NULL; size_t bufsize=strlen((char *)msg->data)-strlen("<cursor/>")+1; c = message = (char *)malloc(bufsize); ZeroMemory(c,bufsize); ZeroMemory(message,bufsize); strncpy(message, (char *)msg->data, search-((char *) msg->data)); c = c + (search - (char *) msg->data); s = search + strlen("<cursor/>"); strncpy(c, s, strlen(search)-strlen("<cursor/>")+1); } else message = _strdup(reinterpret_cast<char*>(msg->data)); #endif res = otrl_message_sending(userstate, &totr_ops, msg, account_name, conn->protocol, conn->username, message, NULL, &newmessage, totrNewContext, eopts); if(res && !newmessage) newmessage = ""; if(newmessage) { if(totr_config.GetSaveHistory()) if(!totr_config.appendHistory(message,conn->protocol,account_name,conn->username)) MessageBox(NULL,"Could not save history","ERROR",MB_OK); // Added by Thisita 10/22/11 message_t msg2; message_options_t mopts; edit_event_t eet; int psres = -1; trillianInitialize(msg2); trillianInitialize(eet); memset(&mopts, -1, sizeof(mopts)); mopts.struct_size = sizeof(mopts); mopts.disable_message = mopts.logging_name = mopts.echo_name = NULL; mopts.nicklist = NULL; reinterpret_cast<TotrAppData*>(conn->app_data)->last_msg = _strdup(reinterpret_cast<char*>(msg->data)); reinterpret_cast<TotrAppData*>(conn->app_data)->last_msg_len = strlen(reinterpret_cast<char*>(msg->data)) + 1; eet.window_id = msg->window_id; eet.event = "edit_setText"; if(strlen(newmessage) != 0) { msg2.connection_id = connection_id; msg2.window_id = msg->window_id; msg2.name = conn->username; msg2.medium = conn->protocol; msg2.text = ""; //msg2.text = _strdup(newmessage); msg2.text_len = static_cast<int>(strlen(newmessage) + 1); // Change proposed by Thisita 10/20/11 msg2.type = "outgoing_privateMessage"; msg2.extra_information = &mopts; msg2.extra_information_size = mopts.struct_size; eet.data = newmessage; OutputDebugString("sent "); OutputDebugString(newmessage); if(otrl_proto_message_type(newmessage) != OTRL_MSGTYPE_TAGGEDPLAINTEXT) { messageWindowEchostate(&msg2, 1); psres = plugin_send(MYGUID, "editEventSend", &eet); msg2.type="outgoing_privateMessage"; msg2.text = message; //<HTML><BODY BGCOLOR=\"#ffffff\">greets</BODY></HTML>"; plugin_send(MYGUID, "messageReceive", &msg2); } } } otrl_message_free(newmessage); free(account_name); account_name = NULL; return 0; }
int main(){ OTRL_INIT; OtrlUserState userstate; char *newmessage = NULL; char *nlmsg=NULL; OtrlMessageAppOps ui_ops; int sockfd, clientfd, recvbytes, recv_ret; socklen_t sin_size; char buf[1024], pwdbuf[1024]; char *dbuf; struct sockaddr_in remote_addr, my_addr; fd_set fds; int one = 1; /* initialize ui callbacks */ memset(&ui_ops, 0, sizeof(OtrlMessageAppOps)); ui_ops.inject_message= inject_msg; ui_ops.gone_secure=gone_secure; printf("\033[31mStarting driver...\033[0m\n"); /* initialize socket connection */ sockfd = socket(AF_INET, SOCK_STREAM, 0); my_addr.sin_family=AF_INET; my_addr.sin_port= htons(3333); my_addr.sin_addr.s_addr = INADDR_ANY; bzero(&(my_addr.sin_zero),8); /* Allow rebinding to address */ setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) { perror("bind"); exit(1); } if (listen(sockfd, 1) == -1) { perror("listen"); exit(1); } sin_size = sizeof(struct sockaddr_in); if ((clientfd = accept(sockfd, (struct sockaddr *)&remote_addr, \ &sin_size)) == -1) { perror("accept"); } printf("\033[31mConnected to Bob\033[0m\n"); /* create userstate, and read the private key */ userstate = otrl_userstate_create(); getcwd(pwdbuf, 1024); strcat(pwdbuf, "/private_key"); otrl_privkey_read(userstate, pwdbuf); /* Clients send messages asynchronously*/ while(1){ FD_ZERO(&fds); FD_SET(0, &fds); FD_SET(clientfd, &fds); select(clientfd+1, &fds, NULL, NULL, NULL); if(FD_ISSET(0, &fds)){ /* send message */ fgets(buf, 1023, stdin); buf[strlen(buf)-1]= '\0'; printf("\033[31mTo OTR:%d:\033[0m%s\n\033[0m",strlen(buf), buf); dbuf = strdup(buf); otrl_message_sending(userstate, &ui_ops, NULL, "*****@*****.**", "msn", "*****@*****.**", &dbuf, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL, NULL); free(dbuf); nlmsg = (char*)malloc(strlen(newmessage)+2); memcpy(nlmsg, newmessage, strlen(newmessage)); nlmsg[strlen(newmessage)]='\n'; nlmsg[strlen(newmessage)+1]='\0'; send(clientfd, nlmsg, strlen(nlmsg), 0); printf("\033[31mTo network:%d:\033[35m%s\033[0m\n\033[0m", strlen(newmessage), newmessage); }else{ /*receive message */ recvbytes=recv(clientfd, buf, MAXDATASIZE, 0); if(recvbytes==0) break; recvbytes--; buf[recvbytes] = '\0'; if(buf[recvbytes-1]=='\r'){ recvbytes--; buf[recvbytes]='\0'; } printf("\033[31mFrom network:%d:\033[35m %s\033[0m\n",recvbytes, buf); recv_ret=otrl_message_receiving(userstate, &ui_ops, &clientfd, "*****@*****.**", "msn", "*****@*****.**", buf, &newmessage, NULL, NULL, NULL, NULL, NULL); if(recv_ret==0) printf("\033[31mFrom OTR:%d:\033[0m %s\n", newmessage ? strlen(newmessage) : 0, newmessage); } } return 0; }