Example #1
0
int mwDirectory_search(struct mwDirectory *dir, const char *query) {
  struct mwServiceDirectory *srvc;
  struct mwChannel *chan;
  struct mwPutBuffer *b;
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(dir != NULL, -1);
  g_return_val_if_fail(MW_DIRECTORY_IS_OPEN(dir), -1);
  g_return_val_if_fail(query != NULL, -1);
  g_return_val_if_fail(*query != '\0', -1);

  srvc = dir->service;
  g_return_val_if_fail(srvc != NULL, -1);

  chan = srvc->channel;
  g_return_val_if_fail(chan != NULL, -1);

  b = mwPutBuffer_new();
  guint32_put(b, map_request(dir));
  guint32_put(b, dir->id);
  guint16_put(b, 0x0061);      /* some magic? */
  guint32_put(b, 0x00000008);  /* seek results */
  mwString_put(b, query);

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_send(chan, action_search, &o);
  mwOpaque_clear(&o);

  return ret;
}
Example #2
0
static int send_attrib_list(struct mwServiceAware *srvc) {
  struct mwPutBuffer *b;
  struct mwOpaque o;

  int tmp;
  GList *l;

  g_return_val_if_fail(srvc != NULL, -1);
  g_return_val_if_fail(srvc->channel != NULL, 0);

  l = map_collect_keys(srvc->attribs);
  tmp = g_list_length(l);

  b = mwPutBuffer_new();
  guint32_put(b, 0x00);
  guint32_put(b, tmp);
  
  for(; l; l = g_list_delete_link(l, l)) {
    guint32_put(b, GPOINTER_TO_UINT(l->data));
  }

  mwPutBuffer_finalize(&o, b);
  tmp = mwChannel_send(srvc->channel, msg_OPT_WATCH, &o);
  mwOpaque_clear(&o);

  return tmp;
}
Example #3
0
static void enc_offer_put(struct mwPutBuffer *b, struct mwEncryptOffer *enc) {
  guint16_put(b, enc->mode);

  if(enc->items) {
    guint32 count;
    struct mwPutBuffer *p;
    struct mwOpaque o;
    GList *list;

    /* write the count, items, extra, and flag into a tmp buffer,
       render that buffer into an opaque, and write it into b */

    count = g_list_length(enc->items);
    p = mwPutBuffer_new();

    guint32_put(p, count);
    for(list = enc->items; list; list = list->next) {
      mwEncryptItem_put(p, list->data);
    }

    guint16_put(p, enc->extra);
    gboolean_put(p, enc->flag);

    mwPutBuffer_finalize(&o, p);
    mwOpaque_put(b, &o);
    mwOpaque_clear(&o);
  }
}
Example #4
0
static int dir_open(struct mwDirectory *dir) {
  struct mwServiceDirectory *srvc;
  struct mwChannel *chan;
  struct mwPutBuffer *b;
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(dir != NULL, -1);

  srvc = dir->service;
  g_return_val_if_fail(srvc != NULL, -1);

  chan = srvc->channel;
  g_return_val_if_fail(chan != NULL, -1);

  b = mwPutBuffer_new();
  guint32_put(b, map_request(dir));

  /* unsure about these three bytes */
  gboolean_put(b, FALSE);
  guint16_put(b, 0x0000);

  guint32_put(b, dir->book->id);
  mwString_put(b, dir->book->name);

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_send(chan, action_open, &o);
  mwOpaque_clear(&o);

  return ret;
}
Example #5
0
void CSametimeProto::ExportContactsToServer()
{
	mwSametimeList* user_list;
	mwStorageUnit* unit;
	mwPutBuffer* buff;
	mwOpaque* op;

	debugLog(_T("CSametimeProto::ExportContactsToServer() start"));
	if (MW_SERVICE_IS_DEAD(service_storage)) {
		debugLog(_T("CSametimeProto::ExportContactsToServer() Failed"));
		showPopup(TranslateT("Failed to upload contacts - storage service unavailable."), SAMETIME_POPUP_ERROR);
		return;
	}

	user_list = mwSametimeList_new();
	ExportContactsToList(user_list);

	buff = mwPutBuffer_new();
	mwSametimeList_put(buff, user_list);
	mwSametimeList_free(user_list);

	/* put the buffer contents into a storage unit */
	unit = mwStorageUnit_new(mwStore_AWARE_LIST);
	op = mwStorageUnit_asOpaque(unit);
	mwPutBuffer_finalize(op, buff);

	/* save the storage unit to the service */
	mwServiceStorage_save(service_storage, unit, NULL, NULL, NULL);
}
Example #6
0
/** compose authentication information into an opaque based on the
    password, encrypted via RC2/40 */
