5

A partial solution was given by:

Parsing ASCII characters with Erlang

Case 1: this worked fine for Hindi text

mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrep39uT92AFuQ1ILouWkfPq52GgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([224,164,181,224,164,191,224,164,149,224,164,191,224,164,
                    170,224,165,128,224,164,161,224,164,191,224,
                    164,175,224,164,190]),
    "9@devlan/sd","asas"). 

Result:

{ok,"{\"multicast_id\":7485677963483149262,\"success\":1,\"failure\":0,\"canonical_ids\":0,\"results\":[{\"message_id\":\"0:1434977706573613%38d7c464f9fd7ecd\"}]}"}

Case 2: for English letters (ASCII values 100, 101 etc were given)

(ejabberd@localhost)3> mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrep39uT92AMQ1ILouWkfPq52GgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([100,101,102,103]),
    "9@devlan/sd","asas").    

{error,{"HTTP/1.1", "JSON_PARSING_ERROR: Unexpected token END OF FILE at position 402.\n"}}

Case 3: An exception was thrown

(ejabberd@localhost)4> mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrLouWkfPq52GgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([224,164,100,101,102,103]),
    "9@devlan/sd","asas").
** exception exit: {ucs,{bad_utf8_character_code}}
     in function  xmerl_ucs:from_utf8/1 (xmerl_ucs.erl, line 185)
     in call from mochijson2:json_encode_string/2 (mochijson2.erl, line 218)
     in call from mochijson2:'-json_encode_proplist/2-fun-0-'/3 (mochijson2.erl, line 199)
     in call from lists:foldl/3 (lists.erl, line 1248)
     in call from mochijson2:json_encode_proplist/2 (mochijson2.erl, line 202)
     in call from mochijson2:'-json_encode_proplist/2-fun-0-'/3 (mochijson2.erl, line 199)
     in call from lists:foldl/3 (lists.erl, line 1248)
     in call from mochijson2:json_encode_proplist/2 (mochijson2.erl, line 202)

Case 4: if the character values are 0-padded

(ejabberd@localhost)7> mod_pushAndroid:send_gcm_msg('APA91bFME7yEJagEeHY7-qRP4Zz4LAYBG5mTALL9TNfrep39uT92AM7asrqGgI3QPNbXHzFfOou67XPtum2J14MnkUdhs0vyccVPDRzLVGrE68k4BNPwRlqQUOv',
    "GROUP","Message","2001","GIS=d",
    list_to_binary([097,098]),
    "9@devlan/sd","asas").

{error,{"HTTP/1.1",
    [60,33,68,79,67,84,89,80,69,32,104,116,109,108,62,10,60,104,
     116,109,108,32,108,97,110|...]}}

What format should this User reg id of GCM user be sent as? I feel something could be wrong with mochijson but then all other languages work fine and English literals fail to be sent.

Any pointers?

Community
  • 1
  • 1
Dummy Bee
  • 259
  • 3
  • 13
  • Is there any way to show the intermediary JSON format generated? – I GIVE TERRIBLE ADVICE Jun 22 '15 at 13:51
  • "{\"registration_ids\":[\"APA91bGLjnkhqZlqFEp7mTo9p1vu9s92_A0UIzlUHnhl4xdFTaZ_0HpD5SISB4jNRPi2D7_c8D_mbhUT_k-T2Bo_i_G3Jt1kIqbgQKrFwB3gp1jeGatrOMsfG4gAJSEkClZFFIJEEyow\"],\"data\":{\"message\":[104,105],\"type\":[71,82,79,85,80],\"enum\":2001,\"groupid\":[71,73,68],\"groupname\":[71,114,111,117,112,78,97,109,101],\"sender\":[49,64,100,101,118,108,97,98,47,115,100,115],\"receiver\":[97,115,97,115]},\"time_to_live\":2419200}" – Dummy Bee Jun 22 '15 at 14:26
  • But I must add after you advice to the "Message" part I have added a list_to_binary(Message). So that's a little different now. This json is from 2 days back. Although not a lot different from the current one. – Dummy Bee Jun 22 '15 at 14:27
  • 1
    I see a bunch of invalid characters there: U+200C (ZERO WIDTH NON-JOINER) and U+200B (ZERO WIDTH SPACE). Are they part of the standard thing or bad copy/pasting? I also tried the thing with encodings where `[71,82,79,85,80]` is `<<71,82,79,85,80>>` which are both the string "GROUP". `jsx` is able to decode it fine, and so is `mochison2`. Finally, prepending 0s in front of numbers does nothing in Erlang: `15 = 015 = 0015`. They're all decimal, none switch base (you use `16#15 = 16#015 = 21`. – I GIVE TERRIBLE ADVICE Jun 22 '15 at 20:46
  • I did not get the invalid characters part. What's U+200C you are getting? I simply replaced the content of list_to_binary([..])each time by up-arrow and then manually backspace deletion of numerlas. Copy/pasted only the first one which worked. Confused! – Dummy Bee Jun 23 '15 at 01:19
  • I copied the text you pasted here. That's the one that contains these 0-space unicode characters. Otherwise, everything appears normal and functional. – I GIVE TERRIBLE ADVICE Jun 23 '15 at 01:57
  • You tried the Case 2 from above? The letters "defg"? I wonder how are these characters being introduced. :/ anything you propose I do or look into? – Dummy Bee Jun 23 '15 at 02:59
  • @IGIVETERRIBLEADVICE Have sent you an email as well. Kindly have a look at that as well. Thank you! – Dummy Bee Jun 23 '15 at 04:58

0 Answers0