LCOV - code coverage report
Current view: top level - zxid - zxidmkwsf.c (source / functions) Hit Total Coverage
Test: ZXID Code Coverage Lines: 186 201 92.5 %
Date: 2010-12-19 Functions: 27 28 96.4 %
Branches: 141 246 57.3 %

           Branch data     Line data    Source code
       1                 :            : /* zxidmkwsf.c  -  Handwritten nitty-gritty functions for constructing various elems
       2                 :            :  * Copyright (c) 2010 Sampo Kellomaki <sampo@iki.fi>, All Rights Reserved.
       3                 :            :  * Copyright (c) 2007-2009 Symlabs (symlabs@symlabs.com), All Rights Reserved.
       4                 :            :  * Author: Sampo Kellomaki (sampo@iki.fi)
       5                 :            :  * This is confidential unpublished proprietary source code of the author.
       6                 :            :  * NO WARRANTY, not even implied warranties. Contains trade secrets.
       7                 :            :  * Distribution prohibited unless authorized in writing.
       8                 :            :  * Licensed under Apache License 2.0, see file COPYING.
       9                 :            :  * $Id: zxidmkwsf.c,v 1.12 2009-11-24 23:53:40 sampo Exp $
      10                 :            :  *
      11                 :            :  * 12.1.2007, created --Sampo
      12                 :            :  * 7.10.2008, added documentation --Sampo
      13                 :            :  * 15.11.2009, added ID-WSF <lu:Status> --Sampo
      14                 :            :  * 25.5.2010, added SOAP fault, tas3:Status, error formatting --Sampo
      15                 :            :  */
      16                 :            : 
      17                 :            : #include "errmac.h"
      18                 :            : #include "zxid.h"
      19                 :            : #include "zxidconf.h"
      20                 :            : #include "saml2.h"
      21                 :            : #include "wsf.h"
      22                 :            : #include "c/zx-const.h"
      23                 :            : #include "c/zx-ns.h"
      24                 :            : #include "c/zx-data.h"
      25                 :            : 
      26                 :            : /* *** What correct API should look like? This is still in flux
      27                 :            :  * and the initial goal is just to make single query for single
      28                 :            :  * service. All other complicated options and multi service queries
      29                 :            :  * will come in later releases. */
      30                 :            : 
      31                 :            : /*() Create ID-WSF protocol <lu:Status> element, given various levels of error input.
      32                 :            :  *
      33                 :            :  * sc1:: First level status code
      34                 :            :  * sc2:: Second level status code, if any
      35                 :            :  * msg:: First level status message
      36                 :            :  * ref:: First level Status/@ref. Ref is used to point to culprit XML element, if any.
      37                 :            :  * returns:: lu:Status data structure with fields populated.
      38                 :            :  *
      39                 :            :  * See also: zxid_mk_fault() */
      40                 :            : 
      41                 :            : /* Called by:  zxid_di_query x2, zxid_idp_as_do x3, zxid_idp_map_nid2uid, zxid_imreq x6, zxid_mk_fault, zxid_mk_lu_Status, zxid_mk_tas3_status, zxid_ps_addent_invite x2, zxid_ps_resolv_id */
      42                 :            : struct zx_lu_Status_s* zxid_mk_lu_Status(zxid_conf* cf, struct zx_elem_s* father, const char* sc1, const char* sc2, const char* msg, const char* ref)
      43                 :         42 : {
      44                 :         42 :   struct zx_lu_Status_s* st = zx_NEW_lu_Status(cf->ctx,father);
      45         [ +  + ]:         42 :   st->code      = zx_dup_attr(cf->ctx, &st->gg, zx_code_ATTR, STRNULLCHKQ(sc1));
      46         [ +  + ]:         42 :   if (msg)
      47                 :          2 :     st->comment = zx_dup_attr(cf->ctx, &st->gg, zx_comment_ATTR, msg);
      48         [ +  + ]:         42 :   if (ref)
      49                 :          2 :     st->ref     = zx_dup_attr(cf->ctx, &st->gg, zx_ref_ATTR, ref);
      50         [ +  + ]:         42 :   if (sc2)
      51                 :          2 :     st->Status  = zxid_mk_lu_Status(cf, &st->gg, sc2, 0, 0, 0);
      52                 :         42 :   return st;
      53                 :            : }
      54                 :            : 
      55                 :            : /*() Create TAS3 application level Status (error) header. */
      56                 :            : 
      57                 :            : /* Called by:  zxid_get_fault_status */
      58                 :            : zxid_tas3_status* zxid_mk_tas3_status(zxid_conf* cf, struct zx_elem_s* father, const char* ctlpt, const char* sc1, const char* sc2, const char* msg, const char* ref)
      59                 :          6 : {
      60                 :          6 :   zxid_tas3_status* st = zx_NEW_tas3_Status(cf->ctx, father);
      61                 :          6 :   st->mustUnderstand = zx_ref_attr(cf->ctx, &st->gg, zx_e_mustUnderstand_ATTR, "0");
      62         [ +  + ]:          6 :   if (ref)
      63                 :          1 :     st->ref          = zx_dup_attr(cf->ctx, &st->gg, zx_ref_ATTR, ref);
      64         [ +  + ]:          6 :   if (ctlpt)
      65                 :          5 :     st->ctlpt        = zx_dup_attr(cf->ctx, &st->gg, zx_ctlpt_ATTR, ctlpt);
      66         [ +  + ]:          6 :   if (msg)
      67                 :          1 :     st->comment      = zx_dup_attr(cf->ctx, &st->gg, zx_comment_ATTR, msg);
      68         [ +  + ]:          6 :   st->code           = zx_dup_attr(cf->ctx, &st->gg, zx_code_ATTR, STRNULLCHKQ(sc1));
      69         [ +  + ]:          6 :   if (sc2)
      70                 :          1 :     st->Status       = zxid_mk_lu_Status(cf, &st->gg, sc2, 0, 0, 0);
      71                 :          6 :   return st;
      72                 :            : }
      73                 :            : 
      74                 :            : /*() Create SOAP Fault element (see Table 2 of [SOAPBind2], pp.12-13)
      75                 :            :  *
      76                 :            :  * fa:: Optional fault actor, such as one of the TAS3 control points (ctlpt)
      77                 :            :  * fc:: Fault code. Should be "e:Client" or "e:Server".
      78                 :            :  * fs:: Fault string. Human readable string explanation of the fault.
      79                 :            :  * sc1:: First level status code (to be placed inside <detail> element)
      80                 :            :  * sc2:: Second level status code, if any
      81                 :            :  * msg:: First level status message
      82                 :            :  * ref:: First level Status/@ref. Ref is used to point to culprit XML element, if any.
      83                 :            :  * returns:: Fault data structure with fields populated.
      84                 :            :  *
      85                 :            :  * See also: zxid_mk_lu_Status()
      86                 :            :  */
      87                 :            : 
      88                 :            : /* Called by:  zxid_call_epr x2, zxid_timestamp_chk x2, zxid_wsc_prepare_call x2, zxid_wsc_valid_re_env x13, zxid_wsf_validate_a7n x6, zxid_wsp_decorate x2, zxid_wsp_validate x2, zxid_wsp_validate_env x12 */
      89                 :            : zxid_fault* zxid_mk_fault(zxid_conf* cf, struct zx_elem_s* father, const char* fa, const char* fc, const char* fs, const char* sc1, const char* sc2, const char* msg, const char* ref)
      90                 :          3 : {
      91                 :          3 :   zxid_fault* flt = zx_NEW_e_Fault(cf->ctx, father);
      92         [ +  - ]:          3 :   if (sc1) {
      93                 :          3 :     flt->detail = zx_NEW_e_detail(cf->ctx, &flt->gg);
      94                 :          3 :     flt->detail->Status = zxid_mk_lu_Status(cf, &flt->detail->gg, sc1, sc2, msg, ref);
      95                 :            :   }
      96         [ +  - ]:          3 :   if (fa)
      97                 :          3 :     flt->faultactor  = zx_dup_elem(cf->ctx, &flt->gg, zx_e_faultactor_ELEM, fa);
      98         [ +  - ]:          3 :   flt->faultstring   = zx_dup_elem(cf->ctx, &flt->gg, zx_e_faultstring_ELEM, fs?fs:"Unknown");
      99         [ +  - ]:          3 :   flt->faultcode     = zx_dup_elem(cf->ctx, &flt->gg, zx_e_faultcode_ELEM,fc?fc:"e:Client");
     100                 :          3 :   return flt;
     101                 :            : }
     102                 :            : 
     103                 :            : /*() Set current fault of the session. If current fault is set, the zxid_wsp_decorate()
     104                 :            :  * function will generate a SOAP Fault response instead of normal SOAP response. If
     105                 :            :  * you wish to return application response in situation where fault has been
     106                 :            :  * detected, you can use this function to reset the current fault to null. */
     107                 :            : 
     108                 :            : /* Called by:  zxid_call_epr x2, zxid_timestamp_chk x2, zxid_wsc_prepare_call x2, zxid_wsc_valid_re_env x14, zxid_wsf_validate_a7n x6, zxid_wsp_decorate x2, zxid_wsp_validate x2, zxid_wsp_validate_env x13 */
     109                 :         59 : void zxid_set_fault(zxid_conf* cf, zxid_ses* ses, zxid_fault* flt) {
     110         [ -  + ]:         59 :   if (ses->curflt) /* Free the previous fault */
     111                 :          0 :     zx_free_elem(cf->ctx, &ses->curflt->gg, 1);
     112                 :         59 :   ses->curflt = flt;
     113                 :         59 : }
     114                 :            : 
     115                 :            : /*() Read current fault of the session. NULL return means that there was no fault. */
     116                 :            : 
     117                 :            : /* Called by: */
     118                 :          1 : zxid_fault* zxid_get_fault(zxid_conf* cf, zxid_ses* ses) {
     119                 :          1 :   return ses->curflt;
     120                 :            : }
     121                 :            : 
     122                 :            : /* Called by:  zxid_get_fault_status */
     123                 :          2 : char* zxid_get_tas3_fault_sc1(zxid_conf* cf, zxid_fault* flt) {
     124   [ +  +  +  -  :          2 :   if (!flt || !ZX_SIMPLE_ELEM_CHK(flt->faultcode))
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     125                 :          1 :     return 0;
     126   [ +  -  +  -  :          1 :   return zx_str_to_c(cf->ctx, ZX_GET_CONTENT(flt->faultcode));
                   +  - ]
     127                 :            : }
     128                 :            : /* Called by: */
     129                 :          2 : char* zxid_get_tas3_fault_sc2(zxid_conf* cf, zxid_fault* flt) {
     130   [ +  +  +  -  :          2 :   if (!flt || !flt->detail || !flt->detail->Status || !flt->detail->Status->code || !flt->detail->Status->code->g.s)
          +  -  +  -  -  
                      + ]
     131                 :          1 :     return 0;
     132                 :          1 :   return zx_str_to_c(cf->ctx, &flt->detail->Status->code->g);
     133                 :            : }
     134                 :            : /* Called by:  zxid_get_fault_status */
     135                 :          2 : char* zxid_get_tas3_fault_comment(zxid_conf* cf, zxid_fault* flt) {
     136   [ +  +  +  -  :          2 :   if (!flt || !ZX_SIMPLE_ELEM_CHK(flt->faultstring))
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     137                 :          1 :     return 0;
     138   [ +  -  +  -  :          1 :   return zx_str_to_c(cf->ctx, ZX_GET_CONTENT(flt->faultstring));
                   +  - ]
     139                 :            : }
     140                 :            : /* Called by: */
     141                 :          2 : char* zxid_get_tas3_fault_ref(zxid_conf* cf, zxid_fault* flt) {
     142   [ +  +  +  -  :          2 :   if (!flt || !flt->detail || !flt->detail->Status || !flt->detail->Status->ref || !flt->detail->Status->ref->g.s)
          +  -  +  -  -  
                      + ]
     143                 :          1 :     return 0;
     144                 :          1 :   return zx_str_to_c(cf->ctx, &flt->detail->Status->ref->g);
     145                 :            : }
     146                 :            : /* Called by:  zxid_get_fault_status */
     147                 :          2 : char* zxid_get_tas3_fault_actor(zxid_conf* cf, zxid_fault* flt) {
     148   [ +  +  +  -  :          2 :   if (!flt || !ZX_SIMPLE_ELEM_CHK(flt->faultactor))
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     149                 :          1 :     return 0;
     150   [ +  -  +  -  :          1 :   return zx_str_to_c(cf->ctx, ZX_GET_CONTENT(flt->faultactor));
                   +  - ]
     151                 :            : }
     152                 :            : 
     153                 :            : /* Called by: */
     154                 :          0 : zxid_tas3_status* zxid_get_fault_status(zxid_conf* cf, zxid_fault* flt) {
     155                 :            :   zxid_tas3_status* st;
     156   [ #  #  #  #  :          0 :   if (!flt || !flt->detail || !flt->detail->Status)
                   #  # ]
     157                 :          0 :     return 0;
     158                 :          0 :   st = zxid_mk_tas3_status(cf, 0,
     159                 :            :                            zxid_get_tas3_fault_actor(cf, flt),
     160                 :            :                            zxid_get_tas3_fault_sc1(cf, flt),
     161                 :            :                            0,
     162                 :            :                            zxid_get_tas3_fault_comment(cf, flt),
     163                 :            :                            0);
     164                 :          0 :   st->Status = flt->detail->Status;
     165                 :          0 :   return st;
     166                 :            : }
     167                 :            : 
     168                 :            : /*() Set current TAS3 Status of the session. If current Status is set,
     169                 :            :  * the zxid_wsp_decorate() function will generate a TAS3 status
     170                 :            :  * header. */
     171                 :            : 
     172                 :            : /* Called by:  zxid_wsc_valid_re_env, zxid_wsp_validate_env */
     173                 :         62 : void zxid_set_tas3_status(zxid_conf* cf, zxid_ses* ses, zxid_tas3_status* status) {
     174   [ +  +  -  + ]:         62 :   D("curstatus=%p status=%p", ses->curstatus, status);
     175         [ +  + ]:         62 :   if (ses->curstatus) /* Free the previous fault */
     176                 :          5 :     zx_free_elem(cf->ctx, &ses->curstatus->gg, 0);
     177                 :         62 :   ses->curstatus = status;
     178                 :         62 : }
     179                 :            : 
     180                 :            : /*() Read current fault of the session. NULL return means that there was no fault. */
     181                 :            : 
     182                 :            : /* Called by: */
     183                 :          1 : zxid_tas3_status* zxid_get_tas3_status(zxid_conf* cf, zxid_ses* ses) {
     184                 :          1 :   return ses->curstatus;
     185                 :            : }
     186                 :            : 
     187                 :            : /* Called by: */
     188                 :          2 : char* zxid_get_tas3_status_sc1(zxid_conf* cf, zxid_tas3_status* st) {
     189   [ +  +  +  -  :          2 :   if (!st || !st->code || !st->code->g.s)
                   -  + ]
     190                 :          1 :     return 0;
     191                 :          1 :   return zx_str_to_c(cf->ctx, &st->code->g);
     192                 :            : }
     193                 :            : /* Called by: */
     194                 :          2 : char* zxid_get_tas3_status_sc2(zxid_conf* cf, zxid_tas3_status* st) {
     195   [ +  +  +  -  :          2 :   if (!st || !st->Status || !st->Status->code || !st->Status->code->g.s)
             +  -  -  + ]
     196                 :          1 :     return 0;
     197                 :          1 :   return zx_str_to_c(cf->ctx, &st->Status->code->g);
     198                 :            : }
     199                 :            : /* Called by: */
     200                 :          2 : char* zxid_get_tas3_status_comment(zxid_conf* cf, zxid_tas3_status* st) {
     201   [ +  +  +  -  :          2 :   if (!st || !st->comment || !st->comment->g.s)
                   -  + ]
     202                 :          1 :     return 0;
     203                 :          1 :   return zx_str_to_c(cf->ctx, &st->comment->g);
     204                 :            : }
     205                 :            : /* Called by: */
     206                 :          2 : char* zxid_get_tas3_status_ref(zxid_conf* cf, zxid_tas3_status* st) {
     207   [ +  +  +  -  :          2 :   if (!st || !st->ref || !st->ref->g.s)
                   -  + ]
     208                 :          1 :     return 0;
     209                 :          1 :   return zx_str_to_c(cf->ctx, &st->ref->g);
     210                 :            : }
     211                 :            : /* Called by: */
     212                 :          2 : char* zxid_get_tas3_status_ctlpt(zxid_conf* cf, zxid_tas3_status* st) {
     213   [ +  +  -  +  :          2 :   if (!st || !st->ctlpt || !st->ctlpt->g.s)
                   #  # ]
     214                 :          2 :     return 0;
     215                 :          0 :   return zx_str_to_c(cf->ctx, &st->ctlpt->g);
     216                 :            : }
     217                 :            : 
     218                 :            : /*() Low level constructor for discovery <di:RequestedService>. */
     219                 :            : 
     220                 :            : /* Called by:  zxid_mk_di_query */
     221                 :            : static struct zx_di_RequestedService_s* zxid_mk_di_req_svc(zxid_conf* cf, struct zx_elem_s* father, int req_id, const char* svc_type, const char* url, const char* di_opt, const char* action)
     222                 :         16 : {
     223                 :         16 :   struct zx_di_RequestedService_s* rs = zx_NEW_di_RequestedService(cf->ctx, father);
     224         [ +  - ]:         16 :   if (svc_type)
     225                 :         16 :     rs->ServiceType = zx_ref_elem(cf->ctx, &rs->gg, zx_di_ServiceType_ELEM, svc_type);
     226         [ +  + ]:         16 :   if (url)
     227                 :          1 :     rs->ProviderID = zx_ref_elem(cf->ctx, &rs->gg, zx_di_ProviderID_ELEM, url);
     228         [ -  + ]:         16 :   if (di_opt) {
     229                 :          0 :     rs->Options = zx_NEW_di_Options(cf->ctx, &rs->gg);
     230                 :            :     /* N.B: We adopt here a simplification that there can only be one option, but it
     231                 :            :      * can be fully generic URI, including a query string. If it is desireable to
     232                 :            :      * support additional options, dollar ($) could be used as a separator. */
     233                 :          0 :     rs->Options->Option = zx_ref_elem(cf->ctx, &rs->Options->gg, zx_di_Option_ELEM, di_opt);
     234                 :            :   }
     235                 :            : #if 0
     236                 :            :   rs->reqID = zx_strf(cf->ctx, "RS%x", req_id);
     237                 :            :   rs->resultType = zx_ref_str(cf->ctx, "all");  /* OPTIONAL: "best", "only-one" */
     238                 :            :   rs->SecurityMechID = zx_ref_elem(cf->ctx, &rs->gg, zx_di_SecurityMechID_ELEM, WSF20_SEC_MECH_TLS_BEARER);
     239                 :            :   rs->SecurityMechID = zx_ref_elem(cf->ctx, &rs->gg, zx_di_SecurityMechID_ELEM, WSF20_SEC_MECH_TLS_SAML2);
     240                 :            : #endif
     241                 :         16 :   rs->Framework = zx_NEW_di_Framework(cf->ctx, &rs->gg);
     242                 :         16 :   rs->Framework->version = zx_ref_attr(cf->ctx, &rs->Framework->gg, zx_version_ATTR, "2.0");  /* Request specific framework, omit=any */
     243         [ -  + ]:         16 :   if (action)
     244                 :          0 :     rs->Action = zx_ref_elem(cf->ctx, &rs->gg, zx_di_Action_ELEM, action);
     245                 :         16 :   zx_reverse_elem_lists(&rs->gg);
     246                 :         16 :   return rs;
     247                 :            : }
     248                 :            : 
     249                 :            : /*() Low level constructor for discovery <di:Query>. */
     250                 :            : 
     251                 :            : /* Called by:  main x2, zxid_get_epr */
     252                 :            : struct zx_di_Query_s* zxid_mk_di_query(zxid_conf* cf, struct zx_elem_s* father, const char* svc_type, const char* url, const char* di_opt, const char* action)
     253                 :         16 : {
     254                 :         16 :   struct zx_di_Query_s* q = zx_NEW_di_Query(cf->ctx, father);
     255                 :         16 :   q->RequestedService = zxid_mk_di_req_svc(cf, &q->gg, 1, svc_type, url, di_opt, action);
     256                 :         16 :   return q;
     257                 :            : }
     258                 :            : 
     259                 :            : /*() Low level constructor for WSA <Address>. */
     260                 :            : 
     261                 :            : /* Called by:  zxid_wsc_prep, zxid_wsf_decor */
     262                 :            : struct zx_a_Address_s* zxid_mk_addr(zxid_conf* cf, struct zx_elem_s* father, struct zx_str* url)
     263                 :         38 : {
     264                 :         38 :   struct zx_a_Address_s* addr = zx_NEW_a_Address(cf->ctx, father);
     265                 :         38 :   zx_add_content(cf->ctx, &addr->gg, url);
     266                 :         38 :   return addr;
     267                 :            : }
     268                 :            : 
     269                 :            : /* --------------- DAP: Select and QueryItem -------------- */
     270                 :            : 
     271                 :            : /*() Low level constructor for <dap:Select>. */
     272                 :            : 
     273                 :            : /* Called by:  main x4 */
     274                 :            : struct zx_dap_Select_s* zxid_mk_dap_select(zxid_conf* cf, struct zx_elem_s* father, char* dn, char* filter, char* attributes, int derefaliases, int scope, int sizelimit, int timelimit, int typesonly)
     275                 :          2 : {
     276                 :          2 :   struct zx_dap_Select_s* sel = zx_NEW_dap_Select(cf->ctx, father);
     277         [ -  + ]:          2 :   if (dn)           sel->dn = zx_ref_elem(cf->ctx, &sel->gg, zx_dap_dn_ELEM, dn);
     278         [ -  + ]:          2 :   if (filter)       sel->filter = zx_ref_elem(cf->ctx, &sel->gg, zx_dap_filter_ELEM, filter);
     279         [ -  + ]:          2 :   if (attributes)   sel->attributes = zx_ref_attr(cf->ctx, &sel->gg, zx_attributes_ATTR, attributes);
     280         [ -  + ]:          2 :   if (derefaliases) sel->derefaliases = zx_attrf(cf->ctx, &sel->gg, zx_derefaliases_ATTR, "%d", derefaliases);
     281         [ +  - ]:          2 :   if (scope)        sel->scope = zx_attrf(cf->ctx, &sel->gg, zx_scope_ATTR, "%d", scope);
     282         [ -  + ]:          2 :   if (sizelimit)    sel->sizelimit = zx_attrf(cf->ctx, &sel->gg, zx_sizelimit_ATTR, "%d", sizelimit);
     283         [ -  + ]:          2 :   if (timelimit)    sel->timelimit = zx_attrf(cf->ctx, &sel->gg, zx_timelimit_ATTR, "%d", timelimit);
     284         [ -  + ]:          2 :   if (typesonly)    sel->typesonly = zx_ref_attr(cf->ctx, &sel->gg, zx_typesonly_ATTR, XML_TRUE);
     285                 :          2 :   return sel;
     286                 :            : }
     287                 :            : 
     288                 :            : /*() Low level constructor for <dap:QueryItem>. */
     289                 :            : 
     290                 :            : /* Called by:  main x3 */
     291                 :            : struct zx_dap_QueryItem_s* zxid_mk_dap_query_item(zxid_conf* cf, struct zx_elem_s* father, struct zx_dap_Select_s* sel, char* objtype, char* predef, char* sort, char* changed_since, int incl_common_attr, int offset, int count, char* setreq, char* setid, char* contingent_itemidref)
     292                 :          1 : {
     293                 :          1 :   struct zx_dap_QueryItem_s* qi = zx_NEW_dap_QueryItem(cf->ctx, father);
     294                 :          1 :   qi->Select = sel;
     295         [ -  + ]:          1 :   if (objtype)       qi->objectType = zx_ref_attr(cf->ctx, &qi->gg, zx_objectType_ATTR, objtype);
     296         [ -  + ]:          1 :   if (changed_since) qi->changedSince = zx_ref_attr(cf->ctx, &qi->gg, zx_changedSince_ATTR, changed_since);
     297         [ -  + ]:          1 :   if (predef)        qi->predefined = zx_ref_attr(cf->ctx, &qi->gg, zx_predefined_ATTR, predef);
     298         [ -  + ]:          1 :   if (sort)          qi->Sort = zx_ref_elem(cf->ctx, &qi->gg, zx_dap_Sort_ELEM, sort);
     299                 :            : 
     300                 :            : #if 0
     301                 :            :   /* ID-DAP specification only allows ChangeFormat == "currentElements"
     302                 :            :    * and in fact recommends omitting it altogether. */
     303                 :            :   if (changed_elems)
     304                 :            :     qi->ChangeFormat = zx_ref_elem(cf->ctx, &qi->gg, zx_dap_ChangeFormat_ELEM, "changedElements");
     305                 :            :   if (curr_elems) {
     306                 :            :     if (qi->ChangeFormat)
     307                 :            :       qi->ChangeFormat->g.n = (struct zx_node_s*)zx_ref_elem(cf->ctx, &qi->gg, zx_dap_ChangeFormat_ELEM, "currentElements");
     308                 :            :     else
     309                 :            :       qi->ChangeFormat = zx_ref_elem(cf->ctx, &qi->gg, zx_dap_ChangeFormat_ELEM, "currentElements");
     310                 :            :   }
     311                 :            : #endif
     312                 :            : 
     313         [ +  - ]:          1 :   if (incl_common_attr) qi->includeCommonAttributes = zx_ref_attr(cf->ctx, &qi->gg, zx_includeCommonAttributes_ATTR, XML_TRUE);
     314         [ +  - ]:          1 :   if (offset)           qi->offset = zx_attrf(cf->ctx, &qi->gg, zx_offset_ATTR, "%d", offset);
     315         [ +  - ]:          1 :   if (count)            qi->count  = zx_attrf(cf->ctx, &qi->gg, zx_count_ATTR,  "%d", count);
     316                 :            :   
     317         [ -  + ]:          1 :   if (setreq) qi->setReq = zx_ref_attr(cf->ctx, &qi->gg, zx_setReq_ATTR, setreq);  /* Request new set */
     318         [ -  + ]:          1 :   if (setid)  qi->setID  = zx_ref_attr(cf->ctx, &qi->gg, zx_setID_ATTR, setid);    /* Continue to use existing set */
     319                 :            :   
     320                 :          1 :   qi->itemID = zxid_mk_id_attr(cf, &qi->gg, zx_itemID_ATTR, "qi", ZXID_ID_BITS);
     321                 :            :   
     322         [ -  + ]:          1 :   if (contingent_itemidref) {
     323                 :          0 :     qi->itemIDRef = zx_ref_attr(cf->ctx, &qi->gg, zx_itemIDRef_ATTR, contingent_itemidref);
     324                 :          0 :     qi->contingency = zx_ref_attr(cf->ctx, &qi->gg, zx_contingency_ATTR, XML_TRUE);
     325                 :            :   }
     326                 :          1 :   return qi;
     327                 :            : }
     328                 :            : 
     329                 :            : /* --------------- DAP: Test -------------- */
     330                 :            : 
     331                 :            : /*() Low level constructor for <dap:TestOp>. */
     332                 :            : 
     333                 :            : /* Called by:  main */
     334                 :            : struct zx_dap_TestOp_s* zxid_mk_dap_testop(zxid_conf* cf, struct zx_elem_s* father, char* dn, char* filter, char* attributes, int derefaliases, int scope, int sizelimit, int timelimit, int typesonly)
     335                 :          1 : {
     336                 :          1 :   struct zx_dap_TestOp_s* sel = zx_NEW_dap_TestOp(cf->ctx, father);
     337         [ -  + ]:          1 :   if (dn)           sel->dn = zx_ref_elem(cf->ctx, &sel->gg, zx_dap_dn_ELEM, dn);
     338         [ -  + ]:          1 :   if (filter)       sel->filter = zx_ref_elem(cf->ctx, &sel->gg, zx_dap_filter_ELEM, filter);
     339         [ -  + ]:          1 :   if (attributes)   sel->attributes = zx_ref_attr(cf->ctx, &sel->gg, zx_attributes_ATTR, attributes);
     340         [ +  - ]:          1 :   if (derefaliases) sel->derefaliases = zx_attrf(cf->ctx, &sel->gg, zx_derefaliases_ATTR, "%d", derefaliases);
     341         [ +  - ]:          1 :   if (scope)        sel->scope = zx_attrf(cf->ctx, &sel->gg, zx_scope_ATTR, "%d", scope);
     342         [ +  - ]:          1 :   if (sizelimit)    sel->sizelimit = zx_attrf(cf->ctx, &sel->gg, zx_sizelimit_ATTR, "%d", sizelimit);
     343         [ +  - ]:          1 :   if (timelimit)    sel->timelimit = zx_attrf(cf->ctx, &sel->gg, zx_timelimit_ATTR, "%d", timelimit);
     344         [ +  - ]:          1 :   if (typesonly)    sel->typesonly = zx_ref_attr(cf->ctx, &sel->gg, zx_typesonly_ATTR, XML_TRUE);
     345                 :          1 :   return sel;
     346                 :            : }
     347                 :            : 
     348                 :            : /*() Low level constructor for <dap:TestItem>. */
     349                 :            : 
     350                 :            : /* Called by:  main */
     351                 :            : struct zx_dap_TestItem_s* zxid_mk_dap_test_item(zxid_conf* cf, struct zx_elem_s* father, struct zx_dap_TestOp_s* top, char* objtype, char* predef)
     352                 :          1 : {
     353                 :          1 :   struct zx_dap_TestItem_s* ti = zx_NEW_dap_TestItem(cf->ctx, father);
     354                 :          1 :   ti->TestOp = top;
     355                 :          1 :   ti->id = ti->itemID = zxid_mk_id_attr(cf, &ti->gg, zx_id_ATTR, "ti", ZXID_ID_BITS);
     356         [ -  + ]:          1 :   if (objtype) ti->objectType = zx_ref_attr(cf->ctx, &ti->gg, zx_objectType_ATTR, objtype);
     357         [ -  + ]:          1 :   if (predef)  ti->predefined = zx_ref_attr(cf->ctx, &ti->gg, zx_predefined_ATTR, predef);
     358                 :          1 :   return ti;
     359                 :            : }
     360                 :            : 
     361                 :            : /* --------------- DAP: ResultQuery and Subscription -------------- */
     362                 :            : 
     363                 :            : /*() Low level constructor for <dap:ResultQuery>. */
     364                 :            : 
     365                 :            : /* Called by:  main */
     366                 :            : struct zx_dap_ResultQuery_s* zxid_mk_dap_resquery(zxid_conf* cf, struct zx_elem_s* father, struct zx_dap_Select_s* sel, char* objtype, char* predef, char* sort, char* changed_since, int incl_common_attr, char* contingent_itemidref)
     367                 :          1 : {
     368                 :          1 :   struct zx_dap_ResultQuery_s* qi = zx_NEW_dap_ResultQuery(cf->ctx, father);
     369                 :          1 :   qi->Select = sel;
     370         [ -  + ]:          1 :   if (changed_since) qi->changedSince = zx_ref_attr(cf->ctx, &qi->gg, zx_changedSince_ATTR, changed_since);
     371         [ -  + ]:          1 :   if (objtype)       qi->objectType = zx_ref_attr(cf->ctx, &qi->gg, zx_objectType_ATTR, objtype);
     372         [ -  + ]:          1 :   if (predef)        qi->predefined = zx_ref_attr(cf->ctx, &qi->gg, zx_predefined_ATTR, predef);
     373         [ -  + ]:          1 :   if (sort)          qi->Sort = zx_ref_elem(cf->ctx, &qi->gg, zx_dap_Sort_ELEM, sort);
     374                 :            : 
     375                 :            : #if 0
     376                 :            :   /* ID-DAP specification only allows ChangeFormat == "currentElements"
     377                 :            :    * and in fact recommends omitting it altogether. */
     378                 :            :   if (changed_elems)
     379                 :            :     qi->ChangeFormat = zx_ref_elem(cf->ctx, &qi->gg, zx_dap_ChangeFormat_ELEM, "changedElements");
     380                 :            :   if (curr_elems) {
     381                 :            :     if (qi->ChangeFormat)
     382                 :            :       qi->ChangeFormat->g.n = (struct zx_node_s*)zx_ref_elem(cf->ctx, &qi->gg, zx_dap_ChangeFormat_ELEM, "currentElements");
     383                 :            :     else
     384                 :            :       qi->ChangeFormat = zx_ref_elem(cf->ctx, &qi->gg, zx_dap_ChangeFormat_ELEM, "currentElements");
     385                 :            :   }
     386                 :            : #endif
     387                 :            :   
     388         [ +  - ]:          1 :   if (incl_common_attr)
     389                 :          1 :     qi->includeCommonAttributes = zx_ref_attr(cf->ctx, &qi->gg, zx_includeCommonAttributes_ATTR, XML_TRUE);
     390                 :            :   
     391                 :          1 :   qi->itemID = zxid_mk_id_attr(cf, &qi->gg, zx_itemID_ATTR, "qi", ZXID_ID_BITS);
     392                 :            :   
     393         [ -  + ]:          1 :   if (contingent_itemidref) {
     394                 :          0 :     qi->itemIDRef = zx_ref_attr(cf->ctx, &qi->gg, zx_itemIDRef_ATTR, contingent_itemidref);
     395                 :          0 :     qi->contingency = zx_ref_attr(cf->ctx, &qi->gg, zx_contingency_ATTR, XML_TRUE);
     396                 :            :   }
     397                 :          1 :   return qi;
     398                 :            : }
     399                 :            : 
     400                 :            : /*() Low level constructor for <dap:Subscription>. */
     401                 :            : 
     402                 :            : /* Called by:  main */
     403                 :            : struct zx_dap_Subscription_s* zxid_mk_dap_subscription(zxid_conf* cf, struct zx_elem_s* father, char* subsID, char* itemidref, struct zx_dap_ResultQuery_s* rq, char* aggreg, char* trig, char* starts, char* expires, int incl_data, char* admin_notif, char* notify_ref)
     404                 :          1 : {
     405                 :          1 :   struct zx_dap_Subscription_s* subs = zx_NEW_dap_Subscription(cf->ctx, father);
     406         [ +  - ]:          1 :   if (itemidref) {
     407                 :          1 :     subs->RefItem = zx_NEW_subs_RefItem(cf->ctx, &subs->gg);
     408                 :          1 :     subs->RefItem->itemIDRef = zx_ref_attr(cf->ctx, &subs->RefItem->gg, zx_itemIDRef_ATTR, itemidref);
     409         [ +  - ]:          1 :     if (subsID)
     410                 :          1 :       subs->RefItem->subscriptionID = zx_ref_attr(cf->ctx, &subs->RefItem->gg, zx_subscriptionID_ATTR, subsID);
     411                 :            :   }
     412                 :          1 :   subs->ResultQuery = rq;
     413         [ -  + ]:          1 :   if (aggreg)  subs->Aggregation = zx_ref_elem(cf->ctx, &subs->gg, zx_dap_Aggregation_ELEM, aggreg);
     414         [ -  + ]:          1 :   if (trig)    subs->Trigger = zx_ref_elem(cf->ctx, &subs->gg, zx_dap_Trigger_ELEM, trig);
     415         [ -  + ]:          1 :   if (starts)  subs->starts = zx_ref_attr(cf->ctx, &subs->gg, zx_starts_ATTR, starts);
     416         [ -  + ]:          1 :   if (expires) subs->expires = zx_ref_attr(cf->ctx, &subs->gg, zx_expires_ATTR, expires);
     417         [ +  - ]:          1 :   if (incl_data)   subs->includeData = zx_ref_attr(cf->ctx, &subs->gg, zx_includeData_ATTR, XML_TRUE);
     418         [ -  + ]:          1 :   if (admin_notif) subs->adminNotifyToRef = zx_ref_attr(cf->ctx, &subs->gg, zx_adminNotifyToRef_ATTR, admin_notif);
     419         [ -  + ]:          1 :   if (notify_ref)  subs->notifyToRef = zx_ref_attr(cf->ctx, &subs->gg, zx_notifyToRef_ATTR, notify_ref);
     420                 :          1 :   subs->subscriptionID = zxid_mk_id_attr(cf, &subs->gg, zx_subscriptionID_ATTR, "subs", ZXID_ID_BITS);;
     421                 :          1 :   return subs;
     422                 :            : }
     423                 :            : 
     424                 :            : /* --------------- DAP: Query -------------- */
     425                 :            : 
     426                 :            : /*() Low level constructor for <dap:Query>. */
     427                 :            : 
     428                 :            : /* Called by:  main x3 */
     429                 :            : struct zx_dap_Query_s* zxid_mk_dap_query(zxid_conf* cf, struct zx_elem_s* father, struct zx_dap_TestItem_s* tis, struct zx_dap_QueryItem_s* qis, struct zx_dap_Subscription_s* subs)
     430                 :          1 : {
     431                 :          1 :   struct zx_dap_Query_s* q = zx_NEW_dap_Query(cf->ctx, father);
     432                 :          1 :   q->TestItem = tis;
     433                 :          1 :   q->QueryItem = qis;
     434                 :          1 :   q->Subscription = subs;
     435                 :          1 :   q->itemID = zx_ref_attr(cf->ctx, &q->gg, zx_itemID_ATTR, "QRY");
     436                 :          1 :   return q;
     437                 :            : }
     438                 :            : 
     439                 :            : /* EOF  --  zxidmkwsf.c */

Generated by: LCOV version 1.9