Support Z_SortKey_sortAttributes in bend_sort. This one is for you Seb!
[simpleserver-moved-to-github.git] / SimpleServer.xs
index a09403f..778042d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: SimpleServer.xs,v 1.43 2006-04-21 07:30:15 sondberg Exp $ 
+ * $Id: SimpleServer.xs,v 1.45 2006-06-02 10:06:11 sondberg Exp $ 
  * ----------------------------------------------------------------------
  * 
  * Copyright (c) 2000-2004, Index Data.
@@ -445,6 +445,44 @@ static SV *rpn2perl(Z_RPNStructure *s)
 }
 
 
+/* Decode the Z_SortAttributes struct and store the whole thing into the
+ * hash by reference
+ */
+int simpleserver_ExpandSortAttributes (HV *sort_spec, Z_SortAttributes *sattr)
+{
+    WRBUF attrset_wr = wrbuf_alloc();
+    AV *list = newAV();
+    Z_AttributeList *attr_list = sattr->list;
+    int i;
+
+    oid2str(sattr->id, attrset_wr);
+    hv_store(sort_spec, "ATTRSET", 7,
+             newSVpv(attrset_wr->buf, attrset_wr->pos), 0);
+    wrbuf_free(attrset_wr, 1);
+
+    hv_store(sort_spec, "SORT_ATTR", 9, newRV( sv_2mortal( (SV*) list ) ), 0);
+
+    for (i = 0; i < attr_list->num_attributes; i++) 
+    {
+        Z_AttributeElement *attr = *attr_list->attributes++; 
+        HV *attr_spec = newHV();
+                
+        av_push(list, newRV( sv_2mortal( (SV*) attr_spec ) ));
+        hv_store(attr_spec, "ATTR_TYPE", 9, newSViv(*attr->attributeType), 0);
+
+        if (attr->which == Z_AttributeValue_numeric)
+        {
+            hv_store(attr_spec, "ATTR_VALUE", 10,
+                     newSViv(*attr->value.numeric), 0);
+        } else {
+            return 0;
+        }
+    }
+
+    return 1;
+}
+
+
 /* Decode the Z_SortKeySpec struct and store the whole thing in a perl hash */
 int simpleserver_SortKeySpecToHash (HV *sort_spec, Z_SortKeySpec *spec)
 {
@@ -487,9 +525,8 @@ int simpleserver_SortKeySpecToHash (HV *sort_spec, Z_SortKeySpec *spec)
         }
         else if (key->which == Z_SortKey_sortAttributes)
         {
-            Z_SortAttributes *attr = key->u.sortAttributes;
-
-            return 0;
+            return simpleserver_ExpandSortAttributes(sort_spec,
+                                                     key->u.sortAttributes);
         }
         else
         {
@@ -814,6 +851,7 @@ int bend_fetch(void *handle, bend_fetch_rr *rr)
 
        Z_RecordComposition *composition;
        Z_ElementSetNames *simple;
+       Z_CompSpec *complex;
        STRLEN length;
 
        dSP;
@@ -856,13 +894,29 @@ int bend_fetch(void *handle, bend_fetch_rr *rr)
                                rr->errcode = 26;
                        }
                }
+               else if (composition->which == Z_RecordComp_complex)
+               {
+                       if (composition->u.complex->generic &&
+
+                                       composition->u.complex->generic &&
+                                       composition->u.complex->generic->elementSpec &&
+                                       composition->u.complex->generic->elementSpec->which ==
+                                       Z_ElementSpec_elementSetName)
+                       {
+                               complex = composition->u.complex;
+                               hv_store(href, "COMP", 4,
+                                       newSVpv(complex->generic->elementSpec->u.elementSetName, 0), 0);
+                       }
+                       else
+                       {
+                               rr->errcode = 26;
+                               return 0;
+                       }
+               }
                else
                {
-                       /* This is where we end up in the case of
-                        * SRU.  Since record composition ("element
-                        * sets") are meaningless in SRU anyway, we
-                        * just skip this.
-                        */
+                       rr->errcode = 26;
+                       return;
                }
        }
 
@@ -974,6 +1028,7 @@ int bend_present(void *handle, bend_present_rr *rr)
        STRLEN len;
        Z_RecordComposition *composition;
        Z_ElementSetNames *simple;
+       Z_CompSpec *complex;
        char *ODR_errstr;
        char *ptr;
        Zfront_handle *zhandle = (Zfront_handle *)handle;
@@ -1012,10 +1067,29 @@ int bend_present(void *handle, bend_present_rr *rr)
                                return 0;
                        }
                }
+               else if (composition->which == Z_RecordComp_complex)
+               {
+                       if (composition->u.complex->generic &&
+
+                                       composition->u.complex->generic &&
+                                       composition->u.complex->generic->elementSpec &&
+                                       composition->u.complex->generic->elementSpec->which ==
+                                       Z_ElementSpec_elementSetName)
+                       {
+                               complex = composition->u.complex;
+                               hv_store(href, "COMP", 4,
+                                       newSVpv(complex->generic->elementSpec->u.elementSetName, 0), 0);
+                       }
+                       else
+                       {
+                               rr->errcode = 26;
+                               return 0;
+                       }
+               }
                else
                {
                        rr->errcode = 26;
-                       return 0;
+                       return;
                }
        }