The format is not different.<br>Any event may have a body which is indicated by the presence of a Content-Length header.<br><br>Most events do not have a body but some do, such as the MESSAGE_WAITING event which contains the protocol specific MWI data.<br>
Also the MESSAGE event contains the composed text of the message much like an email.<br><br>A client should do the framing of the socket by reading headers until 2 CR are encountered and all the bytes up to that point will be a list of name: value pairs one line each.&nbsp; (Any multiline header data is url encoded so it still appears as 1 line on the socket)<br>
If a Content-Length header is encountered you then read exactly that many bytes from the socket.&nbsp; Note since this is TCP this may take more than one read so if you are supposed to read 200 bytes and the next read only returns 50 you must continue to read another 150 and so on until you have read 200 bytes or the socket has an error.&nbsp; Once you have read all the bytes in the content length the next packet will start on the subsequent byte.<br>
<br>The BACKGROUND_JOB event is the same as any other event as far as the protocol is concerned.&nbsp; It contains a body which stores the output of the command you executed.&nbsp; That is the only real difference and that difference is governed by the bgapi mechanism not the event socket protocol.<br>
<br>The fact that the event contains a background job is opaque to the protocol itself.&nbsp; It would be a severe limitation and violation of the scope of the protocol if it were to be aware of exactly what a background job was.<br>
<br>The point of the Content-Type is to enumerate the differences between the types of messages the protocol is aware of.<br><br>You should use the Content-Type to route the event to the client library as an event at which time your code would serialize the event into some form of local hash it can then check the event_id to route it to the code that handles specific events such as BACKGROUND_JOB and when the type is BACKGROUND_JOB you then consult the Job-UUID and the body of the message.<br>
<br>Imagine if your E-mail used the content-type to determine if your message contained a Birthday greeting from your friend Bill..... <br><br><br><div class="gmail_quote">On Mon, Apr 28, 2008 at 6:37 PM, Juan Jose Comellas &lt;<a href="mailto:juanjo@comellas.org">juanjo@comellas.org</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">But shouldn&#39;t the content-type reflect the fact that the format of<br>
this event is different from that of other event messages? I&#39;ve<br>
written a parser for mod_event_socket messages that relies on the<br>
content-type to determine how to interpret the message and here we<br>
seem to have a case where the content-type does not match its content.<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
On Mon, Apr 28, 2008 at 8:17 PM, Anthony Minessale<br>
&lt;<a href="mailto:anthony.minessale@gmail.com">anthony.minessale@gmail.com</a>&gt; wrote:<br>
&gt; it&#39;s not a serialized event. it&#39;s actually the output of the command in<br>
&gt; question.<br>
&gt;<br>
&gt; The correct way to deal with it is to subscribe to the BACKGROUND_JOB event<br>
&gt; and<br>
&gt; use the Job-UUID header to match the packet to the uuid given as a response<br>
&gt; to the submission of the request.<br>
&gt; &nbsp;When a match exists the body of that event will be the output generated by<br>
&gt; the API call.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Mon, Apr 28, 2008 at 5:45 PM, Juan Jose Comellas &lt;<a href="mailto:juanjo@comellas.org">juanjo@comellas.org</a>&gt;<br>
&gt; wrote:<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Whenever a call to a command is made using bgapi, a BACKGROUND_JOB<br>
&gt; &gt; event is sent by FreeSWITCH when the command is completed. A<br>
&gt; &gt; BACKGROUND_JOB event looks like this:<br>
&gt; &gt;<br>
&gt; &gt; -------------- cut --------------<br>
&gt; &gt; Content-Length: 614<br>
&gt; &gt; Content-Type: text/event-plain<br>
&gt; &gt;<br>
&gt; &gt; Job-UUID: d19f2410-1548-11dd-9eeb-0d886880e312<br>
&gt; &gt; Job-Command: originate<br>
&gt; &gt; Job-Command-Arg: sofia/default/user2.comellas%40192.168.1.40%3A5061%202001<br>
&gt; &gt; Event-Name: BACKGROUND_JOB<br>
&gt; &gt; Core-UUID: f17f3284-1543-11dd-9eeb-0d886880e312<br>
&gt; &gt; FreeSWITCH-Hostname: comellas<br>
&gt; &gt; FreeSWITCH-IPv4: <a href="http://192.168.1.38" target="_blank">192.168.1.38</a><br>
&gt; &gt; FreeSWITCH-IPv6: <a href="http://127.0.0.1" target="_blank">127.0.0.1</a><br>
&gt; &gt; Event-Date-Local: 2008-04-28%2014%3A30%3A47<br>
&gt; &gt; Event-Date-GMT: Mon,%2028%20Apr%202008%2017%3A30%3A47%20GMT<br>
&gt; &gt; Event-Date-timestamp: 1209403847575107<br>
&gt; &gt; Event-Calling-File: mod_event_socket.c<br>
&gt; &gt; Event-Calling-Function: api_exec<br>
&gt; &gt; Event-Calling-Line-Number: 602<br>
&gt; &gt; Content-Length: 41<br>
&gt; &gt;<br>
&gt; &gt; +OK d19f45e4-1548-11dd-9eeb-0d886880e312<br>
&gt; &gt; -------------- cut --------------<br>
&gt; &gt;<br>
&gt; &gt; &gt;From what MikeJ told me over IRC, the body of a BACKGROUND_JOB message<br>
&gt; &gt; is actually a serialized event containing the response to the original<br>
&gt; &gt; command. The problem is that the content-type of the message is the<br>
&gt; &gt; same as that used by any normal event. This makes it difficult to have<br>
&gt; &gt; a generic parser, because we have to analyze the body of the message<br>
&gt; &gt; to determine whether we are dealing with a normal event or a<br>
&gt; &gt; BACKGROUND_JOB. The other problem I see is that the body containing<br>
&gt; &gt; the serialized event does not have a content-type of its own.<br>
&gt; &gt;<br>
&gt; &gt; An example of a message with the above mentioned problems addressed<br>
&gt; &gt; could look like this:<br>
&gt; &gt;<br>
&gt; &gt; -------------- cut --------------<br>
&gt; &gt; Content-Length: 643<br>
&gt; &gt; Content-Type: text/background-response-wrapper-plain<br>
&gt; &gt;<br>
&gt; &gt; Job-UUID: d19f2410-1548-11dd-9eeb-0d886880e312<br>
&gt; &gt; Job-Command: originate<br>
&gt; &gt; Job-Command-Arg: sofia/default/user2.comellas%40192.168.1.40%3A5061%202001<br>
&gt; &gt; Event-Name: BACKGROUND_JOB<br>
&gt; &gt; Core-UUID: f17f3284-1543-11dd-9eeb-0d886880e312<br>
&gt; &gt; FreeSWITCH-Hostname: comellas<br>
&gt; &gt; FreeSWITCH-IPv4: <a href="http://192.168.1.38" target="_blank">192.168.1.38</a><br>
&gt; &gt; FreeSWITCH-IPv6: <a href="http://127.0.0.1" target="_blank">127.0.0.1</a><br>
&gt; &gt; Event-Date-Local: 2008-04-28%2014%3A30%3A47<br>
&gt; &gt; Event-Date-GMT: Mon,%2028%20Apr%202008%2017%3A30%3A47%20GMT<br>
&gt; &gt; Event-Date-timestamp: 1209403847575107<br>
&gt; &gt; Event-Calling-File: mod_event_socket.c<br>
&gt; &gt; Event-Calling-Function: api_exec<br>
&gt; &gt; Event-Calling-Line-Number: 602<br>
&gt; &gt; Content-Type: api/background-response<br>
&gt; &gt; Content-Length: 41<br>
&gt; &gt;<br>
&gt; &gt; +OK d19f45e4-1548-11dd-9eeb-0d886880e312<br>
&gt; &gt; -------------- cut --------------<br>
&gt; &gt;<br>
&gt; &gt; What do you think? Is a change similar to what I propose feasible?<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; Freeswitch-dev mailing list<br>
&gt; &gt; <a href="mailto:Freeswitch-dev@lists.freeswitch.org">Freeswitch-dev@lists.freeswitch.org</a><br>
&gt; &gt; <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
&gt; &gt; UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
&gt; &gt; <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Anthony Minessale II<br>
&gt;<br>
&gt; FreeSWITCH <a href="http://www.freeswitch.org/" target="_blank">http://www.freeswitch.org/</a><br>
&gt; ClueCon <a href="http://www.cluecon.com/" target="_blank">http://www.cluecon.com/</a><br>
&gt;<br>
&gt; AIM: anthm<br>
&gt; <a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>
&gt; GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
&gt; &nbsp;IRC: <a href="http://irc.freenode.net" target="_blank">irc.freenode.net</a> #freeswitch<br>
&gt;<br>
&gt; FreeSWITCH Developer Conference<br>
&gt; <a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br>
&gt; <a href="http://iax:guest@conference.freeswitch.org/888" target="_blank">iax:guest@conference.freeswitch.org/888</a><br>
&gt; &nbsp;<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>
&gt; pstn:213-799-1400<br>
&gt; _______________________________________________<br>
&gt; &nbsp;Freeswitch-dev mailing list<br>
&gt; &nbsp;<a href="mailto:Freeswitch-dev@lists.freeswitch.org">Freeswitch-dev@lists.freeswitch.org</a><br>
&gt; &nbsp;<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
&gt; &nbsp;UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
&gt; &nbsp;<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
Freeswitch-dev mailing list<br>
<a href="mailto:Freeswitch-dev@lists.freeswitch.org">Freeswitch-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Anthony Minessale II<br><br>FreeSWITCH <a href="http://www.freeswitch.org/">http://www.freeswitch.org/</a><br>ClueCon <a href="http://www.cluecon.com/">http://www.cluecon.com/</a><br>
<br>AIM: anthm<br><a href="mailto:MSN%3Aanthony_minessale@hotmail.com">MSN:anthony_minessale@hotmail.com</a><br>GTALK/JABBER/<a href="mailto:PAYPAL%3Aanthony.minessale@gmail.com">PAYPAL:anthony.minessale@gmail.com</a><br>
IRC: <a href="http://irc.freenode.net">irc.freenode.net</a> #freeswitch<br><br>FreeSWITCH Developer Conference<br><a href="mailto:sip%3A888@conference.freeswitch.org">sip:888@conference.freeswitch.org</a><br><a href="http://iax:guest@conference.freeswitch.org/888">iax:guest@conference.freeswitch.org/888</a><br>
<a href="mailto:googletalk%3Aconf%2B888@conference.freeswitch.org">googletalk:conf+888@conference.freeswitch.org</a><br>pstn:213-799-1400