Hostinfo day 4: Implement command processing code.
[virt-hostinfo.git] / hostinfod / ping.c
diff --git a/hostinfod/ping.c b/hostinfod/ping.c
new file mode 100644 (file)
index 0000000..075bd1b
--- /dev/null
@@ -0,0 +1,57 @@
+/* virt-hostinfo
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "hostinfod.h"
+
+static void
+ping (struct guest_description *hval,
+      const char *cmd, apr_array_header_t *args)
+{
+  const char *echodata;
+  size_t i, len;
+
+  if (!get_args ("s", &echodata)) {
+    send_error (hval, 400);
+    return;
+  }
+  len = strlen (echodata);
+  if (len < 1 || len > 16) {
+    send_error (hval, 400);
+    return;
+  }
+
+  for (i = 0; i < len; ++i)
+    if (!((echodata[i] >= 'a' && echodata[i] <= 'z') ||
+         (echodata[i] >= 'A' && echodata[i] <= 'Z') ||
+         (echodata[i] >= '0' && echodata[i] <= '9'))) {
+      send_error (hval, 400);
+      return;
+    }
+
+  send_reply (
+
+}
+REGISTER_COMMAND ("ping", ping)