[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Implement DNS SRV record into the bridge driver



On 08/10/2011 10:13 PM, Daniel Veillard wrote:
On Tue, Aug 09, 2011 at 05:50:55PM +0200, Michal Novotny wrote:
+    char *portString = NULL;
+    char *priorityString = NULL;
+    char *weightString = NULL;
+    int port;
+    int priority;
+    int weight;
+    int ret = 0;
+
+    if (!(service = virXMLPropString(cur, "service"))) {
+        virNetworkReportError(VIR_ERR_XML_DETAIL,
+                              "%s", _("Missing required service attribute in dns srv record"));
+        goto error;
+    }
+    if (!(protocol = virXMLPropString(cur, "protocol"))) {
+        virNetworkReportError(VIR_ERR_XML_DETAIL,
+                              _("Missing required protocol attribute in dns srv record '%s'"), service);
+        goto error;
+    }
+
+    target = virXMLPropString(cur, "target");
+    domain = virXMLPropString(cur, "domain");
+    portString = virXMLPropString(cur, "port");
+    priorityString = virXMLPropString(cur, "priority");
+    weightString = virXMLPropString(cur, "weight");
+
+    if (VIR_REALLOC_N(def->srvrecords, def->nsrvrecords + 1)<  0) {
+        virReportOOMError();
+        goto error;
+    }
+
+    if (portString&&
+        virStrToLong_i(portString, NULL, 10,&port)<  0) {
+        virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("Cannot parse 'port' attribute"));
+        goto error;
+    }
+
+    if (priorityString&&
+        virStrToLong_i(priorityString, NULL, 10,&priority)<  0) {
+        virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("Cannot parse 'priority' attribute"));
+        goto error;
+    }
+
+    if (weightString&&
+        virStrToLong_i(weightString, NULL, 10,&weight)<  0) {
+        virNetworkReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("Cannot parse 'weight' attribute"));
+        goto error;
+    }

   Hum, using virXPathInt() using the XPath expressions "@port",
   "@priority" and "@weight" would probably allow to simplify all this
   quite a bit, but you would have to extend virNetworkDNSDefParseXML()
   to carry the xpath context from virNetworkDefParseXML() and
   update the node for it.

A nice side effect would be that it would get the ctxt passed down through virNetworkDNSDefParseXML(), which could then use virXPathNodeSet to get the list of all srv records (and txt records and host records) at once, rather than picking them out in a loop. (not for doing now, but would be a nice cleanup in the future).



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]