implemented IKE/CHILD_SA termination through XML interface
authorMartin Willi <martin@strongswan.org>
Mon, 12 Nov 2007 15:06:04 +0000 (15:06 -0000)
committerMartin Willi <martin@strongswan.org>
Mon, 12 Nov 2007 15:06:04 +0000 (15:06 -0000)
src/charon/control/interfaces/xml_interface.c
src/charon/control/interfaces/xml_interface.xml

index 02da106..7a44c03 100644 (file)
@@ -283,6 +283,49 @@ static void request_query_ikesa(xmlTextReaderPtr reader, xmlTextWriterPtr writer
        xmlTextWriterEndElement(writer);
 }
 
+
+/**
+ * process a *terminate control request message
+ */
+static void request_control_terminate(xmlTextReaderPtr reader,
+                                                                         xmlTextWriterPtr writer, bool ike)
+{
+    while (xmlTextReaderRead(reader))
+    {
+               if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT)
+               {
+                       if (streq(xmlTextReaderConstName(reader), "id"))
+                       {
+                       if (xmlTextReaderRead(reader) &&
+                               xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT)
+                       {
+                                       const char *str;
+                                       u_int32_t id;
+                               
+                                       str = xmlTextReaderConstValue(reader);
+                                       if (str == NULL || !(id = atoi(str)))
+                                       {
+                                               DBG1(DBG_CFG, "error parsing XML id string");
+                                               break;
+                                       }
+                                       DBG1(DBG_CFG, "terminating %s_SA %d", ike ? "IKE" : "CHILD", id);
+                                       if (ike)
+                                       {
+                                               charon->interfaces->terminate_ike(charon->interfaces,
+                                                                                       id, interface_manager_cb_empty, NULL);
+                                       }
+                                       else
+                                       {
+                                               charon->interfaces->terminate_child(charon->interfaces,
+                                                                                       id, interface_manager_cb_empty, NULL);
+                                       }
+                                       break;
+                               }
+                       }
+               }
+       }
+}
+
 /**
  * process a query request
  */
@@ -306,6 +349,33 @@ static void request_query(xmlTextReaderPtr reader, xmlTextWriterPtr writer)
 }
 
 /**
+ * process a control request
+ */
+static void request_control(xmlTextReaderPtr reader, xmlTextWriterPtr writer)
+{
+       /* <control> */
+       xmlTextWriterStartElement(writer, "control");
+    while (xmlTextReaderRead(reader))
+    {
+               if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT)
+               {
+                       if (streq(xmlTextReaderConstName(reader), "ikesaterminate"))
+                       {
+                               request_control_terminate(reader, writer, TRUE);
+                               break;
+                       }
+                       if (streq(xmlTextReaderConstName(reader), "childsaterminate"))
+                       {
+                               request_control_terminate(reader, writer, FALSE);
+                               break;
+                       }
+               }
+       }
+       /* </control> */
+       xmlTextWriterEndElement(writer);
+}
+
+/**
  * process a request message
  */
 static void request(xmlTextReaderPtr reader, char *id, int fd)
@@ -337,6 +407,11 @@ static void request(xmlTextReaderPtr reader, char *id, int fd)
                                request_query(reader, writer);
                                break;
                        }
+                       if (streq(xmlTextReaderConstName(reader), "control"))
+                       {
+                               request_control(reader, writer);
+                               break;
+                       }
                }
        }
        /*   </message> and close document */
index 466d95f..7eaf4ed 100644 (file)
                                                        <!-- others -->
                                                </element>
                                        </optional>
+                                       <optional>
+                                               <element name="control">
+                                                       <optional>
+                                                               <ref name="ControlRequestIkeTerminate"/>
+                                                       </optional>
+                                                       <optional>
+                                                               <ref name="ControlRequestChildTerminate"/>
+                                                       </optional>
+                                                       <!-- others -->
+                                               </element>
+                                       </optional>
                                        <!-- others -->
                                </group>
                                <group> 
@@ -55,7 +66,7 @@
                                                        <optional>
                                                                <element name="query">
                                                                        <optional>
-                                                                               <ref name="QueryResponseIkesa"/>
+                                                                               <ref name="ikesalist"/>
                                                                        </optional>
                                                                        <!-- others -->
                                                                </element>
                        </zeroOrMore>
                </element>
        </define>
+       <define name="ControlRequestIkeTerminate">
+               <element name="ikesaterminate">
+                       <element name="id">
+                               <data type="positiveInteger"/>
+                       </element>
+               </element>
+       </define>
+       <define name="ControlRequestChildTerminate">
+               <element name="childsaterminate">
+                       <element name="id">
+                               <data type="positiveInteger"/>
+                       </element>
+               </element>
+       </define>
        <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
        <!--                    identification and address                       -->
        <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->