static void compose_auth_rc2_40(struct mwOpaque *auth, const char *pass) {
  guchar iv[8], key[5];
  struct mwOpaque a, b, z;
  struct mwPutBuffer *p;

  /* get an IV and a random five-byte key */
  mwIV_init(iv);
  mwKeyRandom(key, 5);

  /* the opaque with the key */
  a.len = 5;
  a.data = key;

  /* the opaque to receive the encrypted pass */
  b.len = 0;
  b.data = NULL;

  /* the plain-text pass dressed up as an opaque */
  z.len = strlen(pass);
  z.data = (guchar *) pass;

  /* the opaque with the encrypted pass */
  mwEncrypt(a.data, a.len, iv, &z, &b);

  /* an opaque containing the other two opaques */
  p = mwPutBuffer_new();
  mwOpaque_put(p, &a);
  mwOpaque_put(p, &b);
  mwPutBuffer_finalize(auth, p);

  /* this is the only one to clear, as the other uses a static buffer */
  mwOpaque_clear(&b);
}
Example #7
0
static int send_JOIN_PLACE(struct mwPlace *place) {
  struct mwOpaque o = {0, 0};
  struct mwPutBuffer *b;
  int ret;

  b = mwPutBuffer_new();
  gboolean_put(b, FALSE);
  guint16_put(b, 0x01);
  guint16_put(b, 0x02); /* 0x01 */
  guint16_put(b, 0x01); /* 0x00 */

  mwPutBuffer_finalize(&o, b);

  ret = mwChannel_send(place->channel, msg_out_JOIN_PLACE, &o);

  mwOpaque_clear(&o);

  if(ret) {
    place_state(place, mwPlace_ERROR);
  } else {
    place_state(place, mwPlace_JOINING);
  }

  return ret;
}
Example #8
0
int mwConference_invite(struct mwConference *conf,
			struct mwIdBlock *who,
			const char *text) {

  struct mwPutBuffer *b;
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(conf != NULL, -1);
  g_return_val_if_fail(conf->channel != NULL, -1);
  g_return_val_if_fail(who != NULL, -1);

  b = mwPutBuffer_new();

  mwIdBlock_put(b, who);
  guint16_put(b, 0x00);
  guint32_put(b, 0x00);
  mwString_put(b, text);
  mwString_put(b, who->user);

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_sendEncrypted(conf->channel, msg_INVITE, &o, FALSE);
  mwOpaque_clear(&o);

  return ret;
}
Example #9
0
static int dir_close(struct mwDirectory *dir) {
  struct mwServiceDirectory *srvc;
  struct mwChannel *chan;
  struct mwPutBuffer *b;
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(dir != NULL, -1);

  srvc = dir->service;
  g_return_val_if_fail(srvc != NULL, -1);

  chan = srvc->channel;
  g_return_val_if_fail(chan != NULL, -1);

  b = mwPutBuffer_new();
  guint32_put(b, next_request_id(dir->service));
  guint32_put(b, dir->id);

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_send(chan, action_close, &o);
  mwOpaque_clear(&o);

  return ret;
}
Example #10
0
int mwPlace_sendText(struct mwPlace *place, const char *msg) {
  struct mwOpaque o = {0,0};
  struct mwPutBuffer *b;
  int ret;

  b = mwPutBuffer_new();
  guint32_put(b, 0x01);  /* probably a message type */
  mwString_put(b, msg);
  mwPutBuffer_finalize(&o, b);

  b = mwPutBuffer_new();
  guint32_put(b, place->section);
  mwOpaque_put(b, &o);
  mwOpaque_clear(&o);
  mwPutBuffer_finalize(&o, b);

  ret = mwChannel_send(place->channel, msg_out_MESSAGE, &o);
  mwOpaque_clear(&o);
  return ret;
}
Example #11
0
struct mwStorageUnit *mwStorageUnit_newInteger(guint32 key,
					       guint32 val) {
  struct mwStorageUnit *u;
  struct mwPutBuffer *b;

  u = g_new0(struct mwStorageUnit, 1);
  u->key = key;
  
  b = mwPutBuffer_new();
  guint32_put(b, val);
  mwPutBuffer_finalize(&u->data, b);

  return u;
}
Example #12
0
struct mwStorageUnit *mwStorageUnit_newString(guint32 key,
					      const char *str) {
  struct mwStorageUnit *u;
  struct mwPutBuffer *b;

  u = g_new0(struct mwStorageUnit, 1);
  u->key = key;

  b = mwPutBuffer_new();
  mwString_put(b, str);
  mwPutBuffer_finalize(&u->data, b);

  return u;
}
Example #13
0
static int send_rem(struct mwChannel *chan, GList *id_list) {
  struct mwPutBuffer *b = mwPutBuffer_new();
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(chan != NULL, 0);

  compose_list(b, id_list);
  mwPutBuffer_finalize(&o, b);

  ret = mwChannel_send(chan, msg_AWARE_REMOVE, &o);
  mwOpaque_clear(&o);

  return ret;
}
Example #14
0
static int send_SECTION_LIST(struct mwPlace *place, guint32 section) {
  int ret = 0;
  struct mwOpaque o = {0, 0};
  struct mwPutBuffer *b;

  b = mwPutBuffer_new();
  guint16_put(b, msg_out_SECTION_LIST);
  guint32_put(b, section);
  gboolean_put(b, FALSE);
  guint32_put(b, ++place->requests);
  mwPutBuffer_finalize(&o, b);

  ret = mwChannel_send(place->channel, msg_out_SECTION, &o);
  mwOpaque_clear(&o);

  return ret;
}
Example #15
0
int mwConference_open(struct mwConference *conf) {
  struct mwSession *session;
  struct mwChannel *chan;
  struct mwPutBuffer *b;
  int ret;
  
  g_return_val_if_fail(conf != NULL, -1);
  g_return_val_if_fail(conf->service != NULL, -1);
  g_return_val_if_fail(conf->state == mwConference_NEW, -1);
  g_return_val_if_fail(conf->channel == NULL, -1);

  session = mwService_getSession(MW_SERVICE(conf->service));
  g_return_val_if_fail(session != NULL, -1);

  if(! conf->name) {
    char *user = mwSession_getProperty(session, mwSession_AUTH_USER_ID);
    conf->name = conf_generate_name(user? user: "******");
  }

  chan = mwChannel_newOutgoing(mwSession_getChannels(session));
  mwChannel_setService(chan, MW_SERVICE(conf->service));
  mwChannel_setProtoType(chan, PROTOCOL_TYPE);
  mwChannel_setProtoVer(chan, PROTOCOL_VER);
  
#if 0
  /* offer all known ciphers */
  mwChannel_populateSupportedCipherInstances(chan);
#endif

  b = mwPutBuffer_new();
  mwString_put(b, conf->name);
  mwString_put(b, conf->title);
  guint32_put(b, 0x00);
  mwPutBuffer_finalize(mwChannel_getAddtlCreate(chan), b);

  ret = mwChannel_create(chan);
  if(ret) {
    conf_state(conf, mwConference_ERROR);
  } else {
    conf_state(conf, mwConference_PENDING);
    conf->channel = chan;
  }

  return ret;
}
Example #16
0
static void ft_create_chan(struct mwFileTransfer *ft) {
  struct mwSession *s;
  struct mwChannelSet *cs;
  struct mwChannel *chan;
  struct mwLoginInfo *login;
  struct mwPutBuffer *b;
  
  /* we only should be calling this if there isn't a channel already
     associated with the conversation */
  g_return_if_fail(ft != NULL);
  g_return_if_fail(mwFileTransfer_isNew(ft));
  g_return_if_fail(ft->channel == NULL);
		   
  s = mwService_getSession(MW_SERVICE(ft->service));
  cs = mwSession_getChannels(s);

  chan = mwChannel_newOutgoing(cs);
  mwChannel_setService(chan, MW_SERVICE(ft->service));
  mwChannel_setProtoType(chan, PROTOCOL_TYPE);
  mwChannel_setProtoVer(chan, PROTOCOL_VER);

  /* offer all known ciphers */
  mwChannel_populateSupportedCipherInstances(chan);

  /* set the target */
  login = mwChannel_getUser(chan);
  login->user_id = g_strdup(ft->who.user);
  login->community = g_strdup(ft->who.community);

  /* compose the addtl create */
  b = mwPutBuffer_new();
  guint32_put(b, 0x00);
  mwString_put(b, ft->filename);
  mwString_put(b, ft->message);
  guint32_put(b, ft->size);
  guint32_put(b, 0x00);
  guint16_put(b, 0x00);

  mwPutBuffer_finalize(mwChannel_getAddtlCreate(chan), b);

  ft->channel = mwChannel_create(chan)? NULL: chan;
  if(ft->channel) {
    mwChannel_setServiceData(ft->channel, ft, NULL);
  }
}
Example #17
0
int mwConference_sendText(struct mwConference *conf, const char *text) {
  struct mwPutBuffer *b;
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(conf != NULL, -1);
  g_return_val_if_fail(conf->channel != NULL, -1);

  b = mwPutBuffer_new();

  guint32_put(b, 0x01);
  mwString_put(b, text);

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_sendEncrypted(conf->channel, msg_MESSAGE, &o, FALSE);
  mwOpaque_clear(&o);

  return ret;
}
Example #18
0
int mwPlace_legacyInvite(struct mwPlace *place,
			 struct mwIdBlock *idb,
			 const char *message) {

  struct mwOpaque o = {0,0};
  struct mwPutBuffer *b;
  int ret;

  b = mwPutBuffer_new();
  mwIdBlock_put(b, idb);
  mwString_put(b, idb->user);
  mwString_put(b, idb->user);
  mwString_put(b, message);
  gboolean_put(b, FALSE);
  mwPutBuffer_finalize(&o, b);

  ret = mwChannel_send(place->channel, msg_out_OLD_INVITE, &o);
  mwOpaque_clear(&o);
  return ret;
}
Example #19
0
int mwServiceDirectory_refreshAddressBooks(struct mwServiceDirectory *srvc) {
  struct mwChannel *chan;
  struct mwPutBuffer *b;
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(srvc != NULL, -1);

  chan = srvc->channel;
  g_return_val_if_fail(chan != NULL, -1);

  b = mwPutBuffer_new();
  guint32_put(b, next_request_id(srvc));

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_send(chan, action_list, &o);
  mwOpaque_clear(&o);

  return ret;
}
Example #20
0
int mwPlace_open(struct mwPlace *p) {
  struct mwSession *session;
  struct mwChannelSet *cs;
  struct mwChannel *chan;
  struct mwPutBuffer *b;
  int ret;

  g_return_val_if_fail(p != NULL, -1);
  g_return_val_if_fail(p->service != NULL, -1);

  session = mwService_getSession(MW_SERVICE(p->service));
  g_return_val_if_fail(session != NULL, -1);

  cs = mwSession_getChannels(session);
  g_return_val_if_fail(cs != NULL, -1);

  chan = mwChannel_newOutgoing(cs);
  mwChannel_setService(chan, MW_SERVICE(p->service));
  mwChannel_setProtoType(chan, PROTOCOL_TYPE);
  mwChannel_setProtoVer(chan, PROTOCOL_VER);

  mwChannel_populateSupportedCipherInstances(chan);

  b = mwPutBuffer_new();
  mwString_put(b, mwPlace_getName(p));
  mwString_put(b, mwPlace_getTitle(p));
  guint32_put(b, 0x00); /* ? */

  mwPutBuffer_finalize(mwChannel_getAddtlCreate(chan), b);

  ret = mwChannel_create(chan);
  if(ret) {
    place_state(p, mwPlace_ERROR);
  } else {
    place_state(p, mwPlace_PENDING);
    p->channel = chan;
    mwChannel_setServiceData(chan, p, NULL);
  }

  return ret;
}
Example #21
0
static int request_send(struct mwChannel *chan, struct mwStorageReq *req) {
  struct mwPutBuffer *b;
  struct mwOpaque o = { 0, 0 };
  int ret;

  b = mwPutBuffer_new();
  request_put(b, req);

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_send(chan, req->action, &o);
  mwOpaque_clear(&o);

  if(! ret) {
    if(req->action == action_save) {
      req->action = action_saved;
    } else if(req->action == action_load) {
      req->action = action_loaded;
    }
  }

  return ret;
}
Example #22
0
int mwConference_sendTyping(struct mwConference *conf, gboolean typing) {
  struct mwPutBuffer *b;
  struct mwOpaque o;
  int ret;

  g_return_val_if_fail(conf != NULL, -1);
  g_return_val_if_fail(conf->channel != NULL, -1);
  g_return_val_if_fail(conf->state == mwConference_OPEN, -1);

  b = mwPutBuffer_new();

  guint32_put(b, 0x02);
  guint32_put(b, 0x01);
  guint32_put(b, !typing);
  mwOpaque_put(b, NULL);

  mwPutBuffer_finalize(&o, b);
  ret = mwChannel_sendEncrypted(conf->channel, msg_MESSAGE, &o, FALSE);
  mwOpaque_clear(&o);

  return ret;
}
void MeanwhileSession::syncContactsToServer()
{
    HERE;
    struct mwSametimeList *list = mwSametimeList_new();

    /* set up a fallback group for top-level contacts */
    struct mwSametimeGroup *topstgroup = mwSametimeGroup_new(list,
            mwSametimeGroup_DYNAMIC, "People");
    mwSametimeGroup_setOpen(topstgroup, true);

    const QHash<QString, Kopete::Contact *> contacts = account->contacts();
   // Q3DictIterator<Kopete::Contact> it(account->contacts());
    for(QHash<QString, Kopete::Contact *>::const_iterator it = contacts.constBegin();
            it != contacts.constEnd(); ++it ) {
        MeanwhileContact *contact = static_cast<MeanwhileContact *>(it.value());

        /* Find the group that the metacontact is in */
        Kopete::MetaContact *mc = contact->metaContact();
        if (!mc)
            continue;

        Kopete::Group *contactgroup = mc->groups().value(0);
        if (!contactgroup)
            continue;

        if (contactgroup->type() == Kopete::Group::Temporary)
            continue;

        struct mwSametimeGroup *stgroup;
        if (contactgroup->type() == Kopete::Group::TopLevel) {
            stgroup = topstgroup;
        } else  {
            /* find (or create) a matching sametime list group */
            stgroup = mwSametimeList_findGroup(list,
                        contactgroup->displayName().toUtf8().constData());
            if (!stgroup) {
                stgroup = mwSametimeGroup_new(list, mwSametimeGroup_DYNAMIC,
                        contactgroup->displayName().toUtf8().constData());
            }
            mwSametimeGroup_setOpen(stgroup, contactgroup->isExpanded());
            mwSametimeGroup_setAlias(stgroup,
                    contactgroup->pluginData(account->protocol(), "alias").toUtf8().constData());
        }

        QByteArray tmpMeanwhileId = contact->meanwhileId().toUtf8();
        /* now add the user (by IDBlock) */
        struct mwIdBlock id =
            { (gchar*)tmpMeanwhileId.constData(), 0 };
        struct mwSametimeUser *stuser = mwSametimeUser_new(stgroup,
                mwSametimeUser_NORMAL, &id);

        mwSametimeUser_setAlias(stuser, mc->displayName().toUtf8().constData());
    }

    /* store! */
    struct mwPutBuffer *buf = mwPutBuffer_new();
    struct mwStorageUnit *unit = mwStorageUnit_new(mwStore_AWARE_LIST);
    struct mwOpaque *opaque = mwStorageUnit_asOpaque(unit);

    mwSametimeList_put(buf, list);
    mwPutBuffer_finalize(opaque, buf);

    mwServiceStorage_save(storageService, unit, NULL, NULL, NULL);

    mwSametimeList_free(list);
}