xpc: use the same XPC message "type" mechanism on Mach service as on channels
authorMartin Willi <martin@revosec.ch>
Thu, 2 May 2013 08:54:55 +0000 (10:54 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 18 Jul 2013 10:17:55 +0000 (12:17 +0200)
src/frontends/osx/charon-xpc/xpc_dispatch.c

index 56d7850..f99ad67 100644 (file)
@@ -195,7 +195,7 @@ xpc_object_t start_connection(private_xpc_dispatch_t *this,
 }
 
 /**
- * XPC command dispatch table
+ * XPC RPC command dispatch table
  */
 static struct {
        char *name;
@@ -213,27 +213,48 @@ static void handle(private_xpc_dispatch_t *this, xpc_object_t request)
 {
        xpc_connection_t client;
        xpc_object_t reply;
-       const char *command;
+       const char *type, *rpc;
+       bool found = FALSE;
        int i;
 
        client = xpc_dictionary_get_remote_connection(request);
-       command = xpc_dictionary_get_string(request, "command");
-       if (command)
+       type = xpc_dictionary_get_string(request, "type");
+       if (type)
        {
-               for (i = 0; i < countof(commands); i++)
+               if (streq(type, "rpc"))
                {
-                       if (streq(commands[i].name, command))
+                       rpc = xpc_dictionary_get_string(request, "rpc");
+                       if (rpc)
                        {
-                               reply = commands[i].handler(this, request, client);
-                               if (reply)
+                               for (i = 0; i < countof(commands); i++)
                                {
-                                       xpc_connection_send_message(client, reply);
-                                       xpc_release(reply);
+                                       if (streq(commands[i].name, rpc))
+                                       {
+                                               found = TRUE;
+                                               reply = commands[i].handler(this, request, client);
+                                               if (reply)
+                                               {
+                                                       xpc_connection_send_message(client, reply);
+                                                       xpc_release(reply);
+                                               }
+                                               break;
+                                       }
                                }
-                               break;
                        }
+                       if (!found)
+                       {
+                               DBG1(DBG_CFG, "received unknown XPC rpc command: %s", rpc);
+                       }
+               }
+               else
+               {
+                       DBG1(DBG_CFG, "received unknown XPC message type: %s", type);
                }
        }
+       else
+       {
+               DBG1(DBG_CFG, "received XPC message without a type");
+       }
 }
 
 /**