ZOOM C refactor. Make helper ZOOM_send_GDU
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 21 Nov 2012 13:57:28 +0000 (14:57 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 21 Nov 2012 13:57:28 +0000 (14:57 +0100)
src/zoom-c.c
src/zoom-p.h
src/zoom-sru.c
src/zoom-z3950.c

index 2445215..2b6b80f 100644 (file)
@@ -1549,15 +1549,26 @@ static zoom_ret send_HTTP_redirect(ZOOM_connection c, const char *uri,
         z_HTTP_header_add_basic_auth(c->odr_out, &gdu->u.HTTP_Request->headers,
                                      c->user, c->password);
     }
-    if (!z_GDU(c->odr_out, &gdu, 0, 0))
+    return ZOOM_send_GDU(c, gdu);
+}
+
+zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu)
+{
+    ZOOM_Event event;
+
+    int r = z_GDU(c->odr_out, &gdu, 0, 0);
+    if (!r)
         return zoom_complete;
     if (c->odr_print)
         z_GDU(c->odr_print, &gdu, 0, 0);
     if (c->odr_save)
         z_GDU(c->odr_save, &gdu, 0, 0);
     c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
-
     odr_reset(c->odr_out);
+
+    event = ZOOM_Event_create(ZOOM_EVENT_SEND_APDU);
+    ZOOM_connection_put_event(c, event);
+
     return ZOOM_send_buf(c);
 }
 
index be1107e..9113242 100644 (file)
@@ -283,6 +283,7 @@ void ZOOM_set_HTTP_error(ZOOM_connection c, int error,
 ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c);
 void ZOOM_connection_remove_events(ZOOM_connection c);
 void ZOOM_Event_destroy(ZOOM_Event event);
+zoom_ret ZOOM_send_GDU(ZOOM_connection c, Z_GDU *gdu);
 
 /*
  * Local variables:
index 687ca83..836f69e 100644 (file)
@@ -34,7 +34,6 @@ static void set_SRU_error(ZOOM_connection c, Z_SRW_diagnostic *d)
 static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr)
 {
     Z_GDU *gdu;
-    ZOOM_Event event;
     const char *database =  ZOOM_options_get(c->options, "databaseName");
 
     gdu = z_get_HTTP_Request_uri(c->odr_out, c->host_port,
@@ -57,18 +56,7 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr)
     {
         yaz_solr_encode_request(gdu->u.HTTP_Request, sr, c->odr_out, c->charset);
     }
-    if (!z_GDU(c->odr_out, &gdu, 0, 0))
-        return zoom_complete;
-    if (c->odr_print)
-        z_GDU(c->odr_print, &gdu, 0, 0);
-    if (c->odr_save)
-        z_GDU(c->odr_save, &gdu, 0, 0);
-    c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
-
-    event = ZOOM_Event_create(ZOOM_EVENT_SEND_APDU);
-    ZOOM_connection_put_event(c, event);
-    odr_reset(c->odr_out);
-    return ZOOM_send_buf(c);
+    return ZOOM_send_GDU(c, gdu);
 }
 #endif
 
index 27a4d4e..b916115 100644 (file)
@@ -959,7 +959,6 @@ ZOOM_API(void)
     }
 }
 
-
 static void handle_Z3950_records(ZOOM_connection c, Z_Records *sr,
                                  int present_phase);