Example #1
0
void GWEN_XMLNode_SetCharValue(GWEN_XMLNODE *n,
                               const char *name,
                               const char *value) {
  if (name && *name) {
    GWEN_XMLNODE *nn;

    nn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, name);
    if (value) {
      GWEN_XMLNODE *nnn;

      nnn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, value);
      GWEN_XMLNode_AddChild(nn, nnn);
    }
    GWEN_XMLNode_AddChild(n, nn);
  }
  else {
    GWEN_XMLNODE *nn;

    nn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, value);
    GWEN_XMLNode_AddChild(n, nn);
  }
}
Example #2
0
void GWEN_XMLNode_AddChildrenOnly(GWEN_XMLNODE *n, GWEN_XMLNODE *nn,
                                  int copythem) {
  GWEN_XMLNODE *ch;

  assert(n);
  assert(nn);

  ch=GWEN_XMLNode_GetChild(nn);
  while(ch) {
    GWEN_XMLNODE *nc;

    nc=GWEN_XMLNode_Next(ch);
    if (!copythem) {
      GWEN_XMLNode_UnlinkChild(nn, ch);
      GWEN_XMLNode_AddChild(n, ch);
    }
    else {
      GWEN_XMLNode_AddChild(n, GWEN_XMLNode_dup(ch));
    }
    ch=nc;
  } /* while */
}
Example #3
0
GWEN_XMLNODE *GWEN_XMLNode_dup(const GWEN_XMLNODE *n) {
  GWEN_XMLNODE *nn, *cn, *ncn;
  const GWEN_XMLPROPERTY *p;
  const GWEN_XMLNODE_NAMESPACE *nns;

  /* duplicate node itself */
  nn=GWEN_XMLNode_new(n->type, n->data);
  if (n->nameSpace)
    nn->nameSpace=strdup(n->nameSpace);

  /* duplicate properties */
  p=n->properties;
  while(p) {
    GWEN_XMLPROPERTY *np;

    np=GWEN_XMLProperty_dup(p);
    GWEN_XMLProperty_add(np, &(nn->properties));
    p=p->next;
  } /* while */

  /* duplicate children */
  cn=GWEN_XMLNode_List_First(n->children);
  while(cn) {
    ncn=GWEN_XMLNode_dup(cn);
    GWEN_XMLNode_AddChild(nn, ncn);
    cn=GWEN_XMLNode_Next(cn);
  } /* while */

  /* duplicate headers */
  cn=GWEN_XMLNode_List_First(n->headers);
  while(cn) {
    ncn=GWEN_XMLNode_dup(cn);
    GWEN_XMLNode_AddHeader(nn, ncn);
    cn=GWEN_XMLNode_Next(cn);
  } /* while */

  /* duplicate namespaces */
  nns=GWEN_XMLNode_NameSpace_List_First(n->nameSpaces);
  while(nns) {
    GWEN_XMLNODE_NAMESPACE *nnns;

    nnns=GWEN_XMLNode_NameSpace_dup(nns);
    GWEN_XMLNode_NameSpace_List_Add(nnns, nn->nameSpaces);
    nns=GWEN_XMLNode_NameSpace_List_Next(nns);
  }

  return nn;
}
Example #4
0
int GWEN_DBIO_XmlDb__ExportGroup(GWEN_DBIO *dbio,
				 GWEN_DB_NODE *data,
				 GWEN_XMLNODE *node,
				 const char *newName) {
  const char *s;
  GWEN_XMLNODE *n;
  GWEN_DB_NODE *dbT;
  int rv;

  if (newName)
    s=newName;
  else
    s=GWEN_DB_GroupName(data);
  assert(s && *s);

  n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, s);
  GWEN_XMLNode_SetProperty(n, "type", "group");
  GWEN_XMLNode_AddChild(node, n);

  /* store variables */
  dbT=GWEN_DB_GetFirstVar(data);
  while(dbT) {
    if (!(GWEN_DB_GetNodeFlags(dbT) & GWEN_DB_NODE_FLAGS_VOLATILE)) {
      rv=GWEN_DBIO_XmlDb__ExportVar(dbio, dbT, n);
      if (rv) {
	DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
	return rv;
      }
    }
    dbT=GWEN_DB_GetNextVar(dbT);
  }

  /* store groups */
  dbT=GWEN_DB_GetFirstGroup(data);
  while(dbT) {
    if (!(GWEN_DB_GetNodeFlags(dbT) & GWEN_DB_NODE_FLAGS_VOLATILE)) {
      rv=GWEN_DBIO_XmlDb__ExportGroup(dbio, dbT, n, 0);
      if (rv) {
	DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
	return rv;
      }
    }
    dbT=GWEN_DB_GetNextGroup(dbT);
  }

  return 0;
}
Example #5
0
void GWEN_Param_WriteXml(const GWEN_PARAM *p_struct, GWEN_XMLNODE *p_db)
{
  assert(p_struct);
  /* member "name" */
  GWEN_XMLNode_SetCharValue(p_db, "name", p_struct->name);

  /* member "flags" */
  GWEN_XMLNode_SetIntValue(p_db, "flags", p_struct->flags);

  /* member "type" */
  GWEN_XMLNode_SetCharValue(p_db, "type", GWEN_Param_Type_toString(p_struct->type));

  /* member "dataType" */
  GWEN_XMLNode_SetCharValue(p_db, "dataType", GWEN_Param_DataType_toString(p_struct->dataType));

  /* member "shortDescription" */
  GWEN_XMLNode_SetCharValue(p_db, "shortDescription", p_struct->shortDescription);

  /* member "longDescription" */
  GWEN_XMLNode_SetCharValue(p_db, "longDescription", p_struct->longDescription);

  /* member "currentValue" */
  GWEN_XMLNode_SetCharValue(p_db, "currentValue", p_struct->currentValue);

  /* member "defaultValue" */
  GWEN_XMLNode_SetCharValue(p_db, "defaultValue", p_struct->defaultValue);

  /* member "choices" */
  if (p_struct->choices) {
    GWEN_XMLNODE *n;
    n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "choices");
    GWEN_StringList2_toXml(p_struct->choices, n);
    GWEN_XMLNode_AddChild(p_db, n);
  }

  /* member "internalIntValue" is volatile, not writing to xml */

  /* member "internalFloatValue" is volatile, not writing to xml */

  /* member "runtimeFlags" is volatile, not writing to xml */

}
Example #6
0
int GWEN_XMLNode_SetCharValueByPath(GWEN_XMLNODE *n, uint32_t flags,
                                    const char *name,
                                    const char *value) {
  GWEN_XMLNODE *nn;

  nn=GWEN_XMLNode_GetNodeByXPath(n, name, 0);
  if (nn) {
    GWEN_XMLNODE *nnn;

    /* clear current entries */
    if (flags & GWEN_XML_PATH_FLAGS_OVERWRITE_VALUES)
      GWEN_XMLNode_List_Clear(nn->children);

    /* create value node */
    nnn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, value);
    GWEN_XMLNode_AddChild(nn, nnn);

    return 0;
  }
  else {
    DBG_ERROR(GWEN_LOGDOMAIN, "Unable to create node [%s]", name);
    return GWEN_ERROR_INVALID;
  }
}
Example #7
0
int GWEN_DBIO_XmlDb__ExportVar(GWEN_DBIO *dbio,
			       GWEN_DB_NODE *data,
			       GWEN_XMLNODE *node) {
  const char *s;
  GWEN_XMLNODE *n;
  GWEN_DB_NODE *dbT;
  int rv;

  s=GWEN_DB_VariableName(data);
  assert(s && *s);

  n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, s);
  GWEN_XMLNode_SetProperty(n, "type", "var");
  GWEN_XMLNode_AddChild(node, n);

  /* store variables */
  dbT=GWEN_DB_GetFirstValue(data);
  while(dbT) {
    if (!(GWEN_DB_GetNodeFlags(dbT) & GWEN_DB_NODE_FLAGS_VOLATILE)) {
      GWEN_DB_NODE_TYPE vt;
      GWEN_XMLNODE *vn;
  
      vt=GWEN_DB_GetValueType(dbT);
      switch(vt) {
  
      case GWEN_DB_NodeType_ValueChar:
	s=GWEN_DB_GetCharValueFromNode(dbT);
	if (s && *s) {
	  GWEN_XMLNODE *dn;
          GWEN_BUFFER *tbuf;

	  vn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "value");
	  GWEN_XMLNode_SetProperty(vn, "type", "char");
	  GWEN_XMLNode_AddChild(n, vn);

	  tbuf=GWEN_Buffer_new(0, 64, 0, 1);
	  rv=GWEN_Text_EscapeXmlToBuffer(s, tbuf);
	  if (rv<0) {
	    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
	    GWEN_Buffer_free(tbuf);
            return rv;
	  }
	  dn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, GWEN_Buffer_GetStart(tbuf));
          GWEN_Buffer_free(tbuf);
	  GWEN_XMLNode_AddChild(vn, dn);
	}
	break;
  
      case GWEN_DB_NodeType_ValueInt: {
	char nbuf[32];
	GWEN_XMLNODE *dn;

	snprintf(nbuf, sizeof(nbuf), "%i", GWEN_DB_GetIntValueFromNode(dbT));

	vn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "value");
	GWEN_XMLNode_SetProperty(vn, "type", "int");
	GWEN_XMLNode_AddChild(n, vn);

	dn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData, nbuf);
	GWEN_XMLNode_AddChild(vn, dn);

	break;
      }
  
      case GWEN_DB_NodeType_ValueBin: {
	const void *vp;
	unsigned int vsize;
  
	vp=GWEN_DB_GetBinValueFromNode(dbT, &vsize);
	if (vp && vsize) {
	  GWEN_BUFFER *bbuf;
	  GWEN_XMLNODE *dn;
  
	  bbuf=GWEN_Buffer_new(0, vsize*2, 0, 1);
	  rv=GWEN_Text_ToHexBuffer((const char*)vp,
				   vsize,
				   bbuf,
				   0, 0, 0);
	  if (rv) {
	    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
	    GWEN_Buffer_free(bbuf);
	    return rv;
	  }
  
	  vn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "value");
	  GWEN_XMLNode_SetProperty(vn, "type", "bin");
	  GWEN_XMLNode_AddChild(n, vn);
  
	  dn=GWEN_XMLNode_new(GWEN_XMLNodeTypeData,
			      GWEN_Buffer_GetStart(bbuf));
	  GWEN_Buffer_free(bbuf);
	  GWEN_XMLNode_AddChild(vn, dn);
	}
  
	break;
      }
  
      case GWEN_DB_NodeType_ValuePtr:
	DBG_DEBUG(GWEN_LOGDOMAIN, "Not storing pointer value");
	break;
  
      default:
	DBG_ERROR(GWEN_LOGDOMAIN,
		  "Unsupported variable type %d",
		  vt);
	return GWEN_ERROR_INVALID;
      }
    } /* if non-volatile */

    dbT=GWEN_DB_GetNextValue(dbT);
  }

  return 0;
}
Example #8
0
void* GWEN_XMLNode_HandlePath(const char *entry,
                              void *data,
                              int idx,
                              uint32_t flags) {
  GWEN_XMLNODE *n;
  GWEN_XMLNODE *nn;
  int i;

  n=(GWEN_XMLNODE*)data;

  if (flags & GWEN_PATH_FLAGS_VARIABLE) {
    DBG_ERROR(GWEN_LOGDOMAIN,
              "GWEN_PATH_FLAGS_VARIABLE not allowed for XPATH");
    return 0;
  }

  if (flags & GWEN_PATH_FLAGS_ROOT) {
    while(n->parent)
      n=n->parent;
    if (*entry=='/')
      entry++;
  }

  if (strcasecmp(entry, "..")==0) {
    return n->parent;
  }
  else if (strcasecmp(entry, ".")==0 ||
           strcasecmp(entry, "here()")==0) {
    return n;
  }

  /* check whether we are allowed to simply create the node */
  if (
    ((flags & GWEN_PATH_FLAGS_LAST) &&
     (((flags & GWEN_PATH_FLAGS_VARIABLE) &&
       (flags & GWEN_PATH_FLAGS_CREATE_VAR)) ||
      (!(flags & GWEN_PATH_FLAGS_VARIABLE) &&
       (flags & GWEN_PATH_FLAGS_CREATE_GROUP)))
    ) ||
    (
      !(flags & GWEN_PATH_FLAGS_LAST) &&
      (flags & GWEN_PATH_FLAGS_PATHCREATE))
  ) {
    /* simply create the new variable/group */
    if (flags & GWEN_PATH_FLAGS_VARIABLE) {
      /* not allowed for now */
      return 0;
    }
    else {
      if (idx!=0) {
        DBG_ERROR(GWEN_LOGDOMAIN,
                  "Can not create tag with index!=1 (%s)", entry);
        return 0;
      }
      DBG_VERBOUS(GWEN_LOGDOMAIN,
                  "Unconditionally creating tag \"%s\"", entry);
      nn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, entry);
      GWEN_XMLNode_AddChild(n, nn);
      return nn;
    }
  }

  /* find the node */
  i=idx;
  nn=GWEN_XMLNode_FindFirstTag(n, entry, 0, 0);
  while(nn && i--) {
    nn=GWEN_XMLNode_FindNextTag(nn, entry, 0, 0);
  }

  if (!nn) {
    /* node not found, check, if we are allowed to create it */
    if (
      (!(flags & GWEN_PATH_FLAGS_LAST) &&
       (flags & GWEN_PATH_FLAGS_PATHMUSTEXIST)) ||
      (flags & GWEN_PATH_FLAGS_NAMEMUSTEXIST)
    ) {
      DBG_VERBOUS(GWEN_LOGDOMAIN,
                  "Tag \"%s\" does not exist", entry);
      return 0;
    }
    /* create the new variable/group */
    if (idx!=0) {
      DBG_ERROR(GWEN_LOGDOMAIN,
                "Can not create tag with index!=1 (%s)", entry);
      return 0;
    }
    DBG_VERBOUS(GWEN_LOGDOMAIN,
                "Tag \"%s\" not found, creating", entry);
    nn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, entry);
    GWEN_XMLNode_AddChild(n, nn);
  } /* if node not found */
  else {
    /* node does exist, check whether this is ok */
    if (
      ((flags & GWEN_PATH_FLAGS_LAST) &&
       (flags & GWEN_PATH_FLAGS_NAMEMUSTNOTEXIST)) ||
      (!(flags & GWEN_PATH_FLAGS_LAST) &&
       (flags & GWEN_PATH_FLAGS_PATHMUSTNOTEXIST))
    ) {
      DBG_VERBOUS(GWEN_LOGDOMAIN, "Entry \"%s\" already exists", entry);
      return 0;
    }
  }

  return nn;
}
GWEN_DIALOG *AB_SetupNewUserDialog_new(AB_BANKING *ab) {
  GWEN_DIALOG *dlg;
  AB_SETUP_NEWUSER_DIALOG *xdlg;
  GWEN_BUFFER *fbuf;
  int rv;
  GWEN_XMLNODE *n;
  GWEN_XMLNODE *nDialog;
  GWEN_PLUGIN_DESCRIPTION_LIST2 *providers;
  GWEN_DIALOG_LIST *subDialogs=NULL;

  dlg=GWEN_Dialog_new("ab_setup_newuser");
  GWEN_NEW_OBJECT(AB_SETUP_NEWUSER_DIALOG, xdlg);
  GWEN_INHERIT_SETDATA(GWEN_DIALOG, AB_SETUP_NEWUSER_DIALOG, dlg, xdlg,
		       AB_SetupNewUserDialog_FreeData);
  GWEN_Dialog_SetSignalHandler(dlg, AB_SetupNewUserDialog_SignalHandler);

  xdlg->backendDialogs=GWEN_Dialog_List2_new();
  xdlg->backendRadioNames=GWEN_StringList_new();
  xdlg->backendNames=GWEN_StringList_new();

  /* get path of dialog description file */
  fbuf=GWEN_Buffer_new(0, 256, 0, 1);
  rv=GWEN_PathManager_FindFile(AB_PM_LIBNAME, AB_PM_DATADIR,
			       "aqbanking/dialogs/dlg_setup_newuser.dlg",
			       fbuf);
  if (rv<0) {
    DBG_INFO(AQBANKING_LOGDOMAIN, "Dialog description file not found (%d).", rv);
    GWEN_Buffer_free(fbuf);
    GWEN_Dialog_free(dlg);
    return NULL;
  }

  /* read XML file, extend it */
  n=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "root");
  rv=GWEN_XML_ReadFile(n, GWEN_Buffer_GetStart(fbuf),
		       GWEN_XML_FLAGS_DEFAULT |
		       GWEN_XML_FLAGS_HANDLE_HEADERS);
  if (rv<0) {
    DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
    GWEN_XMLNode_free(n);
    GWEN_Buffer_free(fbuf);
    GWEN_Dialog_free(dlg);
    return NULL;
  }

  nDialog=GWEN_XMLNode_FindFirstTag(n, "dialog", NULL, NULL);
  if (nDialog==NULL) {
    DBG_INFO(AQBANKING_LOGDOMAIN, "Dialog element not found in XML file [%s]", GWEN_Buffer_GetStart(fbuf));
    GWEN_XMLNode_free(n);
    GWEN_Buffer_free(fbuf);
    GWEN_Dialog_free(dlg);
    return NULL;
  }

  providers=AB_Banking_GetProviderDescrs(ab);
  if (providers) {
    GWEN_XMLNODE *nBackendRadioWidget;

    nBackendRadioWidget=GWEN_XMLNode_FindFirstTag(nDialog, "widget", "name", "dialogVLayout");
    if (nBackendRadioWidget)
      nBackendRadioWidget=GWEN_XMLNode_FindFirstTag(nBackendRadioWidget, "widget", "name", "wiz_stack");
    if (nBackendRadioWidget)
      nBackendRadioWidget=GWEN_XMLNode_FindFirstTag(nBackendRadioWidget, "widget", "name", "backendRadioWidget");
    subDialogs=GWEN_Dialog_List_new();
    if (nBackendRadioWidget) {
      GWEN_PLUGIN_DESCRIPTION_LIST2_ITERATOR *pit;
  
      pit=GWEN_PluginDescription_List2_First(providers);
      if (pit) {
	GWEN_PLUGIN_DESCRIPTION *pd;
  
	pd=GWEN_PluginDescription_List2Iterator_Data(pit);
	while(pd) {
	  const char *name;
  
	  name=GWEN_PluginDescription_GetName(pd);
	  if (name && *name) {
	    AB_PROVIDER *pro;

	    pro=AB_Banking_GetProvider(ab, name);
	    if (pro) {
	      GWEN_DIALOG *cdlg;
	      GWEN_BUFFER *tbuf;
	      GWEN_XMLNODE *wn;
	      const char *s;

	      if (AB_Provider_GetFlags(pro) & AB_PROVIDER_FLAGS_HAS_USERTYPE_DIALOG) {
		cdlg=AB_ProviderGetUserTypeDialog(pro);
		if (cdlg==NULL) {
		  DBG_WARN(AQBANKING_LOGDOMAIN, "Backend [%s] does not return a userType dialog, using default", name);
		  cdlg=AB_UserTypePageDefaultDialog_new(ab);
		}
	      }
	      else
		cdlg=AB_UserTypePageDefaultDialog_new(ab);

	      tbuf=GWEN_Buffer_new(0, 256, 0, 1);
	      GWEN_Buffer_AppendString(tbuf, "backend_");
	      GWEN_Buffer_AppendString(tbuf, name);
	      GWEN_Buffer_AppendString(tbuf, "_radio");
    
	      wn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "widget");
	      GWEN_XMLNode_SetProperty(wn, "type", "radioButton");
	      GWEN_XMLNode_SetProperty(wn, "name", GWEN_Buffer_GetStart(tbuf));
	      GWEN_StringList_AppendString(xdlg->backendRadioNames, GWEN_Buffer_GetStart(tbuf), 0, 0);
	      GWEN_StringList_AppendString(xdlg->backendNames, name, 0, 0);
    
	      s=GWEN_PluginDescription_GetShortDescr(pd);
	      if (!(s && *s))
		s=name;
	      GWEN_XMLNode_SetProperty(wn, "text", I18N(s));
    
	      GWEN_XMLNode_SetProperty(wn, "groupId", "999999");
	      GWEN_XMLNode_SetProperty(wn, "flags", "fillX justifyLeft");
    
	      GWEN_XMLNode_AddChild(nBackendRadioWidget, wn);
	      GWEN_Dialog_List_Add(cdlg, subDialogs);
	    }
	    else {
	      DBG_ERROR(AQBANKING_LOGDOMAIN, "Could not activate backend [%s]", name);
	    }
	  }
  
	  pd=GWEN_PluginDescription_List2Iterator_Next(pit);
	}
	GWEN_PluginDescription_List2Iterator_free(pit);
      }
    }
    else {
      DBG_ERROR(AQBANKING_LOGDOMAIN, "Dialog description does not contain path [dialogVLayout/wiz_stack/backendRadioWidget]");
      GWEN_XMLNode_Dump(nDialog, 2);
      GWEN_XMLNode_free(n);
      GWEN_Buffer_free(fbuf);
      GWEN_Dialog_free(dlg);
      return NULL;
    }
  }

  /* read dialog from dialog description file */
  rv=GWEN_Dialog_ReadXml(dlg, nDialog);
  if (rv<0) {
    DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d).", rv);
    GWEN_Dialog_List_free(subDialogs);
    GWEN_XMLNode_free(n);
    GWEN_Buffer_free(fbuf);
    GWEN_Dialog_free(dlg);
    return NULL;
  }
  GWEN_XMLNode_free(n);
  GWEN_Buffer_free(fbuf);

  /* insert pages for each backend */
  if (GWEN_Dialog_List_GetCount(subDialogs)) {
    GWEN_DIALOG *cdlg;

    while ( (cdlg=GWEN_Dialog_List_First(subDialogs)) ) {
      GWEN_Dialog_List_Del(cdlg);
      DBG_NOTICE(AQBANKING_LOGDOMAIN, "Adding dialog %s", GWEN_Dialog_GetId(cdlg));
      rv=GWEN_Dialog_AddSubDialog(dlg, "wiz_stack", cdlg);
      if (rv<0) {
	DBG_INFO(AQBANKING_LOGDOMAIN, "here (%d)", rv);
        GWEN_Dialog_List_free(subDialogs);
	GWEN_Dialog_free(cdlg);
	GWEN_Dialog_free(dlg);
	return NULL;
      }
      GWEN_Dialog_List2_PushBack(xdlg->backendDialogs, cdlg);
    }
  }
  GWEN_Dialog_List_free(subDialogs);

  xdlg->banking=ab;

  /* done */
  return dlg;
}