コード例 #1
0
ファイル: menu.cpp プロジェクト: Israel-/jwm-settings-manager
bool JSM_Menu::ConfigSubMenuItem(int menu,int item,int sub,Fl_Input* prog_label,Fl_Input* prog_icon,Fl_Input* prog_input,Fl_Check_Button* conf_button){
	debug_out("bool ConfigMenuItem(int menu,int item,int sub,Fl_Input* prog_label,Fl_Input* prog_icon,Fl_Input* prog_input,Fl_Check_Button* conf_button)");
	const char* lbl=NULL;
	if(prog_label!=NULL)lbl=prog_label->value();
	const char* icn=NULL;
	if(prog_icon!=NULL)icn=prog_icon->value();
	const char* prog=NULL;
	if(prog_input!=NULL)prog=prog_input->value();
	char chk='a';
	if(conf_button!=NULL)chk=conf_button->value();
	std::string check="false";
	switch (chk){
		case '0':check="true";
		default:check="false";
	}
	bool retval = true;
	pugi::xml_node noder=getNode(menu, "RootMenu", item);
	if(!noder){return false;}
	pugi::xml_node node=getSubNode(sub,noder);
	pugi::xml_node node1=node;
	pugi::xml_node node2=node;
	if(!node){return false;}
	if(lbl!=NULL){if(!setAttribute(node,"label",lbl)){retval=false;}}
	noder=getNode(menu, "RootMenu", item);
	if(!noder){return false;}
	node=getSubNode(sub,noder);
	if(icn!=NULL){if(!setAttribute(node,"icon",icn)){retval=false;}}
	noder=getNode(menu, "RootMenu", item);
	if(!noder){return false;}
	node=getSubNode(sub,noder);
	if(prog!=NULL){if(!setNodeText(node,prog)){retval=false;}}
	//TODO toggle button issue...
	return retval;
}
コード例 #2
0
ファイル: XMLUtils.cpp プロジェクト: Inzaghi2012/ie-toolbar
MSXML2::IXMLDOMNodePtr createNodeWithText(MSXML2::IXMLDOMDocumentPtr& xmlDoc, 
      const String& nodeName, const String& text) {
  MSXML2::IXMLDOMNodePtr res = createNode(xmlDoc, nodeName);
  if (res == NULL) {
    throw XMLUtils::ParseError();
  }

  setNodeText(res, text);

  return res;
}
コード例 #3
0
ファイル: omemo.cpp プロジェクト: psi-plus/plugins
  void OMEMO::publishOwnBundle(int account) {
    Bundle b = getSignal(account)->collectBundle();
    if (!b.isValid()) return;

    QDomDocument doc;
    QDomElement publish = doc.createElement("publish");
    doc.appendChild(publish);

    QDomElement item = doc.createElement("item");
    publish.appendChild(item);

    QDomElement bundle = doc.createElementNS(OMEMO_XMLNS, "bundle");
    item.appendChild(bundle);

    publish.setAttribute("node", bundleNodeName(getSignal(account)->getDeviceId()));

    QDomElement signedPreKey = doc.createElement("signedPreKeyPublic");
    signedPreKey.setAttribute("signedPreKeyId", b.signedPreKeyId);
    setNodeText(signedPreKey, b.signedPreKeyPublic);
    bundle.appendChild(signedPreKey);

    QDomElement signedPreKeySignature = doc.createElement("signedPreKeySignature");
    setNodeText(signedPreKeySignature, b.signedPreKeySignature);
    bundle.appendChild(signedPreKeySignature);

    QDomElement identityKey = doc.createElement("identityKey");
    setNodeText(identityKey, b.identityKeyPublic);
    bundle.appendChild(identityKey);

    QDomElement preKeys = doc.createElement("prekeys");
    bundle.appendChild(preKeys);

    foreach (auto preKey, b.preKeys) {
      QDomElement preKeyPublic = doc.createElement("preKeyPublic");
      preKeyPublic.setAttribute("preKeyId", preKey.first);
      setNodeText(preKeyPublic, preKey.second);
      preKeys.appendChild(preKeyPublic);
    }

    pepPublish(account, doc.toString());
  }
