+/* ### I am not 100% about the memory management in this handler */
+int bend_delete(void *handle, bend_delete_rr *rr)
+{
+ Zfront_handle *zhandle = (Zfront_handle *)handle;
+ HV *href;
+ CV* handler_cv;
+ int i;
+ SV **temp;
+ SV *point;
+
+ dSP;
+ ENTER;
+ SAVETMPS;
+
+ href = newHV();
+ hv_store(href, "GHANDLE", 7, newSVsv(zhandle->ghandle), 0);
+ hv_store(href, "HANDLE", 6, zhandle->handle, 0);
+ hv_store(href, "STATUS", 6, newSViv(0), 0);
+
+ PUSHMARK(sp);
+ XPUSHs(sv_2mortal(newRV( (SV*) href)));
+ PUTBACK;
+
+ handler_cv = simpleserver_sv2cv(delete_ref);
+
+ if (rr->function == 1) {
+ /* Delete all result sets in the session */
+ perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
+ temp = hv_fetch(href, "STATUS", 6, 1);
+ rr->delete_status = SvIV(*temp);
+ } else {
+ rr->delete_status = 0;
+ /*
+ * For some reason, deleting two or more result-sets in
+ * one operation goes horribly wrong, and ### I don't have
+ * time to debug it right now.
+ */
+ if (rr->num_setnames > 1) {
+ rr->delete_status = 3; /* "System problem at target" */
+ /* There's no way to sent delete-msg using the GFS */
+ return 0;
+ }
+
+ for (i = 0; i < rr->num_setnames; i++) {
+ hv_store(href, "SETNAME", 7, newSVpv(rr->setnames[i], 0), 0);
+ perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
+ temp = hv_fetch(href, "STATUS", 6, 1);
+ rr->statuses[i] = SvIV(*temp);
+ if (rr->statuses[i] != 0)
+ rr->delete_status = rr->statuses[i];
+ }
+ }
+
+ SPAGAIN;
+
+ temp = hv_fetch(href, "HANDLE", 6, 1);
+ point = newSVsv(*temp);
+
+ hv_undef(href);
+
+ zhandle->handle = point;
+
+ sv_free( (SV*) href);
+
+ PUTBACK;
+ FREETMPS;
+ LEAVE;
+
+ return 0;
+}
+
+