[asterisk-users] Problem with AMI action userevent

Jim Dickenson dickenson at cfmc.com
Wed Feb 11 17:25:51 CST 2009


When action_userevent was rewritten to not use local variables there was an
omission. The buffer is not initialized each time so things keep getting
appended to the buffer.

In addition I would find it useful to have the ping action return the
timestamp. That way I do not have to have timestamp event enabled and when I
want to check the time sync with the asterisk server I can just to a ping
and get a timestamp back.

Here is a patch the current svn version of manager.c from the 1.6.0 branch


--- manager.c    2009-02-11 15:16:16.000000000 -0800
+++ manager.c.mine    2009-02-11 15:10:52.000000000 -0800
@@ -1089,9 +1089,13 @@
 
 static int action_ping(struct mansession *s, const struct message *m)
 {
+    struct timeval now;
+
+    now = ast_tvnow();
+
     astman_append(s, "Response: Success\r\n"
-        "Ping: Pong\r\n"
-        "\r\n");
+        "Ping: Pong Timestamp: %ld.%06lu\r\n"
+        "\r\n", now.tv_sec, (unsigned long) now.tv_usec);
     return 0;
 }
 
@@ -2462,6 +2466,8 @@
     const char *event = astman_get_header(m, "UserEvent");
     struct ast_str *body = ast_str_thread_get(&userevent_buf, 16);
     int x;
+        /* better init stuff so  ast_str_append can be called */
+        body->used = 0;
     for (x = 0; x < m->hdrcount; x++) {
         if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:")))
{
             ast_str_append(&body, 0, "%s\r\n", m->headers[x]);

-- 
Jim Dickenson
mailto:dickenson at cfmc.com

CfMC
http://www.cfmc.com/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20090211/de8f4da2/attachment.htm 


More information about the asterisk-users mailing list