コード例 #4
0
ファイル: XMLUtils.cpp プロジェクト: Inzaghi2012/ie-toolbar
void  addTextAttributeToNode(MSXML2::IXMLDOMDocumentPtr& xmlDoc,
      MSXML2::IXMLDOMNodePtr& targetNode, const String& attributeName, 
      const String& attributeValue) {
  MSXML2::IXMLDOMNodePtr attributeNode = 
  xmlDoc->createNode(NODE_ATTRIBUTE, attributeName.c_str(), _T("")); 

  setNodeText(attributeNode, attributeValue);
  MSXML2::IXMLDOMNamedNodeMapPtr attributes = targetNode->Getattributes();
  if (attributes == NULL) {
    throw XMLUtils::ParseError();
  }

  attributes->setNamedItem(attributeNode);
}
コード例 #5
0
ファイル: omemo.cpp プロジェクト: psi-plus/plugins
  bool OMEMO::encryptMessage(const QString &ownJid, int account, QDomElement &xml, bool buildSessions, const uint32_t *toDeviceId) {
    std::shared_ptr<Signal> signal = getSignal(account);
    QString recipient = m_contactInfoAccessor->realJid(account, xml.attribute("to")).split("/").first();
    bool isGroup = xml.attribute("type") == "groupchat";
    if (!isEnabledForUser(account, recipient)) {
      return false;
    }

    if (buildSessions) {
      QMap<QString, QVector<uint32_t>> invalidSessions;
      QVector<uint32_t> invalidSessionsWithOwnDevices;
      if (isGroup) {
        forEachMucParticipant(account, ownJid, recipient, [&](const QString &userJid) {
          QVector<uint32_t> sessions = signal->invalidSessions(userJid);
          if (!sessions.isEmpty()) {
            invalidSessions.insert(userJid, sessions);
          }
          return true;
        });
      }
      else {
        QVector<uint32_t> sessions = signal->invalidSessions(recipient);
        if (!sessions.isEmpty()) {
          invalidSessions.insert(recipient, sessions);
        }
      }
      invalidSessionsWithOwnDevices = signal->invalidSessions(ownJid);
      invalidSessionsWithOwnDevices.removeOne(signal->getDeviceId());
      if (!invalidSessions.isEmpty() || !invalidSessionsWithOwnDevices.isEmpty()) {
        buildSessionsFromBundle(invalidSessions, invalidSessionsWithOwnDevices, ownJid, account, xml);
        xml = QDomElement();
        return true;
      }
    }

    signal->processUndecidedDevices(recipient, false);
    signal->processUndecidedDevices(ownJid, true);

    QDomElement encrypted = xml.ownerDocument().createElementNS(OMEMO_XMLNS, "encrypted");
    QDomElement header = xml.ownerDocument().createElement("header");
    header.setAttribute("sid", signal->getDeviceId());
    encrypted.appendChild(header);
    xml.appendChild(encrypted);

    QByteArray iv = Crypto::randomBytes(OMEMO_AES_GCM_IV_LENGTH);

    QDomElement ivElement = xml.ownerDocument().createElement("iv");
    ivElement.appendChild(xml.ownerDocument().createTextNode(iv.toBase64()));
    header.appendChild(ivElement);

    QByteArray key = Crypto::randomBytes(OMEMO_AES_128_KEY_LENGTH);
    QDomElement body = xml.firstChildElement("body");
    QPair<QByteArray, QByteArray> encryptedBody;
    if (!body.isNull()) {
      QString plainText = body.firstChild().nodeValue();
      encryptedBody = Crypto::aes_gcm(Crypto::Encode, iv, key, plainText.toUtf8());
      key += encryptedBody.second;
    }
    QList<EncryptedKey> encryptedKeys;
    if (isGroup) {
      forEachMucParticipant(account, ownJid, recipient, [&](const QString &userJid) {
        encryptedKeys.append(signal->encryptKey(ownJid, userJid, key));
        return true;
      });
    }
    else {
      encryptedKeys = signal->encryptKey(ownJid, recipient, key);
    }

    if (encryptedKeys.isEmpty()) {
      m_accountController->appendSysMsg(account, xml.attribute("to"), "[OMEMO] Unable to build any sessions, the message was not sent");
      xml = QDomElement();
    }
    else {
      foreach (EncryptedKey encKey, encryptedKeys) {
        if (toDeviceId != nullptr && *toDeviceId != encKey.deviceId) {
          continue;
        }
        QDomElement keyElement = xml.ownerDocument().createElement("key");
        keyElement.setAttribute("rid", encKey.deviceId);
        if (encKey.isPreKey) {
          keyElement.setAttribute("prekey", 1);
        }
        setNodeText(keyElement, encKey.key);
        header.appendChild(keyElement);
      }

      if (!body.isNull()) {
        if (isGroup) {
          m_encryptedGroupMessages.insert(xml.attribute("id"), body.firstChild().nodeValue());
        }
        xml.removeChild(body);

        QDomElement payload = xml.ownerDocument().createElement("payload");
        payload.appendChild(xml.ownerDocument().createTextNode(encryptedBody.first.toBase64()));
        encrypted.appendChild(payload);

        QDomElement html = xml.firstChildElement("html");
        if (!html.isNull()) {
          xml.removeChild(html);
        }
      }

      xml.appendChild(xml.ownerDocument().createElementNS("urn:xmpp:hints", "store"));

      QDomElement encryption = xml.ownerDocument().createElementNS("urn:xmpp:eme:0", "encryption");
      encryption.setAttribute("namespace", OMEMO_XMLNS);
      encryption.setAttribute("name", "OMEMO");
      xml.appendChild(encryption);
    }

    return true;
  }