示例#1
0
static void tgprpl_remove_buddy (PurpleConnection * gc, PurpleBuddy * buddy, PurpleGroup * group) {
  debug ("tgprpl_remove_buddy()\n");
  if (!buddy) { return; }
  
  telegram_conn *conn = purple_connection_get_protocol_data (gc);
  struct tgl_user *user = purple_buddy_get_protocol_data (buddy);
  if (!user) { warning ("cannot remove buddy '%s', no protocol data found\n", buddy->name); return; }
  
  tgl_do_del_contact (conn->TLS, user->id, NULL, NULL);
}
示例#2
0
void py_do_all (void) {
    int p = 0;
    while (p < pos) {
        assert (p + 2 <= pos);

        enum py_query_type f = (long)py_ptr[p ++];
        PyObject *args = (PyObject *)py_ptr[p ++];

        const char *str, *str1, *str2, *str3;

        Py_ssize_t i;
        tgl_user_id_t *ids;

        int len, len1, len2, len3;
        int limit, offset;
        long msg_id = 0;
        PyObject *pyObj1 = NULL;
        PyObject *pyObj2 = NULL;
        PyObject *cb_extra = NULL;

        PyObject *peer = NULL;
        PyObject *peer1 = NULL;

        switch (f) {
        case pq_contact_list:
            if(PyArg_ParseTuple(args, "|O", &cb_extra))
                tgl_do_update_contact_list (TLS, py_contact_list_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_dialog_list:
            if(PyArg_ParseTuple(args, "|O", &cb_extra))
                tgl_do_get_dialog_list (TLS, 100, 0, py_dialog_list_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_msg:
            if(PyArg_ParseTuple(args, "O!s#|O", &tgl_PeerType, &peer, &str, &len, &cb_extra))
                tgl_do_send_message (TLS, PY_PEER_ID(peer), str, len, 0, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_typing:
            if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra))
                tgl_do_send_typing (TLS, PY_PEER_ID(peer), tgl_typing_typing, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_typing_abort:
            if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra))
                tgl_do_send_typing (TLS, PY_PEER_ID(peer), tgl_typing_cancel, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_rename_chat:
            if(PyArg_ParseTuple(args, "O!s#|O", &tgl_PeerType, &peer, &str, &len, &cb_extra))
                tgl_do_rename_chat (TLS, PY_PEER_ID(peer), str, len, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_photo:
            if(PyArg_ParseTuple(args, "O!s|O", &tgl_PeerType, &peer, &str, &cb_extra))
                tgl_do_send_document (TLS, PY_PEER_ID(peer), str, NULL, 0, TGL_SEND_MSG_FLAG_DOCUMENT_PHOTO, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_video:
            if(PyArg_ParseTuple(args, "O!s|O", &tgl_PeerType, &peer, &str, &cb_extra))
                tgl_do_send_document (TLS, PY_PEER_ID(peer), str, NULL, 0, TGL_SEND_MSG_FLAG_DOCUMENT_VIDEO, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_audio:
            if(PyArg_ParseTuple(args, "O!s|O", &tgl_PeerType, &peer, &str, &cb_extra))
                tgl_do_send_document (TLS, PY_PEER_ID(peer), str, NULL, 0, TGL_SEND_MSG_FLAG_DOCUMENT_AUDIO, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_document:
            if(PyArg_ParseTuple(args, "O!s|O", &tgl_PeerType, &peer, &str, &cb_extra))
                tgl_do_send_document (TLS, PY_PEER_ID(peer), str, NULL, 0, 0, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_file:
            if(PyArg_ParseTuple(args, "O!s|O", &tgl_PeerType, &peer, &str, &cb_extra))
                tgl_do_send_document (TLS, PY_PEER_ID(peer), str, NULL, 0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_text:
            if(PyArg_ParseTuple(args, "O!s|O", &tgl_PeerType, &peer, &str, &cb_extra))
                tgl_do_send_text (TLS, PY_PEER_ID(peer), str, 0, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_chat_set_photo:
            if(PyArg_ParseTuple(args, "O!s|O", &tgl_PeerType, &peer, &str, &cb_extra))
                tgl_do_set_chat_photo (TLS, PY_PEER_ID(peer), str, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        /*  case pq_load_photo:
            case pq_load_video:
            case pq_load_audio:
            case pq_load_document:
              M = py_ptr[p + 1];
              if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_photo_encr && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) {
                py_file_cb (TLS, py_ptr[p], 0, 0);
              } else {
                , limit, offse, limit, offsettif (M->media.type == tgl_message_media_photo) {
                  tgl_do_load_photo (TLS, &M->media.photo, py_file_cb, py_ptr[p]);
                } else if (M->media.type == tgl_message_media_document) {
                  tgl_do_load_document (TLS, &M->media.document, py_file_cb, py_ptr[p]);
                } else {
                  tgl_do_load_encr_document (TLS, &M->media.encr_document, py_file_cb, py_ptr[p]);
                }
              }
              break;
            case pq_load_video_thumb:
            case pq_load_document_thumb:
              M = py_ptr[p + 1];
              if (!M || (M->media.type != tgl_message_media_document)) {
                py_file_cb (TLS, py_ptr[p], 0, 0);
              } else {
                tgl_do_load_document_thumb (TLS, &M->media.document, py_file_cb, py_ptr[p]);
              }
              break;
        */
        case pq_fwd:
            if(PyArg_ParseTuple(args, "O!l|O", &tgl_PeerType, &peer, &msg_id, &cb_extra))
                tgl_do_forward_message (TLS, PY_PEER_ID(peer), msg_id, 0, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_fwd_media:
            if(PyArg_ParseTuple(args, "O!l|O", &tgl_PeerType, &peer, &msg_id, &cb_extra))
                tgl_do_forward_media (TLS, PY_PEER_ID(peer), msg_id, 0, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_chat_info:
            if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra))
                tgl_do_get_chat_info (TLS, PY_PEER_ID(peer), 0, py_chat_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_user_info:
            if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra))
                tgl_do_get_user_info (TLS, PY_PEER_ID(peer), 0, py_user_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_history:
            if(PyArg_ParseTuple(args, "O!ii|O", &tgl_PeerType, &peer, &offset, &limit, &cb_extra))
                tgl_do_get_history (TLS, PY_PEER_ID(peer), offset, limit, 0, py_msg_list_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_chat_add_user:
            if(PyArg_ParseTuple(args, "O!O!|O", &tgl_PeerType, &peer, &tgl_PeerType, &peer1, &cb_extra))
                tgl_do_add_user_to_chat (TLS, PY_PEER_ID(peer), PY_PEER_ID(peer1), 100, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_chat_del_user:
            if(PyArg_ParseTuple(args, "O!O!|O", &tgl_PeerType, &peer, &tgl_PeerType, &peer1, &cb_extra))
                tgl_do_del_user_from_chat (TLS, PY_PEER_ID(peer), PY_PEER_ID(peer1), py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_add_contact:
            if(PyArg_ParseTuple(args, "s#s#s#|O", &str1, &len1, &str2, &len2, &str3, &len3, &cb_extra))
                tgl_do_add_contact (TLS, str1, len1, str2, len2, str3, len3, 0, py_contact_list_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_del_contact:
            if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra))
                tgl_do_del_contact (TLS, PY_PEER_ID(peer), py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_rename_contact:
            if(PyArg_ParseTuple(args, "s#s#s#|O", &str1, &len1, &str2, &len2, &str3, &len3, &cb_extra))
                tgl_do_add_contact (TLS, str1, len1, str2, len2, str3, len3, 1, py_contact_list_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_search:
            if(PyArg_ParseTuple(args, "O!s#|O", &tgl_PeerType, &peer, &str, &len, &cb_extra))
                tgl_do_msg_search (TLS, PY_PEER_ID(peer), 0, 0, 40, 0, str, len, py_msg_list_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_global_search:
            if(PyArg_ParseTuple(args, "s#|O", &str, &len, &cb_extra))
                tgl_do_msg_search (TLS, tgl_set_peer_id (TGL_PEER_UNKNOWN, 0), 0, 0, 40, 0, str, len, py_msg_list_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_mark_read:
            if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra))
                tgl_do_mark_read (TLS, PY_PEER_ID(peer), py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_set_profile_photo:
            if(PyArg_ParseTuple(args, "s|O", &str, &cb_extra))
                tgl_do_set_profile_photo (TLS, str, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_set_profile_name:
            if(PyArg_ParseTuple(args, "s#s#|O", &str1, &len1, &str2, &len2, &cb_extra))
                tgl_do_set_profile_name (TLS, str1, len1, str2, len2, py_user_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_create_secret_chat:
            if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra))
                tgl_do_create_secret_chat (TLS, PY_PEER_ID(peer), py_secret_chat_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_create_group_chat:
            if(PyArg_ParseTuple(args, "O!s#|O", &PyList_Type, &pyObj1, &str, &len, &cb_extra)) {
                if(PyList_GET_SIZE(pyObj1) > 2) {
                    ids = (tgl_user_id_t *)malloc(PyList_GET_SIZE(pyObj1) * sizeof(tgl_user_id_t));
                    for(i = 0; i < PyList_GET_SIZE(pyObj1); i++) {
                        peer = PyList_GetItem(pyObj1, i);
                        *(ids+i) = PY_PEER_ID(peer);
                    }
                    tgl_do_create_group_chat (TLS, PyList_GET_SIZE(pyObj1), ids, str, len, py_empty_cb, cb_extra);

                    tfree(ids, PyList_GET_SIZE(pyObj1) * sizeof(tgl_user_id_t));
                } else {
                    logprintf("create_group_chat: Argument 1 must be a list of at least 3 peers");
                }
            }
            Py_XDECREF(pyObj1);
            break;
        case pq_delete_msg:
        case pq_restore_msg:
            if(PyArg_ParseTuple(args, "l|O", &msg_id, &cb_extra))
                tgl_do_delete_msg (TLS, msg_id, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        /*
            case pq_accept_secret_chat:
              tgl_do_accept_encr_chat_request (TLS, py_ptr[p + 1], py_secret_chat_cb, py_ptr[p]);
              break;
        */
        case pq_send_contact:
            if(PyArg_ParseTuple(args, "O!s#s#s#|O",  &tgl_PeerType, &peer, &str1, &len1, &str2, &len2,
                                &str3, &len3, &cb_extra))
                tgl_do_send_contact (TLS, PY_PEER_ID(peer), str1, len1, str2, len2, str3, len3, 0, py_msg_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_status_online:
            if(PyArg_ParseTuple(args, "|O", &cb_extra))
                tgl_do_update_status (TLS, 1, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_status_offline:
            if(PyArg_ParseTuple(args, "|O", &cb_extra))
                tgl_do_update_status (TLS, 0, py_empty_cb, cb_extra);
            else
                PyErr_Print();
            break;
        case pq_extf:
            if(PyArg_ParseTuple(args, "s#|O", &str, &len, &cb_extra))
                tgl_do_send_extf (TLS, str, len, py_str_cb, &cb_extra);
            else
                PyErr_Print();
            break;
        case pq_send_location:
            if(PyArg_ParseTuple(args, "O!O!O!|O", &tgl_PeerType, &peer, &PyFloat_Type, &pyObj1, &PyFloat_Type, &pyObj2, &cb_extra)) {
                tgl_do_send_location (TLS, PY_PEER_ID(peer),
                                      PyFloat_AsDouble(pyObj1), PyFloat_AsDouble(pyObj2), 0, py_msg_cb, cb_extra);
                Py_XDECREF(pyObj1);
                Py_XDECREF(pyObj2);
            } else
                PyErr_Print();
            break;
        default:
            assert (0);
        }

        // Increment reference on cb_extra as it is passed on to the callback to use
        Py_XINCREF(cb_extra);

        // Clean up any arg variables we could have used.
        //Py_XDECREF(args); // TODO: this is going negative ref and causing segfaults
        Py_XDECREF(peer);
        Py_XDECREF(peer1);

    }
    pos = 0;
}