Beispiel #1
0
static void tgprpl_xfer_send_init (PurpleXfer *X) {
  struct tgp_xfer_send_data *data = X->data;
  
  purple_xfer_start (X, -1, NULL, 0);
  
  const char *file = purple_xfer_get_filename (X);
  const char *localfile = purple_xfer_get_local_filename (X);
  const char *who = purple_xfer_get_remote_user (X);
  debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who);
  
  tgl_peer_t *P = find_peer_by_name (data->conn->TLS, who);
  if (P) {
    if (tgl_get_peer_type (P->id) != TGL_PEER_ENCR_CHAT) {
      tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL,
                            0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_on_finished, data);
    }
    else {
      purple_notify_message (_telegram_protocol, PURPLE_NOTIFY_MSG_ERROR, "Not supported",
                             "Sorry, sending documents to encrypted chats not yet supported.",
                             NULL, NULL, NULL);
    }
  }
  
  data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X);
}
Beispiel #2
0
static void tgprpl_xfer_send_init (PurpleXfer *X) {
  debug ("tgprpl_xfer_send_init(): sending xfer accepted.");

  struct tgp_xfer_send_data *data;
  const char *file, *localfile, *who;
  tgl_peer_t *P;

  data = X->data;
  purple_xfer_start (X, -1, NULL, 0);

  file = purple_xfer_get_filename (X);
  localfile = purple_xfer_get_local_filename (X);
  who = purple_xfer_get_remote_user (X);
  debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who);

  P = tgp_blist_lookup_peer_get (data->conn->TLS, who);
  g_return_if_fail (P);

  if (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT) {
    purple_xfer_error (PURPLE_XFER_SEND, data->conn->pa, who,
        _("Sorry, sending documents to encrypted chats not yet supported."));
    purple_xfer_cancel_local (X);
    return;
  }

  tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL, 0,
      TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_send_on_finished, data);

  // see comment in tgprpl_xfer_recv_init()
  purple_xfer_ref (X);

  data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X);
  data->loading = TRUE;
}
Beispiel #3
0
static void tgprpl_xfer_send_init (PurpleXfer *X) {
  struct tgp_xfer_send_data *data = X->data;
  
  purple_xfer_start (X, -1, NULL, 0);
  
  const char *file = purple_xfer_get_filename (X);
  const char *localfile = purple_xfer_get_local_filename (X);
  const char *who = purple_xfer_get_remote_user (X);
  debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who);
  
  tgl_peer_t *P = find_peer_by_name (data->conn->TLS, who);
  if (P) {
      tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL,
                            0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_on_finished, data);
  }
  
  data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X);
}
Beispiel #4
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;
}
Beispiel #5
0
int tgp_msg_send (struct tgl_state *TLS, const char *message, tgl_peer_id_t to) {
  // search for outgoing embedded image tags and send them
  gchar *img = NULL;
  gchar *stripped = NULL;
  if ((img = g_strrstr (message, "<IMG")) || (img = g_strrstr (message, "<img"))) {
    if (tgl_get_peer_type(to) == TGL_PEER_ENCR_CHAT) {
      tgp_msg_err_out (TLS, "Sorry, sending documents to encrypted chats not yet supported.", to);
      return 0;
    }
    
    debug ("img found: %s", img);
    gchar *id;
    if ((id = g_strrstr (img, "ID=\"")) || (id = g_strrstr (img, "id=\""))) {
      id += 4;
      debug ("id found: %s", id);
      int imgid = atoi (id);
      if (imgid > 0) {
        PurpleStoredImage *psi = purple_imgstore_find_by_id (imgid);
        gchar *tmp = g_build_filename(g_get_tmp_dir(), purple_imgstore_get_filename (psi), NULL) ;
        GError *err = NULL;
        gconstpointer data = purple_imgstore_get_data (psi);
        g_file_set_contents (tmp, data, purple_imgstore_get_size (psi), &err);
        if (! err) {
          stripped = purple_markup_strip_html (message);
          tgl_do_send_document (TLS, to, tmp, stripped, (int)strlen (stripped), TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgp_msg_send_done, NULL);
          g_free (stripped);
          return 1;
        } else {
          failure ("Cannot store image, temp directory not available: %s\n", err->message);
          g_error_free (err);
          return 0;
        }
      }
    }
    // no image id found in image
    return 0;
  }
  
#ifndef __ADIUM_
  /*
    Adium won't escape any HTML markup and just pass any user-input through,
    while Pidgin will replace special chars with the escape chars and also add 
    additional markup for RTL languages and such.

    First, we remove any HTML markup added by Pidgin, since Telegram won't handle it properly.
    User-entered HTML is still escaped and therefore won't be harmed.
   */
  stripped = purple_markup_strip_html (message);
  
  /* 
    now unescape the markup, so that html special chars will still show
    up properly in Telegram
   */
  gchar *unescaped = purple_unescape_text (stripped);
  int ret = tgp_msg_send_split (TLS, stripped, to);
  
  g_free (unescaped);
  g_free (stripped);
  return ret;
#endif
  
  return tgp_msg_send_split (TLS, message, to);
}