Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Taro Yamada #1
Member since Sep 2014 · 1 post
Group memberships: Members
Show profile · Link to this post
Subject: How to set xmpp notifications for Google cloud print
Hi,

I'm currently working on Google cloud print notifications using Xmpp.
I have used Matrix SDK to set up and wait for notifications of print jobs in google cloud.
I have three questions.

a) About setting parameter
According to under GCP XMPP site, we need to connect handshake flow.
https://developers.google.com/cloud-print/docs/rawxmpp

Please tell me how to set up the first for which you want to connect.
We need the following settings.
1) Set OAUTH2.0 AccessToken
2) Set HTTP Proxy
      -> For the connection from the enterprise

Currently setting codes are as below:

XmppClient xmpp = new XmppClient();
xmpp.SetUsername(AccessToken); // In agsXMPP, I use AccessToken and success subscription
xmpp.SetXmppDomain("gmail.com");
xmpp.ResolveSrvRecords = false;
xmpp.Hostname = "talk.google.com";
xmpp.ProxyHostname = "proxy.*****.co.jp";
xmpp.ProxyPort = 80**;

Is it correct?

b) How to create the JID
According to https://developers.google.com/cloud-print/docs/rawxmpp,
we need to set 'username' and 'cookie' as below.

std::string credential;
credential.append("\0", 1);
credential.append(username_);
credential.append("\0", 1);
credential.append(cookie_);
el->AddText(Base64Encode(credential));

'cookie' is defined by OAuth2 access token.
In agsXMPP, 'username' is gotten by XmppClientConnection.MyJID.
However, in Matrix, I cannot understand how to create JID.
I think XmppClient does not have JID.


c) How to send the XML
In AgsXMPP, I had to send XML in the following way.
XmppClientConnection xmpp = new XmppClientConnection();
.. // setting
string str = "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>";
xmpp.Send(str);

However, Matrix SDK cannot exist the same method.
Before I send the message, I think I need to create the "new Matrix.Xml.XmppXElement(str)".
Is this correct method?
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

A) and B)
here is an example how you select to use the OAUTH2 authentication in the OnBeforeSasl event.
According to the link you included O-AUTH2 is not a must, its only one of the 3 supported authentication types.

  1. private void xmppClient_OnBeforeSasl(object sender, Matrix.Xmpp.Sasl.SaslEventArgs e)
  2. {
  3.     e.Auto = false;
  4.     e.SaslMechanism = Matrix.Xmpp.Sasl.SaslMechanism.X_OAUTH2;
  5.     e.SaslProperties = new Matrix.Xmpp.Sasl.Processor.XOAuth2.XOAuth2Properties
  6.     {
  7.         AccessToken = "PUT_YOUR_ACCESS_TOKEN_HERE"
  8.     };
  9. }

in your code to setup the proxy you did not specify the proxy type. Once you add this it should be fine:

  1. // this example is for HTTP proxy
  2. // there are other proxy types as well in MatriX
  3. xmpp.ProxyType = Matrix.Net.Proxy.ProxyType.HttpTunnel;
  4. xmpp.ProxyHostname = "proxy.*****.co.jp";
  5. xmpp.ProxyPort = 80**;
  6.  
  7. // set username and password when required
  8. xmpp.ProxyUser = "username";
  9. xmpp.ProxyPass = "secret";

The username is what you put in the xmpp.Username property. This is not different in MatriX than in agsXMPP.
When you gmail address is user123@gmail.com then the username is user123.

C)
there is no need to send a <starttls/> Xmpp packet manual. MatriX is doing this all automatically during the login process.
If you have to send any Xml manual then we recomment to create your custom XmppXElements like described here:
http://www.ag-software.net/matrix-xmpp-sdk/matrix-develope…

if you prefer to send from a string instead of strongly typed code then just do the following:
  1. string xml = @"<message type='chat' to='user123@gmail.com/MatriX' id='f801199c-7bd6-4455-af7c-42e2e7e6be16' xmlns='jabber:client'><body>Hello World</body></message>";
  2.  
  3. XmppXElement el = XmppXElement.LoadXml(xml);
  4. xmpp.Send(el);

let me know if this answers your questions.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS