int GaduSession::sendMessage( uin_t recipient, const Kopete::Message& msg, int msgClass ) { QString sendMsg; QCString cpMsg; KGaduMessage* gadumessage; if ( isConnected() ) { gadumessage = rtf->convertToGaduMessage( msg ); if ( gadumessage ) { const void* data = (const void*)gadumessage->rtf.data(); cpMsg = textcodec->fromUnicode( gadumessage->message ); int o; o = gg_send_message_richtext( session_, msgClass, recipient, (const unsigned char *)cpMsg.data(), (const unsigned char*) data, gadumessage->rtf.size() ); gadumessage->rtf.resize(0); delete gadumessage; return o; } else { sendMsg = msg.plainBody(); sendMsg.replace( QString::fromAscii( "\n" ), QString::fromAscii( "\r\n" ) ); cpMsg = textcodec->fromUnicode( sendMsg ); return gg_send_message( session_, msgClass, recipient, (const unsigned char *)cpMsg.data() ); } } else { emit error( i18n("Not Connected"), i18n("You are not connected to the server.") ); } return 1; }
int GGPROTO::SendMsg(MCONTACT hContact, int, const char *msg) { uin_t uin = (uin_t)getDword(hContact, GG_KEY_UIN, 0); if (!isonline() || !uin) return 0; if (!msg) return 0; gg_EnterCriticalSection(&sess_mutex, "SendMsg", 53, "sess_mutex", 1); int seq = gg_send_message(sess, GG_CLASS_CHAT, uin, (BYTE*)msg); gg_LeaveCriticalSection(&sess_mutex, "SendMsg", 53, 1, "sess_mutex", 1); if (!getByte(GG_KEY_MSGACK, GG_KEYDEF_MSGACK)) { // Auto-ack message without waiting for server ack GG_SEQ_ACK *ack = (GG_SEQ_ACK*)mir_alloc(sizeof(GG_SEQ_ACK)); if (ack) { ack->seq = seq; ack->hContact = hContact; #ifdef DEBUGMODE debugLogA("SendMsg(): ForkThread 16 GGPROTO::sendackthread"); #endif ForkThread(&GGPROTO::sendackthread, ack); } } return seq; }
gboolean gnomegadu_protocol_send_message (gchar * uin_str, gchar *msg) { gchar *msg_windows1250 = g_convert (msg, strlen (msg), "WINDOWS-1250", "UTF-8", NULL, NULL, NULL); if (!gnomegadu_protocol_check_connected()) return FALSE; if (gg_send_message(gnomegadu_gadugadu_session, GG_CLASS_CHAT, g_ascii_strtod (uin_str, NULL), msg_windows1250) == -1) return FALSE; g_free(msg_windows1250); return TRUE; }
int ggp_message_send_im(PurpleConnection *gc, const char *who, const char *message, PurpleMessageFlags flags) { GGPInfo *info = purple_connection_get_protocol_data(gc); PurpleIMConversation *im; ggp_buddy_data *buddy_data; gchar *gg_msg; gboolean succ; /* TODO: return -ENOTCONN, if not connected */ if (message == NULL || message[0] == '\0') return 0; buddy_data = ggp_buddy_get_data(purple_blist_find_buddy( purple_connection_get_account(gc), who)); if (buddy_data->blocked) return -1; im = purple_conversations_find_im_with_account( who, purple_connection_get_account(gc)); gg_msg = ggp_message_format_to_gg(PURPLE_CONVERSATION(im), message); /* TODO: splitting messages */ if (strlen(gg_msg) > GG_MSG_MAXSIZE) { g_free(gg_msg); return -E2BIG; } #if GGP_ENABLE_GG11 succ = (gg_send_message_html(info->session, GG_CLASS_CHAT, ggp_str_to_uin(who), (unsigned char *)gg_msg) >= 0); #else { gchar *plain = purple_markup_strip_html(gg_msg); succ = (gg_send_message(info->session, GG_CLASS_CHAT, ggp_str_to_uin(who), (unsigned char *)plain) >= 0); g_free(plain); } #endif g_free(gg_msg); return succ ? 1 : -1; }
int session_send_message(Session *s,uin_t uin,int chat,const char *body){ const char *m; unsigned char *mp; g_assert(s!=NULL); if (!s->connected || !s->ggs) return -1; m=body; while(m){ mp=(unsigned char *)session_split_message(&m); if (mp){ gg_messages_out++; gg_send_message(s->ggs,chat?GG_CLASS_CHAT:GG_CLASS_MSG,uin, (const unsigned char *)mp); g_free(mp); } } return 0; /* FIXME: check for errors */ }
int GGPROTO::SendMsg(HANDLE hContact, int flags, const char *msg) { uin_t uin = (uin_t)getDword(hContact, GG_KEY_UIN, 0); if (!isonline() || !uin) return 0; char* msg_utf8; if (flags & PREF_UNICODE) msg_utf8 = mir_utf8encodeW((wchar_t*)&msg[ strlen( msg )+1 ] ); else if (flags & PREF_UTF) msg_utf8 = mir_strdup(msg); else msg_utf8 = mir_utf8encode(msg); if (!msg_utf8) return 0; gg_EnterCriticalSection(&sess_mutex, "SendMsg", 53, "sess_mutex", 1); int seq = gg_send_message(sess, GG_CLASS_CHAT, uin, (BYTE*)msg_utf8); gg_LeaveCriticalSection(&sess_mutex, "SendMsg", 53, 1, "sess_mutex", 1); if (!getByte(GG_KEY_MSGACK, GG_KEYDEF_MSGACK)) { // Auto-ack message without waiting for server ack GG_SEQ_ACK *ack = (GG_SEQ_ACK*)mir_alloc(sizeof(GG_SEQ_ACK)); if (ack) { ack->seq = seq; ack->hContact = hContact; #ifdef DEBUGMODE debugLogA("SendMsg(): ForkThread 16 GGPROTO::sendackthread"); #endif ForkThread(&GGPROTO::sendackthread, ack); } } mir_free(msg_utf8); return seq; }
void GGWrapper::processMessageEvent(ggMessageEvent &event) { Logger::log(std::string("Sending message") + event.msg.c_str()); gg_send_message(mpSession,GG_CLASS_MSG,event.uin,(unsigned char*)event.msg.c_str()); }
void reload(GLOBAL *g, struct ggnotify_module *n) { QueryHandle *res, *result; char *message = 0; int i, j; double balance; struct gg_session *sess; struct gg_login_params p; memset(&p, 0, sizeof(p)); p.uin = n->uin; p.password = n->passwd; // Najpierw po³±czmy siê z serwerem GG if( !(sess = gg_login(&p)) ) { syslog(LOG_ERR, "[%s/ggnotify] Unable to connect to Gadu-Gadu server.", n->base.instance); gg_free_session(sess); } else { #ifdef DEBUG1 syslog(LOG_INFO, "DEBUG: [%s/ggnotify] Connected to Gadu-Gadu server.",n->base.instance); #endif res = g->db_query(g->conn, "SELECT customers.id AS id, pin, name, lastname, " "SUM(cash.value) AS balance, imessengers.uid AS im " "FROM customers " "LEFT JOIN imessengers ON customers.id = imessengers.customerid " "LEFT JOIN cash ON customers.id = cash.customerid " "WHERE deleted = 0 AND imessengers.type = 0 " "GROUP BY customers.id, imessengers.uid, pin, name, lastname"); if( g->db_nrows(res) ) { for(i=0; i<g->db_nrows(res); i++) { if( atoi(g->db_get_data(res,i,"im")) ) { balance = atof(g->db_get_data(res,i,"balance")); if( balance < n->limit ) { message = load_file(n->ggtemplate); if( message ) { if( strstr(message, "%last_10_in_a_table") ) { char *date, *value, *comment, *last_ten, *temp, *temp2; last_ten = strdup(""); result = g->db_pquery(g->conn, "SELECT value, comment, time FROM cash WHERE customerid = ? ORDER BY time DESC LIMIT 10", g->db_get_data(res,i,"id")); for(j=0; j<g->db_nrows(result); j++) { date = utoc(atof(g->db_get_data(result,j,"time"))); value = g->db_get_data(result,j,"value"); comment = g->db_get_data(result,j,"comment"); temp = (char *) malloc(strlen(date)+strlen(value)+strlen(comment)+12); sprintf(temp, "%s\t | %s\t\t | %s\n", date, value, comment); temp2 = g->str_concat(last_ten, temp); free(last_ten); last_ten = strdup(temp2); free(temp2); free(temp); free(date); } g->str_replace(&message, "%last_10_in_a_table", last_ten); g->db_free(&result); free(last_ten); } g->str_replace(&message, "%saldo", g->db_get_data(res,i,"balance")); g->str_replace(&message, "%B", g->db_get_data(res,i,"balance")); g->str_replace(&message, "%b", balance < 0 ? ftoa(balance * -1) : g->db_get_data(res,i,"balance")); g->str_replace(&message, "%pin", g->db_get_data(res,i,"pin")); g->str_replace(&message, "%name", g->db_get_data(res,i,"name")); g->str_replace(&message, "%lastname", g->db_get_data(res,i,"lastname")); // Konwersja na windows g->str_replace(&message, "\n", "\n\r"); g->str_replace(&message, "\xA1", "\xA5"); g->str_replace(&message, "\xA6", "\x8C"); g->str_replace(&message, "\xAC", "\x8F"); g->str_replace(&message, "\xB1", "\xB9"); g->str_replace(&message, "\xB6", "\x9C"); g->str_replace(&message, "\xBC", "\x9F"); if( n->debuguin ) { if (gg_send_message(sess, GG_CLASS_MSG, n->debuguin, message ) == -1) { syslog(LOG_INFO, "DEBUG: [%s/ggnotify] Connection broken..",n->base.instance); gg_free_session(sess); } } else { if (gg_send_message(sess, GG_CLASS_MSG, atoi(g->db_get_data(res,i,"im")), message) == -1) { syslog(LOG_INFO, "DEBUG: [%s/ggnotify] Connection broken..",n->base.instance); gg_free_session(sess); } } free(message); } } } } } else syslog(LOG_ERR, "[%s/ggnotify] Unable to read database", n->base.instance); g->db_free(&res); gg_logoff(sess); gg_free_session(sess); #ifdef DEBUG1 syslog(LOG_INFO, "DEBUG: [%s/ggnotify] reloaded",n->base.instance); #endif } free(n->passwd); free(n->ggtemplate); }