Esempio n. 1
0
/*** wgtmenuVerify - allows the driver to check elsewhere in the tree
 *** to make sure that the conditions it requires for proper functioning
 *** are present - checking for other widgets that might be necessary,
 *** checking interface versions on widgets to be interacted with, etc.
 ***/
int
wgtmenuVerify(pWgtrVerifySession s)
    {
    pWgtrNode menu = s->CurrWidget;
    char* str;
    int i;
    int min_height = s->ClientInfo->ParagraphHeight + 4;

	if (menu->min_height < min_height) menu->min_height = min_height;

	if (menu->Parent && !strcmp(menu->Parent->Type, "widget/menu"))
	    {
	    menu->Flags |= WGTR_F_FLOATING;
	    if (wgtrGetPropertyType(menu, "popup") < 0)
		{
		str = "yes";
		wgtrAddProperty(menu, "popup", DATA_T_STRING, POD(&str), 0);
		}
	    if (wgtrGetPropertyType(menu, "direction") < 0)
		{
		str = "vertical";
		wgtrAddProperty(menu, "direction", DATA_T_STRING, POD(&str), 0);
		}
	    }
	if (wgtrGetPropertyValue(menu, "popup", DATA_T_STRING, POD(&str)) == 0)
	    {
	    if (!strcasecmp(str,"yes") || !strcasecmp(str,"true") || !strcasecmp(str,"on"))
		menu->Flags |= WGTR_F_FLOATING;
	    }
	else if (wgtrGetPropertyValue(menu, "popup", DATA_T_INTEGER, POD(&i)) == 0 && i)
	    menu->Flags |= WGTR_F_FLOATING;

    return 0;
    }
Esempio n. 2
0
/*** AddRule: add a declarative osrc rule to the generated document.
 ***/
int
htosrc_internal_AddRule(pHtSession s, pWgtrNode tree, char* treename, pWgtrNode sub_tree)
    {
    char ruletype[32];
    int query_delay;
    int min_chars;
    int trailing_wildcard;
    int leading_wildcard;
    char fieldname[64];
    char* ptr;
    pExpression code;

	/** Get type of rule **/
	if (wgtrGetPropertyValue(sub_tree, "ruletype", DATA_T_STRING, POD(&ptr)) != 0)
	    {
	    mssError(1, "HTOSRC", "ruletype is required for widget/osrc-rule");
	    return -1;
	    }
	strtcpy(ruletype, ptr, sizeof(ruletype));

	/** Handle the rule based on the type **/
	if (!strcmp(ruletype, "relationship"))
	    {
	    }
	else if (!strcmp(ruletype, "filter"))
	    {
	    trailing_wildcard = htrGetBoolean(sub_tree, "trailing_wildcard", 1);
	    leading_wildcard = htrGetBoolean(sub_tree, "leading_wildcard", 0);
	    if (wgtrGetPropertyValue(sub_tree, "min_chars", DATA_T_INTEGER, POD(&min_chars)) != 0)
		min_chars = 3;
	    if (wgtrGetPropertyValue(sub_tree, "query_delay", DATA_T_INTEGER, POD(&query_delay)) != 0)
		query_delay = 500;
	    if (wgtrGetPropertyValue(sub_tree, "fieldname", DATA_T_STRING, POD(&ptr)) == 0)
		strtcpy(fieldname, ptr, sizeof(fieldname));
	    else
		{
		mssError(1, "HTOSRC", "fieldname is required for widget/osrc-rule of type 'filter'");
		return -1;
		}

	    /** Get target **/
	    if (wgtrGetPropertyType(sub_tree,"value") == DATA_T_CODE)
		{
		wgtrGetPropertyValue(sub_tree,"value",DATA_T_CODE,POD(&code));
		htrAddExpression(s, treename, wgtrGetDName(sub_tree), code);
		}

	    /** Write the init line **/
	    htrAddScriptInit_va(s, "    nodes[\"%STR&SYM\"].AddRule('%STR&SYM', {dname:'%STR&SYM', field:'%STR&ESCQ', qd:%INT, mc:%INT, tw:%INT, lw:%INT});\n",
		    treename, ruletype, wgtrGetDName(sub_tree), fieldname, 
		    query_delay, min_chars, trailing_wildcard, leading_wildcard);
	    }
	else if (!strcmp(ruletype, "keying"))
	    {
	    }

    return 0;
    }
Esempio n. 3
0
int test_main(int, char **)
{
  test( 0,1234 ) ;
  test( 0.0,12.34 ) ;
  test( POD(0,0,0.0), POD('a',1234,56.78) ) ;
  test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ;

  return 0;
}
Esempio n. 4
0
/*** nht_internal_GetGeom() - deploy a snippet of javascript to the browser
 *** to fetch the window geometry and reload the application.
 ***/
int
nht_internal_GetGeom(pObject target_obj, pFile output)
    {
    char bgnd[128];
    char* ptr;
    int font_size = -1;
    char font_name[128];

	/** Font sizes have an impact here **/
	objGetAttrValue(target_obj, "font_size", DATA_T_INTEGER, POD(&font_size));
	if (font_size < 5 || font_size > 100) font_size = -1;
	if (objGetAttrValue(target_obj, "font_name", DATA_T_STRING, POD(&ptr)) == 0 && ptr)
	    strtcpy(font_name, ptr, sizeof(font_name));
	else
	    strcpy(font_name, "");

	/** Do we have a bgcolor / background? **/
	if (objGetAttrValue(target_obj, "bgcolor", DATA_T_STRING, POD(&ptr)) == 0)
	    {
	    snprintf(bgnd, sizeof(bgnd), "bgcolor='%.100s'", ptr);
	    }
	else if (objGetAttrValue(target_obj, "background", DATA_T_STRING, POD(&ptr)) == 0)
	    {
	    snprintf(bgnd, sizeof(bgnd), "background='%.100s'", ptr);
	    }
	else
	    {
	    strcpy(bgnd, "bgcolor='white'");
	    }

	/** Generate the snippet **/
	fdQPrintf(output,"<html>\n"
			 "<head>\n"
			 "    <meta http-equiv=\"Pragma\" CONTENT=\"no-cache\">\n"
			 "    <style type=\"text/css\">\n"
			 "        #l1 { POSITION:absolute; VISIBILITY: hidden; left:0px; top:0px; }\n"
			 "        #l2 { POSITION:absolute; VISIBILITY: hidden; left:0px; top:0px; }\n"
			 "        body { %[font-size:%POSpx; %]%[font-family:%STR&CSSVAL; %]}\n"
			 "    </style>\n"
			 "<script type=\"text/javascript\" language=\"javascript\" src=\"/sys/js/startup.js\"></script>\n"
			 "</head>\n"
			 "<body %STR onload='startup();'>\n"
			 "    <img src='/sys/images/loading.gif'>\n"
			 "    <div id=\"l1\">x<br>x</div>\n"
			 "    <div id=\"l2\">xx</div>\n"
			 "</body>\n"
			 "</html>\n", font_size > 0, font_size, *font_name, font_name, bgnd);

    return 0;
    }
Esempio n. 5
0
/*** hnt_internal_GetExpr() - gets an expression from an object
 ***/
pExpression
hnt_internal_GetExpr(pObject obj, char* attrname)
    {
    pExpression exp;
    int t;
    ObjData pod;

	/** Check data type **/
	t = objGetAttrType(obj, attrname);
	if (t < 0) return NULL;
	if (t == DATA_T_CODE)
	    {
	    /** Get code directly **/
	    if (objGetAttrValue(obj, attrname, t, POD(&exp)) != 0)
		return NULL;
	    exp = expDuplicateExpression(exp);
	    }
	else
	    {
	    /** Build exp from pod **/
	    if (objGetAttrValue(obj, attrname, t, &pod) != 0)
		return NULL;
	    exp = expPodToExpression(&pod, t, NULL);
	    }

    return exp;
    }
Esempio n. 6
0
/*** qyt_internal_ReadText() - attempt to read data from a 'text' type object
 *** that might have a 'content' property giving the object's content.
 ***/
int
qyt_internal_ReadText(pQytData inf, char* buffer, int maxcnt, int offset, int flags, pObjTrxTree* oxt)
    {
    pStructInf content_inf;
    int len;
    char* ptr;

	/** do we have content? **/
	content_inf = stLookup(inf->NodeData, "content");
	if (!content_inf)
	    {
	    mssError(1,"QYT","Text querytree object has no content");
	    return -1;
	    }

	/** ok, get our bearings... **/
	if (stGetAttrValue(content_inf, DATA_T_STRING, POD(&ptr), 0) != 0)
	    {
	    mssError(1,"QYT","Could not read content from text querytree object");
	    return -1;
	    }
	len = strlen(ptr);
	if (flags & OBJ_U_SEEK)
	    inf->Offset = offset;
	if (inf->Offset < 0) inf->Offset = 0;
	if (inf->Offset > len) inf->Offset = len;
	if (inf->Offset + maxcnt > len) maxcnt = len - inf->Offset;
	if (maxcnt <= 0) return 0;
	memcpy(buffer, ptr+inf->Offset, maxcnt);
	inf->Offset += maxcnt;

    return maxcnt;
    }
Esempio n. 7
0
/*** hnt_internal_GetString() - gets a string value 
 ***/
char*
hnt_internal_GetString(pObject obj, char* attrname)
    {
    char* str;

	if (objGetAttrValue(obj,attrname,DATA_T_STRING, POD(&str)) != 0)
	    return NULL;
	str = nmSysStrdup(str);

    return str;
    }
Esempio n. 8
0
/*** qyt_internal_GetQueryItem - finds the first(next) inf item in the .qyt
 *** file to include in this query.  Items to include are system/querytree
 *** type subitems that either have a source= or text= property.  Source=
 *** type subitems will result in zero or more items for the query.  Text=
 *** subitems will result in exactly one returned object for the query.
 *** Text= types cannot be modified/etc by the enduser.  The .qyt must be
 *** opened as a structure file (via objdrv_struct) to modify Text=items.
 *** modifications/addidions/deletions of query results from a Source=
 *** item will be passed on to the source driver (such as objdrv_sybase).
 ***/
int
qyt_internal_GetQueryItem(pQytQuery qy)
    {
    pStructInf main_inf;
    pStructInf find_inf;
    char* val;
    char* ptr;
    int t;

    	/** Already hit end of query? **/
	if (qy->NextSubInfID == -1) return -1;

	/** Need to 'prime' the struct table? **/
	if (qy->StructTable.nItems == 0)
	    {
	    find_inf = qy->ObjInf->NodeData;
	    while(find_inf)
	        {
		if (stStructType(find_inf) == ST_T_SUBGROUP) 
		    xhAdd(&qy->StructTable, find_inf->Name, (void*)find_inf);
		find_inf = find_inf->Parent;
		}
	    }

    	/** Search for a SOURCE= or TEXT= subgroup inf **/
	main_inf = qy->ObjInf->NodeData;

	/** Is main_inf already a 'recurse' node? **/
	/*if (stStructType(main_inf) == ST_T_ATTRIB && !strcmp(main_inf->Name, "recurse"))
	    {
	    stGetAttrValue(main_inf, DATA_T_STRING, POD(&ptr), 0);
	    find_inf = (pStructInf)xhLookup(&qy->StructTable, ptr);
	    if (find_inf) main_inf = find_inf;
	    }*/

	/** Do the search **/
	while(qy->NextSubInfID < main_inf->nSubInf)
	    {
	    find_inf = main_inf->SubInf[qy->NextSubInfID++];
	    if (stStructType(find_inf) == ST_T_ATTRIB && !strcmp(find_inf->Name, "recurse"))
	        {
		stGetAttrValue(find_inf, DATA_T_STRING, POD(&ptr), 0);
		find_inf = (pStructInf)xhLookup(&qy->StructTable, ptr);
		if (!find_inf) continue;
		}
	    qy->ItemText = NULL;
	    qy->ItemSrc = NULL;
	    qy->ItemWhere = NULL;
	    qy->ItemOrder = NULL;
	    qy->ItemSql = NULL;
	    if (qy->ItemSqlExpr)
		expFreeExpression(qy->ItemSqlExpr);
	    qy->ItemSqlExpr = NULL;
	    if (stStructType(find_inf) == ST_T_SUBGROUP)
	        {
		xhAdd(&qy->StructTable, find_inf->Name, (void*)find_inf);
		val = NULL;
		stAttrValue(stLookup(find_inf,"text"),NULL,&val,0);
		if (val)
		    {
		    qy->ItemText = val;
		    return qy->NextSubInfID - 1;
		    }
		stAttrValue(stLookup(find_inf,"source"),NULL,&val,0);
		if (val)
		    {
		    qy->ItemSrc = val;
		    stAttrValue(stLookup(find_inf,"where"),NULL,&(qy->ItemWhere),0);
		    stAttrValue(stLookup(find_inf,"order"),NULL,&(qy->ItemOrder),0);
		    return qy->NextSubInfID - 1;
		    }
		t = stGetAttrType(stLookup(find_inf,"sql"), 0);
		if (t == DATA_T_STRING)
		    {
		    stAttrValue(stLookup(find_inf,"sql"),NULL,&val,0);
		    if (val)
			{
			qy->ItemSql = val;
			return qy->NextSubInfID - 1;
			}
		    }
		else if (t == DATA_T_CODE)
		    {
		    stGetAttrValue(stLookup(find_inf,"sql"), DATA_T_CODE, POD(&qy->ItemSqlExpr), 0);
		    if (qy->ItemSqlExpr)
			{
			qy->ItemSqlExpr = expDuplicateExpression(qy->ItemSqlExpr);
			qy->ItemSql = "";
			return qy->NextSubInfID - 1;
			}
		    }
		}
	    }

	/** End of query. **/
	qy->NextSubInfID = -1;

    return -1;
    }
Esempio n. 9
0
/*** qyt_internal_ProcessPath - handles the lookup of the snNode from the given
 *** path in the querytree, and the optional creation of a new entity, as needed,
 *** manipulating the WHERE sql in the snNode to assign parent foreign key links
 *** and so forth.
 ***/
pQytData
qyt_internal_ProcessPath(pObjSession s, pPathname path, pSnNode node, int subref, pStructInf dptr, int openflags, int no_open)
    {
    pQytData inf;
    pStructInf lookup_inf, find_inf, next_inf;
    char* strval;
    char* exprval;
    char* ptr;
    int i,v,t;
    pExpression expr;
    pParamObjects objlist;
    pObject test_obj;
    XHashTable struct_table;
    XString sql;
    pObjQuery test_qy;
    char createpath[OBJSYS_MAX_PATH+1];

    	/** Setup the pathname into its subparts **/
	for(i=1;i<path->nElements;i++) path->Elements[i][-1] = 0;

    	/** Allocate the data info first **/
	inf = (pQytData)nmMalloc(sizeof(QytData));
	if (!inf) return NULL;
	memset(inf,0,sizeof(QytData));
	inf->BaseNode = node;
	inf->LLObj = NULL;
	inf->Offset = 0;

	/** Create the object parameter list... **/
        objlist = expCreateParamList();

	/** Initialize the listing of query tree elements **/
	xhInit(&struct_table, 17, 0);

	/** Look for the part of the structinf which this path references. **/
	while(subref < path->nElements)
	    {
	    /** Add a slot to the param object list for this tree level **/
	    objlist->ParentID = objlist->CurrentID;

	    /** Look for text and source items in the querytree definition. **/
	    next_inf = NULL;
	    for(i=0;i<dptr->nSubInf;i++) 
	        {
		find_inf = dptr->SubInf[i];
		if (stStructType(find_inf) == ST_T_SUBGROUP)
                    {
	    PROCESS_SUBGROUP:
                    inf->Pathname[0] = '\0';
		    inf->Flags = 0;
                    if ((lookup_inf = stLookup(find_inf, "text")))
                        {
                        strval = "";
                        stAttrValue(lookup_inf,NULL,&strval,0);
                        if (!strcmp(path->Elements[subref],strval))
                            {
			    expAddParamToList(objlist,strval,NULL,EXPR_O_CURRENT | EXPR_O_ALLOWDUPS);
                            next_inf = find_inf;
                            break;
                            }
                        if (subref == path->nElements - 1)
                            inf->LLObj = NULL;
                        }
                    else if ((lookup_inf = stLookup(find_inf, "sql")))
			{
			xhAdd(&struct_table, find_inf->Name, (void*)find_inf);

			/** not opening objects? skip sql query if so **/
			if (no_open)
			    {
			    next_inf = find_inf;
			    break;
			    }

			/** forced leaf flag and having clause flag **/
			strval = NULL;
			stAttrValue(stLookup(find_inf, "force_leaf"), NULL, &strval, 0);
			if (strval && !strcasecmp(strval,"yes"))
			    inf->Flags |= QYT_F_FLEAF;
			strval = NULL;
			stAttrValue(stLookup(find_inf, "use_having"), NULL, &strval, 0);
			if (strval && !strcasecmp(strval,"yes"))
			    inf->Flags |= QYT_F_USEHAVING;

			/** build and run the sql query to find the object **/
			expAddParamToList(objlist,find_inf->Name,NULL,EXPR_O_CURRENT | EXPR_O_ALLOWDUPS);
			xsInit(&sql);
			strval = "";
			expr = NULL;
			t = stGetAttrType(lookup_inf, 0);
			if (t == DATA_T_STRING)
			    {
			    stAttrValue(lookup_inf, NULL, &strval, 0);
			    }
			else if (t == DATA_T_CODE)
			    {
			    if (stGetAttrValue(lookup_inf, DATA_T_CODE, POD(&expr), 0) == 0)
				{
				expr = expDuplicateExpression(expr);
				if (expr)
				    {
				    objlist->Session = s;
				    expBindExpression(expr, objlist, EXPR_F_RUNSERVER);
				    if (expEvalTree(expr, objlist) == 0 && expr->DataType == DATA_T_STRING && !(expr->Flags & EXPR_F_NULL))
					strval = expr->String;
				    }
				}
			    }

			if (!strcmp(strval, ""))
			    {
			    if (expr) expFreeExpression(expr);
			    mssError(0,"QYT","Invalid SQL for '%s'",find_inf->Name);
			    goto error;
			    }

			xsQPrintf(&sql, "%STR %STR :name = %STR&DQUOT", strval, (inf->Flags & QYT_F_USEHAVING)?"HAVING":"WHERE", path->Elements[subref]);
			if (expr) expFreeExpression(expr);
			expr = NULL;

			test_obj = NULL;
			test_qy = objMultiQuery(s, sql.String, objlist, 0);
			if (test_qy)
			    {
			    /** sizeof(createpath)-2 to leave room for two chars **/
			    if (objGetQueryIdentityPath(test_qy, createpath, sizeof(createpath) - 2) < 0)
				createpath[0] = '\0';

			    /** query open succeeded, try to fetch a result **/
			    test_obj = objQueryFetch(test_qy, O_RDONLY);

			    /** are we creating a new object? **/
			    if (!test_obj && subref == path->nElements - 1 && (openflags & O_CREAT) && createpath[0])
				{
				/** We left room for these two chars in the
				 ** above call to objGetQueryIdentityPath().
				 **/
				strcat(createpath, "/*");
				test_obj = objOpen(s, createpath, O_RDWR | O_TRUNC | (openflags & (O_CREAT | OBJ_O_AUTONAME)), 0600, "system/file");
				}
			    objQueryClose(test_qy);
			    }
			xsDeInit(&sql);
			if (!test_obj)
			    continue;

			/** ok, found the object **/
			expModifyParam(objlist,NULL,test_obj);
			objUnmanageObject(test_obj->Session, test_obj);
                        if (subref == path->nElements - 1) 
			    {
                            inf->LLObj = objLinkTo(test_obj);
			    }
			next_inf = find_inf;
			break;
			}
                    else if ((lookup_inf = stLookup(find_inf, "source")))
                        {
                        strval = "";
                        stAttrValue(lookup_inf,NULL,&strval,0);
                        expr = NULL;
                        exprval = NULL;
                        stAttrValue(stLookup(find_inf, "where"),NULL,&exprval,0);
                        if (exprval && !no_open) 
			    {
			    //objlist->Names[(signed char)(objlist->CurrentID)] = find_inf->Name;
			    expr = (pExpression)expCompileExpression(exprval, objlist, MLX_F_ICASE | MLX_F_FILENAMES, 0);
			    }
                        snprintf(inf->Pathname,sizeof(inf->Pathname),"%s/%s?ls__type=application%%2foctet-stream",strval,path->Elements[subref]);

			/** forced leaf flag **/
			strval = NULL;
			stAttrValue(stLookup(find_inf, "force_leaf"), NULL, &strval, 0);
			if (strval && !strcasecmp(strval,"yes"))
			    inf->Flags |= QYT_F_FLEAF;
			strval = NULL;
			stAttrValue(stLookup(find_inf, "use_having"), NULL, &strval, 0);
			if (strval && !strcasecmp(strval,"yes"))
			    inf->Flags |= QYT_F_USEHAVING;

			/** Setup this querytree struct entry for lookups **/
			xhAdd(&struct_table, find_inf->Name, (void*)find_inf);
			expAddParamToList(objlist,find_inf->Name,NULL,EXPR_O_CURRENT | EXPR_O_ALLOWDUPS);

			/** Not opening any objects?  Skip open attempt if so. **/
			if (no_open)
			    {
			    next_inf = find_inf;
			    break;
			    }
    
                        /** Open the object, or create if need be.  If create, convert any WHERE to setattrs **/
                        test_obj = objOpen(s, inf->Pathname, O_RDONLY, 0600, "system/file");
			if (test_obj) 
			    {
			    expModifyParam(objlist, NULL, test_obj);
			    objUnmanageObject(test_obj->Session, test_obj);
			    }
                        if (!test_obj && subref == path->nElements - 1 && (openflags & O_CREAT))
                            {
                            test_obj = objOpen(s, inf->Pathname, O_RDWR | O_TRUNC | (openflags & (O_CREAT | OBJ_O_AUTONAME)), 0600, "system/file");
                            if (!test_obj)
				continue;
			    expModifyParam(objlist, NULL, test_obj);
			    objUnmanageObject(test_obj->Session, test_obj);
			    objlist->Flags[(signed char)(objlist->CurrentID)] |= EXPR_O_UPDATE;
                            if (expr)
                                {
				/** Reverse eval the expression to set the object attributes **/
				expr->Integer = 1;
				v = expReverseEvalTree(expr, objlist);
				expFreeExpression(expr);
				expr = NULL;
				if (v < 0)
				    {
				    objClose(test_obj);
				    expModifyParam(objlist, NULL, NULL);
				    break;
				    }
                                }
                            }
                        else if (!test_obj)
			    continue;
    
                        /** Validate the where clause expression if need be. **/
			objlist->Session = s;
                        v = !expr || (expEvalTree(expr,objlist) >= 0 && expr->Integer != 0);
                        if (expr) expFreeExpression(expr);
			expr = NULL;
                        if (subref == path->nElements - 1) 
			    {
                            inf->LLObj = objLinkTo(test_obj);
			    }
                        /*else 
			    {
                            if (!v) objClose(test_obj);
			    }*/
			if (v)
			    {
			    next_inf = find_inf;
			    break;
			    }
                        }
                    }
		else if (!strcmp(find_inf->Name,"recurse"))
		    {
		    expr = NULL;
		    exprval = NULL;
		    stAttrValue(stLookup(dptr, "known_leaf"),NULL,&exprval,0);
		    expAddParamToList(objlist,find_inf->Name,NULL,EXPR_O_CURRENT | EXPR_O_ALLOWDUPS);
		    if (exprval) 
			{
			expr = (pExpression)expCompileExpression(exprval, objlist, MLX_F_ICASE | MLX_F_FILENAMES, 0);
			if (!expr)
			    {
			    mssError(0,"QYT","Error in known_leaf expression");
			    break;
			    }
			else
			    {
			    v = (expEvalTree(expr,objlist) >= 0 && expr->Integer != 0);
			    expFreeExpression(expr);
			    expr = NULL;
			    if (v) break;
			    }
			}
		    expRemoveParamFromList(objlist, find_inf->Name);
		    stGetAttrValue(find_inf, DATA_T_STRING, POD(&ptr), 0);
		    find_inf = (pStructInf)xhLookup(&struct_table, ptr);
		    if (find_inf) goto PROCESS_SUBGROUP;
		    }
		}

	    /** Didn't find? **/
	    if (!next_inf) 
	        {
		inf->LLObj = NULL;
		mssError(0,"QYT","Could not find object via access through querytree");
		goto error;
		}
	    dptr = next_inf;
	    subref++;
	    }

	/** Ok, close up the structure table. **/
	xhClear(&struct_table, NULL, NULL);
	xhDeInit(&struct_table);

	inf->NodeData = dptr;
	inf->ObjList = objlist;

	return inf;

    error:
	/** Ok, close up the structure table. **/
	xhClear(&struct_table, NULL, NULL);
	xhDeInit(&struct_table);
	if (objlist)
	    {
	    for(i=0;i<objlist->nObjects-1;i++)
		if (objlist->Objects[i])
		    objClose(objlist->Objects[i]);
	    expFreeParamList(objlist);
	    }
	nmFree(inf,sizeof(QytData));

	return NULL;
    }
Esempio n. 10
0
/*** qytQueryFetch - get the next directory entry as an open object.
 ***/
void*
qytQueryFetch(void* qy_v, pObject obj, int mode, pObjTrxTree* oxt)
    {
    pQytQuery qy = ((pQytQuery)(qy_v));
    pQytData inf;
    pObject llobj = NULL;
    pStructInf find_inf;
    char* ptr;
    char* objname = NULL;
    int cur_id = -1;

	/** If text item, return it and go to next item, else look at sub query **/
	while(!objname && qy->NextSubInfID != -1)
	    {
	    cur_id = qy->NextSubInfID - 1;
	    if (qy->ItemText != NULL)
	        {
		qy->LLQuery = NULL;
	        objname = qy->ItemText;
	        qyt_internal_GetQueryItem(qy);
	        if (qy->NextSubInfID != -1 && (qy->ItemSrc != NULL || qy->ItemSql != NULL))
		    qy->LLQuery = qyt_internal_StartQuery(qy);
	        }
	    else
	        {
	        if (qy->LLQuery) 
		    {
		    llobj = objQueryFetch(qy->LLQuery, mode);
		    if (!llobj) 
		        {
			objQueryClose(qy->LLQuery);
			qy->LLQuery = NULL;
			if (qy->LLQueryObj)
			    {
			    objClose(qy->LLQueryObj);
			    qy->LLQueryObj = NULL;
			    }
			}
		    }
		if (!llobj)
		    {
	            qyt_internal_GetQueryItem(qy);
	            if (qy->NextSubInfID != -1 && (qy->ItemSrc != NULL || qy->ItemSql != NULL))
			qy->LLQuery = qyt_internal_StartQuery(qy);
		    }
		else
		    {
		    objGetAttrValue(llobj, "name", DATA_T_STRING,POD(&objname));
		    if (!objname)
			{
			/** Object is somehow invalid -- force a go-around to next fetch **/
			objClose(llobj);
			llobj = NULL;
			}
		    else
			{
			objUnmanageObject(llobj->Session, llobj);
			}
		    }
	        }
	    }

    	/** If end of query, return NULL. **/
	if (cur_id == -1 || !objname) return NULL;

	/** Build the filename. **/
	if (obj_internal_AddToPath(obj->Pathname, objname) < 0)
	    {
	    mssError(1,"QYT","Could not fetch object from querytree");
	    return NULL;
	    }

	/** Alloc the structure **/
	inf = qyt_internal_ProcessPath(obj->Session, obj->Pathname, qy->ObjInf->BaseNode, 
		qy->ObjInf->Obj->SubPtr, qy->ObjInf->BaseNode->Data, 0, 1);
	if (!inf)
	    return NULL;
	strcpy(inf->Pathname, obj_internal_PathPart(obj->Pathname, 0, 0));
	if (inf->LLObj)
	    objClose(inf->LLObj);
	inf->LLObj = llobj;
	inf->BaseNode = qy->ObjInf->BaseNode;

	/** Point to the correct structure file subgroup **/
	inf->NodeData = qy->ObjInf->NodeData->SubInf[cur_id];
	if (stStructType(inf->NodeData) == ST_T_ATTRIB && !strcmp(inf->NodeData->Name, "recurse"))
	    {
	    stGetAttrValue(inf->NodeData, DATA_T_STRING, POD(&ptr), 0);
	    find_inf = (pStructInf)xhLookup(&qy->StructTable, ptr);
	    if (find_inf) inf->NodeData = find_inf;
	    }

	inf->BaseNode->OpenCnt++;
	inf->Obj = obj;
	inf->Offset = 0;
	obj_internal_PathPart(obj->Pathname,0,0);

	/** Set up the param objects list for this fetched object. **/
	if (inf->ObjList)
	    expFreeParamList(inf->ObjList);
	inf->ObjList = expCreateParamList();
	expCopyList(qy->ObjInf->ObjList, inf->ObjList, -1);
	expAddParamToList(inf->ObjList, objname, llobj, EXPR_O_CURRENT);
	expLinkParams(inf->ObjList, 0, -1);

    return (void*)inf;
    }
Esempio n. 11
0
/*** qyt_internal_ReadObject - reads an object, with its attributes (blobs
 *** limited to 255 bytes), and stores the data in the object-attr cache,
 *** or looks the object up there if it has already been cached.
 ***/
pQytObjAttr
qyt_internal_ReadObject(char* path, pObjSession s)
    {
    pQytObjAttr objattr;
    pObject obj;
    char* attrname;
    int type;
    int ival;
    char* sval;

    	/** Check the cache first. **/
	objattr = (pQytObjAttr)xhLookup(&QYT_INF.ObjAttrCache, path);
	if (objattr) 
	    {
	    objattr->CacheTime = time(NULL);
	    objattr->LinkCnt++;
	    return objattr;
	    }

	/** Otherwise, open the object & read its attrs. **/
	obj = objOpen(s, path, O_RDONLY, 0600, "system/file");
	if (!obj) return NULL;

	/** Allocate... **/
	objattr = (pQytObjAttr)nmMalloc(sizeof(QytObjAttr));
	if (!objattr)
	    {
	    objClose(obj);
	    return NULL;
	    }
	memccpy(objattr->ObjPathname,path,0,255);
	objattr->ObjPathname[255]=0;
	xsInit(&objattr->AttrNameBuf);
	xsInit(&objattr->AttrValueBuf);
	xaInit(&objattr->AttrNames,32);
	xaInit(&objattr->AttrValues,32);

	/** Loop through attributes. **/
	for(attrname=objGetFirstAttr(obj);attrname;attrname=objGetNextAttr(obj))
	    {
	    /** Copy attrname to names listing.  Be sure to copy the '\0'. **/
	    xaAddItem(&objattr->AttrNames, xsStringEnd(&objattr->AttrNameBuf));
	    xsConcatenate(&objattr->AttrNameBuf, attrname, strlen(attrname)+1);

	    /** Get type and copy to attrvalues. **/
	    type = objGetAttrType(obj,attrname);
	    switch(type)
	        {
		case DATA_T_INTEGER:
		    if (objGetAttrValue(obj,attrname,DATA_T_INTEGER,POD(&ival)) == 0)
		        {
		        xaAddItem(&objattr->AttrValues, xsStringEnd(&objattr->AttrValueBuf));
			xsConcatenate(&objattr->AttrValueBuf, (char*)&ival, 4);
			}
		    else
		        {
		        xaAddItem(&objattr->AttrValues, NULL);
			}
		    break;

		case DATA_T_STRING:
		    if (objGetAttrValue(obj,attrname,DATA_T_INTEGER,POD(&sval)) == 0)
		        {
		        xaAddItem(&objattr->AttrValues, xsStringEnd(&objattr->AttrValueBuf));
		        xsConcatenate(&objattr->AttrValueBuf,sval, strlen(sval)+1);
			}
		    else
		        {
		        xaAddItem(&objattr->AttrValues, NULL);
			}
		    break;

		default:
		    break;
		}
	    }

	/** Close up the object **/
	objClose(obj);

	/** Cache the objattr structure **/
	xhAdd(&QYT_INF.ObjAttrCache, objattr->ObjPathname, (void*)objattr);
	xaAddItem(&QYT_INF.ObjAttrCacheList, (void*)objattr);

    return objattr;
    }
Esempio n. 12
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    POD p = POD();
    static_assert(std::is_pod<POD>::value, "");
    return p;
}
Esempio n. 13
0
/*** stxOpen - open a file or directory.
 ***/
void*
stxOpen(pObject obj, int mask, pContentType systype, char* usrtype, pObjTrxTree* oxt)
    {
    pStxData inf;
    char* endptr;
    pSnNode node = NULL;
    pStruct open_inf;
    pStructInf find_inf, attr_inf, search_inf;
    int i,j,n;
    char* ptr;

	/** Allocate the structure **/
	inf = (pStxData)nmMalloc(sizeof(StxData));
	if (!inf) return NULL;
	memset(inf,0,sizeof(StxData));
	inf->Obj = obj;
	inf->Mask = mask;

	/** Check node access.  IF newly created node object, handle differently. **/
	if ((obj->Prev->Flags & OBJ_F_CREATED) && (obj->Mode & O_CREAT))
	    {
	    /** Make the node **/
	    node = snNewNode(obj->Prev,"system/structure");
	    if (!node)
	        {
		mssError(0,"STX","Could not create new structure file");
		nmFree(inf, sizeof(StxData));
		return NULL;
		}

	    /** Any parameters to set? **/
	    if (obj->Pathname->OpenCtl[obj->SubPtr])
	        {
		for(i=0;i<obj->Pathname->OpenCtl[obj->SubPtr]->nSubInf;i++)
		    {
		    open_inf = obj->Pathname->OpenCtl[obj->SubPtr]->SubInf[i];
		    if (strncmp(open_inf->Name,"ls__",4) && open_inf->StrVal)
		        {
			attr_inf = stAddAttr(node->Data, open_inf->Name);
			endptr = NULL;
			n = strtoi(open_inf->StrVal,&endptr,0);
			if (endptr && *endptr == '\0')
			    stSetAttrValue(attr_inf, DATA_T_INTEGER, POD(&n), 0);
			else 
			    stSetAttrValue(attr_inf, DATA_T_STRING, POD(&(open_inf->StrVal)), 0);
			}
		    }
		}

	    /** Write the node. **/
	    snWriteNode(obj->Prev, node);
	    }
	else
	    {
	    /** Open an existing node. **/
	    node = snReadNode(obj->Prev);
	    if (node && (obj->Mode & O_CREAT) && (obj->Mode & O_EXCL) && obj->SubPtr == obj->Pathname->nElements)
	        {
		mssError(0,"STX","Structure file already exists");
		nmFree(inf, sizeof(StxData));
		return NULL;
		}
	    if (!node)
	        {
		mssError(0,"STX","Could not read structure file");
		nmFree(inf, sizeof(StxData));
		return NULL;
		}
	    }

	/** Search down the struct tree if we opened a sub-structure. **/
	search_inf = node->Data;
	obj->SubCnt = obj->Pathname->nElements - obj->SubPtr + 1;
	for(i=obj->SubPtr;i<obj->Pathname->nElements;i++)
	    {
	    ptr = obj_internal_PathPart(obj->Pathname,i,1);
	    find_inf = NULL;
	    for(j=0;j<search_inf->nSubInf;j++) if (!strcmp(ptr,search_inf->SubInf[j]->Name) && stStructType(search_inf->SubInf[j]) == ST_T_SUBGROUP)
	        {
		if (i == obj->Pathname->nElements-1 && (obj->Mode & O_CREAT) && (obj->Mode & O_EXCL))
		    {
		    nmFree(inf,sizeof(StxData));
		    mssError(1,"STX","Structure file sub-group already exists");
		    return NULL;
		    }
		find_inf = search_inf->SubInf[j];
		break;
		}
	    if (!find_inf && i == obj->Pathname->nElements-1 && (obj->Mode & O_CREAT))
	        {
		find_inf = stAddGroup(search_inf, ptr, usrtype);
		node->Status = SN_NS_DIRTY;
		}
	    else if (!find_inf)
	        {
		nmFree(inf,sizeof(StxData));
		mssError(1,"STX","Structure file sub-group does not exist");
		return NULL;
		}
	    search_inf = find_inf;

	    /** Stop searching because the current level is final? **/
	    if (stAttrValue(stLookup(search_inf,"final"),NULL,&ptr,0) == 0 && !strcasecmp(ptr,"yes"))
	        {
		obj->SubCnt = i - obj->SubPtr + 1;
	        break;
		}
	    }

	/** Set object params. **/
	inf->Node = node;
	inf->Data = search_inf;
	strcpy(inf->Pathname, obj_internal_PathPart(obj->Pathname,0,0));
	inf->Node->OpenCnt++;

    return (void*)inf;
    }
Esempio n. 14
0
/*** qy_internal_GetQueryItem - finds the first(next) inf item in the .qy
 *** file to include in this query.  Items to include are system/querytree
 *** type subitems that either have a source= or text= property.  Source=
 *** type subitems will result in zero or more items for the query.  Text=
 *** subitems will result in exactly one returned object for the query.
 *** Text= types cannot be modified/etc by the enduser.  The .qy must be
 *** opened as a structure file (via objdrv_struct) to modify Text=items.
 *** modifications/addidions/deletions of query results from a Source=
 *** item will be passed on to the source driver (such as objdrv_sybase).
 ***/
int
qy_internal_GetQueryItem(pQyQuery qy)
    {
    pStructInf main_inf;
    pStructInf find_inf;
    char* val;
    char* ptr;

    	/** Already hit end of query? **/
	if (qy->NextSubInfID == -1) return -1;

	/** Need to 'prime' the struct table? **/
	if (qy->StructTable.nItems == 0)
	    {
	    find_inf = qy->ObjInf->NodeData;
	    while(find_inf)
	        {
		if (find_inf->Type == ST_T_SUBGROUP) 
		    xhAdd(&qy->StructTable, find_inf->Name, (void*)find_inf);
		find_inf = find_inf->Parent;
		}
	    }

    	/** Search for a SOURCE= or TEXT= subgroup inf **/
	main_inf = qy->ObjInf->NodeData;
	while(qy->NextSubInfID < main_inf->nSubInf)
	    {
	    find_inf = main_inf->SubInf[qy->NextSubInfID++];
	    if (find_inf->Type == ST_T_ATTRIB && !strcmp(find_inf->Name, "recurse"))
	        {
		stGetAttrValue(find_inf, DATA_T_STRING, POD(&ptr), 0);
		find_inf = (pStructInf)xhLookup(&qy->StructTable, ptr);
		if (!find_inf) continue;
		}
	    if (find_inf->Type == ST_T_SUBGROUP)
	        {
		xhAdd(&qy->StructTable, find_inf->Name, (void*)find_inf);
		val = NULL;
		stAttrValue(stLookup(find_inf,"text"),NULL,&val,0);
		if (val)
		    {
		    qy->ItemText = val;
		    qy->ItemSrc = NULL;
		    qy->ItemWhere = NULL;
		    return qy->NextSubInfID - 1;
		    }
		stAttrValue(stLookup(find_inf,"source"),NULL,&val,0);
		if (val)
		    {
		    qy->ItemText = NULL;
		    qy->ItemSrc = val;
		    qy->ItemWhere = NULL;
		    stAttrValue(stLookup(find_inf,"where"),NULL,&(qy->ItemWhere),0);
		    return qy->NextSubInfID - 1;
		    }
		}
	    }

	/** End of query. **/
	qy->NextSubInfID = -1;

    return -1;
    }
Esempio n. 15
0
/*** qy_internal_ProcessPath - handles the lookup of the snNode from the given
 *** path in the querytree, and the optional creation of a new entity, as needed,
 *** manipulating the WHERE sql in the snNode to assign parent foreign key links
 *** and so forth.
 ***/
pQyData
qy_internal_ProcessPath(pObjSession s, pPathname path, pSnNode node, int subref, pStructInf dptr, int create, int no_open)
    {
    pQyData inf;
    pStructInf lookup_inf, find_inf, next_inf;
    char* ptr;
    char* strval;
    char* exprval;
    int i,v;
    pExpression expr;
    pParamObjects objlist;
    pObject test_obj;
    XHashTable struct_table;

    	/** Setup the pathname into its subparts **/
	for(i=1;i<path->nElements;i++) path->Elements[i][-1] = 0;

    	/** Allocate the data info first **/
	inf = (pQyData)nmMalloc(sizeof(QyData));
	if (!inf) return NULL;
	memset(inf,0,sizeof(QyData));
	inf->BaseNode = node;
	inf->LLObj = NULL;

	/** Create the object parameter list... **/
        objlist = expCreateParamList();

	/** Initialize the listing of query tree elements **/
	xhInit(&struct_table, 17, 0);

	/** Look for the part of the structinf which this path references. **/
	while(subref < path->nElements)
	    {
	    /** Add a slot to the param object list for this tree level **/
	    objlist->ParentID = objlist->CurrentID;
	    expAddParamToList(objlist,"",NULL,EXPR_O_CURRENT);

	    /** Look for text and source items in the querytree definition. **/
	    next_inf = NULL;
	    for(i=0;i<dptr->nSubInf;i++) 
	        {
		find_inf = dptr->SubInf[i];
		if (find_inf->Type == ST_T_SUBGROUP)
                    {
	    PROCESS_SUBGROUP:
                    inf->Pathname[0] = '\0';
                    if (lookup_inf = stLookup(find_inf, "text"))
                        {
                        strval = "";
                        stAttrValue(lookup_inf,NULL,&strval,0);
                        if (!strcmp(path->Elements[subref],strval))
                            {
                            next_inf = find_inf;
                            break;
                            }
                        if (subref == path->nElements - 1)
                            inf->LLObj = NULL;
                        }
                    else if (lookup_inf = stLookup(find_inf, "source"))
                        {
                        strval = "";
                        stAttrValue(lookup_inf,NULL,&strval,0);
                        expr = NULL;
                        exprval = NULL;
                        stAttrValue(stLookup(find_inf, "where"),NULL,&exprval,0);
                        if (exprval) 
			    {
			    objlist->Names[objlist->CurrentID] = find_inf->Name;
			    expr = (pExpression)expCompileExpression(exprval, objlist, MLX_F_ICASE | MLX_F_FILENAMES, 0);
			    }
                        sprintf(inf->Pathname,"%s/%s",strval,path->Elements[subref]);

			/** Setup this querytree struct entry for lookups **/
			xhAdd(&struct_table, find_inf->Name, (void*)find_inf);

			/** Not opening any objects?  Skip open attempt if so. **/
			if (no_open)
			    {
			    next_inf = find_inf;
			    break;
			    }
    
                        /** Open the object, or create if need be.  If create, convert any WHERE to setattrs **/
                        test_obj = objOpen(s, inf->Pathname, O_RDONLY, 0600, "system/file");
			if (test_obj) 
			    {
			    expModifyParam(objlist, NULL, test_obj);
			    }
                        if (!test_obj && subref == path->nElements - 1 && create)
                            {
                            test_obj = objOpen(s, inf->Pathname, O_RDWR | O_CREAT | O_TRUNC, 0600, "system/file");
                            if (!test_obj) break;
			    expModifyParam(objlist, NULL, test_obj);
			    objlist->Flags[objlist->CurrentID] |= EXPR_O_UPDATE;
                            if (expr)
                                {
				/** Reverse eval the expression to set the object attributes **/
				expr->Integer = 1;
				v = expReverseEvalTree(expr, objlist);
				expFreeExpression(expr);
				expr = NULL;
				if (v < 0)
				    {
				    objClose(test_obj);
				    break;
				    }
                                }
                            }
                        else if (!test_obj) break;
    
                        /** Validate the where clause expression if need be. **/
			objlist->Session = s;
                        v = !expr || (expEvalTree(expr,objlist) != -1 && expr->Integer != 0);
                        if (expr) expFreeExpression(expr);
			expr = NULL;
                        if (subref == path->nElements - 1) 
			    {
                            inf->LLObj = test_obj;
			    }
                        else 
			    {
                            if (!v) objClose(test_obj);
			    }
			if (v)
			    {
			    next_inf = find_inf;
			    break;
			    }
                        }
                    }
		else if (!strcmp(find_inf->Name,"recurse"))
		    {
		    stGetAttrValue(find_inf, DATA_T_STRING, POD(&ptr), 0);
		    find_inf = (pStructInf)xhLookup(&struct_table, ptr);
		    if (find_inf) goto PROCESS_SUBGROUP;
		    }
		}

	    /** Didn't find? **/
	    if (!next_inf) 
	        {
		/** Ok, close up the structure table. **/
		xhDeInit(&struct_table);
		nmFree(inf,sizeof(QyData));
		inf->LLObj = NULL;

		/** Close the objects and free the param list. **/
		for(i=0;i<objlist->nObjects-1;i++) objClose(objlist->Objects[i]);
		expFreeParamList(objlist);
		mssError(0,"QY","Could not find object via access through querytree");
		return NULL;
		}
	    dptr = next_inf;
	    subref++;
	    }
	inf->NodeData = dptr;
	xhDeInit(&struct_table);
	for(i=0;i<objlist->nObjects-1;i++) objClose(objlist->Objects[i]);

    return inf;
    }
Esempio n. 16
0
/*** hntObjToHints() - reads hints data from a pObject
 ***/
pObjPresentationHints
hntObjToHints(pObject obj)
    {
    pObjPresentationHints ph;
    int t,i;
    char* ptr;
    int n;
    ObjData od;

    	/** Allocate a new ph structure **/
	ph = (pObjPresentationHints)nmMalloc(sizeof(ObjPresentationHints));
	if (!ph) return NULL;
	memset(ph,0,sizeof(ObjPresentationHints));
	xaInit(&(ph->EnumList),16);

	/** expressions **/
	ph->Constraint = hnt_internal_GetExpr(obj,"constraint");
	ph->DefaultExpr = hnt_internal_GetExpr(obj,"default");
	ph->MinValue = hnt_internal_GetExpr(obj,"min");
	ph->MaxValue = hnt_internal_GetExpr(obj,"max");

	/** enum list? **/
	t = objGetAttrType(obj,"enumlist");
	if (t >= 0) 
	    {
	    if (objGetAttrValue(obj,"enumlist",t,&od) != 0) t = -1;
	    }
	if (t>=0) switch(t)
	    {
	    case DATA_T_STRINGVEC:
		for(i=0;i<od.StringVec->nStrings;i++)
		    xaAddItem(&(ph->EnumList), nmSysStrdup(od.StringVec->Strings[i]));
		break;

	    case DATA_T_INTVEC:
		for(i=0;i<od.IntVec->nIntegers;i++)
		    {
		    ptr = nmSysMalloc(16);
		    sprintf(ptr,"%d",od.IntVec->Integers[i]);
		    xaAddItem(&(ph->EnumList), ptr);
		    }
		break;

	    case DATA_T_INTEGER:
		ptr = nmSysMalloc(16);
		sprintf(ptr,"%d",od.Integer);
		xaAddItem(&(ph->EnumList), ptr);
		break;

	    case DATA_T_STRING:
		xaAddItem(&(ph->EnumList), nmSysStrdup(od.String));
		break;

	    default:
		mssError(1,"HNT","Invalid type for enumlist!");
		objFreeHints(ph);
		return NULL;
	    }

	/** String type hint info **/
	ph->EnumQuery = hnt_internal_GetString(obj,"enumquery");
	ph->AllowChars = hnt_internal_GetString(obj,"allowchars");
	ph->BadChars = hnt_internal_GetString(obj,"badchars");
	ph->Format = hnt_internal_GetString(obj,"format");
	ph->GroupName = hnt_internal_GetString(obj,"groupname");
	ph->FriendlyName = hnt_internal_GetString(obj,"description");

	/** Int type hint info **/
	if (objGetAttrValue(obj,"length",DATA_T_INTEGER,POD(&n)) == 0)
	    ph->Length = n;
	if (objGetAttrValue(obj,"width",DATA_T_INTEGER,POD(&n)) == 0)
	    ph->VisualLength = n;
	if (objGetAttrValue(obj,"height",DATA_T_INTEGER,POD(&n)) == 0)
	    ph->VisualLength2 = n;
	else
	    ph->VisualLength2 = 1;
	if (objGetAttrValue(obj,"groupid",DATA_T_INTEGER,POD(&n)) == 0)
	    ph->GroupID = n;

	/** Read-only bits **/
	t = objGetAttrType(obj, "readonlybits");
	if (t >= 0) 
	    {
	    if (objGetAttrValue(obj, "readonlybits", t, &od) != 0) t = -1;
	    }
	if (t>=0) switch(t)
	    {
	    case DATA_T_INTEGER:
		ph->BitmaskRO = (1<<od.Integer);
		break;
	    case DATA_T_INTVEC:
		ph->BitmaskRO = 0;
		for(i=0;i<od.IntVec->nIntegers;i++)
		    ph->BitmaskRO |= (1<<od.IntVec->Integers[i]);
		break;
	    default:
		mssError(1,"HNT","Invalid type for readonlybits!");
		objFreeHints(ph);
		return NULL;
	    }

	/** Style **/
	t = objGetAttrType(obj, "style");
	if (t >= 0)
	    {
	    if (objGetAttrValue(obj, "style", t, &od) != 0) t = -1;
	    }
	i=0;
	if (t == DATA_T_STRING || t == DATA_T_STRINGVEC) 
	  while(1)
	    {
	    /** String or StringVec? **/
	    if (t == DATA_T_STRING)
		{
		ptr = od.String;
		}
	    else
		{
		if (od.StringVec->nStrings == 0) break;
		ptr = od.StringVec->Strings[i];
		}

	    /** Check style settings **/
	    hnt_internal_SetStyleItem(ph, ptr);

	    if (t == DATA_T_STRING || i >= od.StringVec->nStrings-1) break;
	    i++;
	    }

    return ph;
    }
Esempio n. 17
0
/*** httbtnRender - generate the HTML code for the page.
 ***/
int
httbtnRender(pHtSession s, pWgtrNode tree, int z)
    {
    char* ptr;
    char name[64];
    char text[64];
    char fgcolor1[64];
    char fgcolor2[64];
    char bgstyle[128];
    char disable_color[64];
    int x,y,w,h;
    int id, i;
    int is_ts = 1;
    int is_enabled = 1;
    pExpression code;
    int box_offset;
    int clip_offset;
    int border_radius;
    char border_style[32];
    char border_color[64];
    char image_position[16]; /* top, left, right, bottom */
    char image[OBJSYS_MAX_PATH];
    char h_align[16];
    int image_width=0, image_height=0, image_margin=0;

	if(!s->Capabilities.Dom0NS && !s->Capabilities.Dom0IE && !(s->Capabilities.Dom1HTML && s->Capabilities.Dom2CSS))
	    {
	    mssError(1,"HTTBTN","Netscape DOM or (W3C DOM1 HTML and W3C DOM2 CSS) support required");
	    return -1;
	    }

    	/** Get an id for this. **/
	id = (HTTBTN.idcnt++);

    	/** Get x,y,w,h of this object **/
	if (wgtrGetPropertyValue(tree,"x",DATA_T_INTEGER,POD(&x)) != 0) 
	    {
	    mssError(1,"HTTBTN","TextButton widget must have an 'x' property");
	    return -1;
	    }
	if (wgtrGetPropertyValue(tree,"y",DATA_T_INTEGER,POD(&y)) != 0)
	    {
	    mssError(1,"HTTBTN","TextButton widget must have a 'y' property");
	    return -1;
	    }
	if (wgtrGetPropertyValue(tree,"width",DATA_T_INTEGER,POD(&w)) != 0)
	    {
	    mssError(1,"HTTBTN","TextButton widget must have a 'width' property");
	    return -1;
	    }
	if (wgtrGetPropertyValue(tree,"height",DATA_T_INTEGER,POD(&h)) != 0) h = -1;
	if (wgtrGetPropertyType(tree,"enabled") == DATA_T_STRING && wgtrGetPropertyValue(tree,"enabled",DATA_T_STRING,POD(&ptr)) == 0 && ptr)
	    {
	    if (!strcasecmp(ptr,"false") || !strcasecmp(ptr,"no")) is_enabled = 0;
	    }

	/** Border radius, color, and style.  For style, we only support outset,
	 ** solid, and none here.
	 **/
	if (wgtrGetPropertyValue(tree,"border_radius",DATA_T_INTEGER,POD(&border_radius)) != 0)
	    border_radius=0;
	if (wgtrGetPropertyValue(tree,"border_color",DATA_T_STRING,POD(&ptr)) != 0)
	    strcpy(border_color, "#c0c0c0");
	else
	    strtcpy(border_color, ptr, sizeof(border_color));
	if (wgtrGetPropertyValue(tree,"border_style",DATA_T_STRING,POD(&ptr)) != 0 || (strcmp(ptr,"outset") && strcmp(ptr,"solid") && strcmp(ptr,"none")))
	    strcpy(border_style, "outset");
	else
	    strtcpy(border_style, ptr, sizeof(border_style));

	/** Alignment **/
	if (wgtrGetPropertyValue(tree,"align",DATA_T_STRING,POD(&ptr)) == 0 && (!strcmp(ptr,"left") || !strcmp(ptr,"right") || !strcmp(ptr,"center")))
	    strtcpy(h_align, ptr, sizeof(h_align));
	else
	    strcpy(h_align, "center");

	/** Image location **/
	if (wgtrGetPropertyValue(tree,"image_position",DATA_T_STRING,POD(&ptr)) != 0 || (strcmp(ptr,"top") && strcmp(ptr,"right") && strcmp(ptr,"bottom") && strcmp(ptr, "left")))
	    strcpy(image_position, "top");
	else
	    strtcpy(image_position, ptr, sizeof(image_position));

	/** Image source **/
	if (wgtrGetPropertyValue(tree,"image",DATA_T_STRING,POD(&ptr)) != 0)
	    strcpy(image, "");
	else
	    strtcpy(image, ptr, sizeof(image));

	/** Image sizing **/
	if (wgtrGetPropertyValue(tree,"image_width",DATA_T_INTEGER, POD(&image_width)) != 0)
	    image_width = 0;
	if (wgtrGetPropertyValue(tree,"image_height",DATA_T_INTEGER, POD(&image_height)) != 0)
	    image_height = 0;
	if (wgtrGetPropertyValue(tree,"image_margin",DATA_T_INTEGER, POD(&image_margin)) != 0)
	    image_margin = 0;

	/** Get name **/
	if (wgtrGetPropertyValue(tree,"name",DATA_T_STRING,POD(&ptr)) != 0) return -1;
	strtcpy(name,ptr,sizeof(name));

	/** box adjustment... arrgh **/
	if (s->Capabilities.CSSBox)
	    box_offset = 1;
	else
	    box_offset = 0;
	clip_offset = s->Capabilities.CSSClip?1:0;

	/** User requesting expression for enabled? **/
	if (wgtrGetPropertyType(tree,"enabled") == DATA_T_CODE)
	    {
	    wgtrGetPropertyValue(tree,"enabled",DATA_T_CODE,POD(&code));
	    is_enabled = 0;
	    htrAddExpression(s, name, "enabled", code);
	    }

	/** Threestate button or twostate? **/
	if (wgtrGetPropertyValue(tree,"tristate",DATA_T_STRING,POD(&ptr)) == 0 && !strcmp(ptr,"no")) is_ts = 0;

	/** Get normal, point, and click images **/
	ptr = "-";
	if (!htrCheckAddExpression(s, tree, name, "text") && wgtrGetPropertyValue(tree,"text",DATA_T_STRING,POD(&ptr)) != 0)
	    {
	    mssError(1,"HTTBTN","TextButton widget must have a 'text' property");
	    return -1;
	    }
	strtcpy(text,ptr,sizeof(text));

	/** Get fgnd colors 1,2, and background color **/
	htrGetBackground(tree, NULL, 1, bgstyle, sizeof(bgstyle));

	if (wgtrGetPropertyValue(tree,"fgcolor1",DATA_T_STRING,POD(&ptr)) == 0)
	    strtcpy(fgcolor1,ptr,sizeof(fgcolor1));
	else
	    strcpy(fgcolor1,"white");
	if (wgtrGetPropertyValue(tree,"fgcolor2",DATA_T_STRING,POD(&ptr)) == 0)
	    strtcpy(fgcolor2,ptr,sizeof(fgcolor2));
	else
	    strcpy(fgcolor2,"black");
	if (wgtrGetPropertyValue(tree,"disable_color",DATA_T_STRING,POD(&ptr)) == 0)
	    strtcpy(disable_color,ptr,sizeof(disable_color));
	else
	    strcpy(disable_color,"#808080");

	htrAddScriptGlobal(s, "tb_current", "null", 0);

	/** DOM Linkages **/
	htrAddWgtrObjLinkage_va(s, tree, "tb%POSpane",id);

	/** Include the javascript code for the textbutton **/
	htrAddScriptInclude(s, "/sys/js/htdrv_textbutton.js", 0);
	htrAddScriptInclude(s, "/sys/js/ht_utils_layers.js", 0);

	/** Initial CSS styles **/
	htrAddStylesheetItem_va(s,"\t#tb%POSpane { POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; %[HEIGHT:%POSpx; %]WIDTH:%POSpx; Z-INDEX:%POS; OVERFLOW:hidden; display:table; }\n",
		id,
		x, y, h>=0, h-1-2*box_offset, w-1-2*box_offset, z
		);
	htrAddStylesheetItem_va(s, "\t#tb%POSpane .cell { height:100%%; width:100%%; vertical-align:middle; display:table-cell; padding:1px; font-weight:bold; cursor:default; text-align:%STR; border-width:1px; border-style:%STR&CSSVAL; border-color:%STR&CSSVAL; border-radius:%INTpx; color:%STR&CSSVAL; %[text-shadow:1px 1px %STR&CSSVAL; %]%STR }\n",
		/* clipping no longer needed:  0, w-1-2*box_offset+2*clip_offset, h-1-2*box_offset+2*clip_offset, 0, */
		id,
		h_align,
		border_style, border_color, border_radius,
		is_enabled?fgcolor1:disable_color, is_enabled, fgcolor2,
		bgstyle
		);

	/** CSS for image on the button **/
	if (image[0] && (image_width || image_height || image_margin))
	    {
	    htrAddStylesheetItem_va(s, "\t#tb%POSpane img { %[height:%POSpx; %]%[width:%POSpx; %]%[margin:%POSpx;%] }\n",
		    id,
		    image_height, image_height,
		    image_width, image_width,
		    image_margin, image_margin);
	    }

#if 00
	if(h >=0 )
	    {
	    htrAddStylesheetItem_va(s,"\t#tb%POSpane { POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; HEIGHT:%POSpx; WIDTH:%POSpx; Z-INDEX:%POS; OVERFLOW:hidden; clip:rect(%INTpx %INTpx %INTpx %INTpx)}\n", id, x, y, h-1-2*box_offset, w-1-2*box_offset, z, 0, w-1-2*box_offset+2*clip_offset, h-1-2*box_offset+2*clip_offset, 0);
	    }
	else
	    {
	    htrAddStylesheetItem_va(s,"\t#tb%POSpane { POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; WIDTH:%POSpx; Z-INDEX:%POS; OVERFLOW:hidden; clip:rect(%INTpx %INTpx auto %INTpx)}\n",id,x,y,w-1-2*box_offset,z,0,w-1-2*box_offset+2*clip_offset,0);
	    }
	htrAddStylesheetItem_va(s,"\t#tb%POSpane { cursor:default; text-align: center; %STR border-width: 1px; border-style: solid; border-color: white gray gray white; border-radius: %INTpx; }\n",id,bgstyle, border_radius);
	if (is_enabled)
	    htrAddStylesheetItem_va(s,"\t#tb%POSspan { color:%STR&CSSVAL; text-shadow:1px 1px %STR&CSSVAL; }\n", id, fgcolor1, fgcolor2);
	else
	    htrAddStylesheetItem_va(s,"\t#tb%POSspan { color:%STR&CSSVAL; }\n", id, disable_color);
#endif

	//htrAddBodyItem_va(s,"<DIV ID=\"tb%POSpane\"><center><table cellspacing=0 cellpadding=1 border=0><tr><td height=%POS valign=middle align=center><span id=\"tb%POSspan\"><b>%STR&HTE</b></span></td></tr></table></center>\n", id, h-3, id, text);
	//htrAddBodyItem(s,   "</DIV>");

	/** We need two DIVs here because of a long-outstanding Firefox bug :( **/
	htrAddBodyItem_va(s,"<div id=\"tb%POSpane\"><div class=\"cell\">%[<img border=\"0\" src=\"%STR&HTE\"/><br>%]%[<img border=\"0\" src=\"%STR&HTE\" style=\"vertical-align:middle;\"/>%]<span>%STR&HTE</span>%[<img border=\"0\" src=\"%STR&HTE\" style=\"vertical-align:middle;\"/>%]%[<br><img border=\"0\" src=\"%STR&HTE\"/>%]</div></div>", 
		id,
		image[0] && !strcmp(image_position, "top"), image,
		image[0] && !strcmp(image_position, "left"), image,
		text,
		image[0] && !strcmp(image_position, "right"), image,
		image[0] && !strcmp(image_position, "bottom"), image
		);

	/** Script initialization call. **/
	//htrAddScriptInit_va(s, "    tb_init({layer:wgtrGetNodeRef(ns,'%STR&SYM'), span:document.getElementById(\"tb%POSspan\"), ena:%INT, c1:\"%STR&JSSTR\", c2:\"%STR&JSSTR\", dc1:\"%STR&JSSTR\", top:null, bottom:null, right:null, left:null, width:%INT, height:%INT, tristate:%INT, name:\"%STR&SYM\", text:'%STR&JSSTR'});\n",
		//name, id, is_enabled, fgcolor1, fgcolor2, disable_color, w, h, is_ts, name, text);
	htrAddScriptInit_va(s, "    tb_init({layer:wgtrGetNodeRef(ns,'%STR&SYM'), ena:%INT, c1:\"%STR&JSSTR\", c2:\"%STR&JSSTR\", dc1:\"%STR&JSSTR\", top:null, bottom:null, right:null, left:null, width:%INT, height:%INT, tristate:%INT, name:\"%STR&SYM\", text:'%STR&JSSTR'});\n",
		name, is_enabled, fgcolor1, fgcolor2, disable_color, w, h, is_ts, name, text);

	/** Add the event handling scripts **/
	htrAddEventHandlerFunction(s, "document", "MOUSEDOWN", "tb", "tb_mousedown");
	htrAddEventHandlerFunction(s, "document", "MOUSEUP", "tb", "tb_mouseup");
	htrAddEventHandlerFunction(s, "document", "MOUSEOVER", "tb", "tb_mouseover");
	htrAddEventHandlerFunction(s, "document", "MOUSEOUT", "tb", "tb_mouseout");
	htrAddEventHandlerFunction(s, "document", "MOUSEMOVE", "tb", "tb_mousemove");

	/** IE handles dblclick strangely **/
	if (s->Capabilities.Dom0IE)
	    htrAddEventHandlerFunction(s, "document", "DBLCLICK", "tb", "tb_dblclick");

	/** Check for more sub-widgets within the textbutton. **/
	for (i=0;i<xaCount(&(tree->Children));i++)
	    htrRenderWidget(s, xaGetItem(&(tree->Children), i), z+3);

    return 0;
    }
Esempio n. 18
0
/* 
   htddRender - generate the HTML code for the page.
*/
int htddRender(pHtSession s, pWgtrNode tree, int z) {
   char bgstr[HT_SBUF_SIZE];
   char hilight[HT_SBUF_SIZE];
   char string[HT_SBUF_SIZE];
   char fieldname[30];
   char form[64];
   char osrc[64];
   char name[64];
   char *ptr;
   char *sql;
   char *str;
   char *attr;
   int type, rval, mode, flag=0;
   int x,y,w,h;
   int id, i;
   int num_disp;
   int query_multiselect;
   int invalid_select_default;
   int pop_w;
   ObjData od;
   XString xs;
   pObjQuery qy;
   pObject qy_obj;
   pWgtrNode subtree;

   if(!s->Capabilities.Dom0NS && !s->Capabilities.Dom1HTML)
       {
       mssError(1,"HTDD","Netscape or W3C DOM support required");
       return -1;
       }

   /** Get an id for this. **/
   id = (HTDD.idcnt++);

   /** Get x,y of this object **/
   if (wgtrGetPropertyValue(tree,"x",DATA_T_INTEGER,POD(&x)) != 0) x=0;
   if (wgtrGetPropertyValue(tree,"y",DATA_T_INTEGER,POD(&y)) != 0) y=0;
   if (wgtrGetPropertyValue(tree,"height",DATA_T_INTEGER,POD(&h)) != 0) h=0;
   if (h < s->ClientInfo->ParagraphHeight+2)
	h = s->ClientInfo->ParagraphHeight+2;
   if (wgtrGetPropertyValue(tree,"width",DATA_T_INTEGER,POD(&w)) != 0) {
	mssError(1,"HTDD","Drop Down widget must have a 'width' property");
	return -1;
   }
   pop_w = w;

   /** Width of popup dropdown list **/
   wgtrGetPropertyValue(tree,"popup_width", DATA_T_INTEGER, POD(&pop_w));

   query_multiselect = htrGetBoolean(tree, "query_multiselect", 0);
   invalid_select_default = htrGetBoolean(tree, "invalid_select_default", 0);

   if (wgtrGetPropertyValue(tree,"numdisplay",DATA_T_INTEGER,POD(&num_disp)) != 0) num_disp=3;

   if (wgtrGetPropertyValue(tree,"hilight",DATA_T_STRING,POD(&ptr)) == 0) {
	strtcpy(hilight,ptr,sizeof(hilight));
   } else {
	mssError(1,"HTDD","Drop Down widget must have a 'hilight' property");
	return -1;
   }

   if (wgtrGetPropertyValue(tree,"bgcolor",DATA_T_STRING,POD(&ptr)) == 0) {
	strtcpy(bgstr,ptr,sizeof(bgstr));
   } else {
	mssError(1,"HTDD","Drop Down widget must have a 'bgcolor' property");
	return -1;
   }

   if (wgtrGetPropertyValue(tree,"fieldname",DATA_T_STRING,POD(&ptr)) == 0) {
	strtcpy(fieldname,ptr,sizeof(fieldname));
   } else {
	fieldname[0]='\0';
   }

   if (wgtrGetPropertyValue(tree,"form",DATA_T_STRING,POD(&ptr)) == 0)
	strtcpy(form,ptr,sizeof(form));
   else
	form[0]='\0';
   if (wgtrGetPropertyValue(tree,"objectsource",DATA_T_STRING,POD(&ptr)) == 0)
	strtcpy(osrc,ptr,sizeof(osrc));
   else
	osrc[0]='\0';

    /** Get name **/
    if (wgtrGetPropertyValue(tree,"name",DATA_T_STRING,POD(&ptr)) != 0) return -1;
    strtcpy(name,ptr,sizeof(name));

    /** Ok, write the style header items. **/
    htrAddStylesheetItem_va(s,"\t#dd%POSbtn { OVERFLOW:hidden; POSITION:absolute; VISIBILITY:inherit; LEFT:%INTpx; TOP:%INTpx; HEIGHT:%POSpx; WIDTH:%POSpx; Z-INDEX:%POS; cursor:default; background-color: %STR&CSSVAL; }\n",id,x,y,h,w,z,bgstr);
    htrAddStylesheetItem_va(s,"\t#dd%POScon1 { OVERFLOW:hidden; POSITION:absolute; VISIBILITY:inherit; LEFT:1px; TOP:1px; WIDTH:1024px; HEIGHT:%POSpx; Z-INDEX:%POS; }\n",id,h-2,z+1);
    htrAddStylesheetItem_va(s,"\t#dd%POScon2 { OVERFLOW:hidden; POSITION:absolute; VISIBILITY:hidden; LEFT:1px; TOP:1px; WIDTH:1024px; HEIGHT:%POSpx; Z-INDEX:%POS; }\n",id,h-2,z+1);

    htrAddScriptGlobal(s, "dd_current", "null", 0);
    htrAddScriptGlobal(s, "dd_lastkey", "null", 0);
    htrAddScriptGlobal(s, "dd_target_img", "null", 0);
    htrAddScriptGlobal(s, "dd_thum_y","0",0);
    htrAddScriptGlobal(s, "dd_timeout","null",0);
    htrAddScriptGlobal(s, "dd_click_x","0",0);
    htrAddScriptGlobal(s, "dd_click_y","0",0);
    htrAddScriptGlobal(s, "dd_incr","0",0);
    htrAddScriptGlobal(s, "dd_cur_mainlayer","null",0);
    htrAddWgtrObjLinkage_va(s, tree, "dd%POSbtn", id);

    htrAddScriptInclude(s, "/sys/js/ht_utils_layers.js", 0);
    htrAddScriptInclude(s, "/sys/js/ht_utils_string.js", 0);
    htrAddScriptInclude(s, "/sys/js/ht_utils_hints.js", 0);
    htrAddScriptInclude(s, "/sys/js/htdrv_dropdown.js", 0);

    htrAddEventHandlerFunction(s, "document","MOUSEMOVE", "dd", "dd_mousemove");
    htrAddEventHandlerFunction(s, "document","MOUSEOVER", "dd", "dd_mouseover");
    htrAddEventHandlerFunction(s, "document","MOUSEUP", "dd", "dd_mouseup");
    htrAddEventHandlerFunction(s, "document","MOUSEDOWN", "dd", "dd_mousedown");
    htrAddEventHandlerFunction(s, "document","MOUSEOUT", "dd", "dd_mouseout");
    if (s->Capabilities.Dom1HTML)
       htrAddEventHandlerFunction(s, "document", "CONTEXTMENU", "dd", "dd_contextmenu");


    /** Get the mode (default to 1, dynamicpage) **/
    mode = 0;
    if (wgtrGetPropertyValue(tree,"mode",DATA_T_STRING,POD(&ptr)) == 0) {
	if (!strcmp(ptr,"static")) mode = 0;
	else if (!strcmp(ptr,"dynamic_server")) mode = 1;
	else if (!strcmp(ptr,"dynamic")) mode = 2;
	else if (!strcmp(ptr,"dynamic_client")) mode = 2;
	else if (!strcmp(ptr,"objectsource")) mode = 3;
	else {
	    mssError(1,"HTDD","Dropdown widget has not specified a valid mode.");
	    return -1;
	}
    }

    sql = 0;
    if (wgtrGetPropertyValue(tree,"sql",DATA_T_STRING,POD(&sql)) != 0 && mode != 0 && mode != 3) {
	mssError(1, "HTDD", "SQL parameter was not specified for dropdown widget");
	return -1;
    }
    /** Script initialization call. **/
    htrAddScriptInit_va(s,"    dd_init({layer:wgtrGetNodeRef(ns,\"%STR&SYM\"), c1:htr_subel(wgtrGetNodeRef(ns,\"%STR&SYM\"), \"dd%POScon1\"), c2:htr_subel(wgtrGetNodeRef(ns,\"%STR&SYM\"), \"dd%POScon2\"), background:'%STR&JSSTR', highlight:'%STR&JSSTR', fieldname:'%STR&JSSTR', numDisplay:%INT, mode:%INT, sql:'%STR&JSSTR', width:%INT, height:%INT, form:'%STR&JSSTR', osrc:'%STR&JSSTR', qms:%INT, ivs:%INT, popup_width:%INT});\n", name, name, id, name, id, bgstr, hilight, fieldname, num_disp, mode, sql?sql:"", w, h, form, osrc, query_multiselect, invalid_select_default, pop_w);

    /** HTML body <DIV> element for the layers. **/
    htrAddBodyItem_va(s,"<DIV ID=\"dd%POSbtn\">\n", id);
    htrAddBodyItem_va(s,"<TABLE width=%POS cellspacing=0 cellpadding=0 border=0>\n",w);
    htrAddBodyItem(s,   "   <TR><TD><IMG SRC=/sys/images/white_1x1.png></TD>\n");
    htrAddBodyItem_va(s,"       <TD><IMG SRC=/sys/images/white_1x1.png height=1 width=%POS></TD>\n",w-2);
    htrAddBodyItem(s,   "       <TD><IMG SRC=/sys/images/white_1x1.png></TD></TR>\n");
    htrAddBodyItem_va(s,"   <TR><TD><IMG SRC=/sys/images/white_1x1.png height=%POS width=1></TD>\n",h-2);
    htrAddBodyItem(s,   "       <TD align=right valign=middle><IMG SRC=/sys/images/ico15b.gif></TD>\n");
    htrAddBodyItem_va(s,"       <TD><IMG SRC=/sys/images/dkgrey_1x1.png height=%POS width=1></TD></TR>\n",h-2);
    htrAddBodyItem(s,   "   <TR><TD><IMG SRC=/sys/images/dkgrey_1x1.png></TD>\n");
    htrAddBodyItem_va(s,"       <TD><IMG SRC=/sys/images/dkgrey_1x1.png height=1 width=%POS></TD>\n",w-2);
    htrAddBodyItem(s,   "       <TD><IMG SRC=/sys/images/dkgrey_1x1.png></TD></TR>\n");
    htrAddBodyItem(s,   "</TABLE>\n");
    htrAddBodyItem_va(s,"<DIV ID=\"dd%POScon1\"></DIV>\n",id);
    htrAddBodyItem_va(s,"<DIV ID=\"dd%POScon2\"></DIV>\n",id);
    htrAddBodyItem(s,   "</DIV>\n");
    
    /* Read and initialize the dropdown items */
    if (mode == 1) {
	/** The result set from this SQL query can take two forms: positional or named.
	 ** For Positional, the params are: label, value, selected, group, hidden.
	 ** For Named, the above names can appear in any order.
	 ** label and value are required.
	 **/
	if ((qy = objMultiQuery(s->ObjSession, sql, NULL, 0))) {
	    flag=0;
	    htrAddScriptInit_va(s,"    dd_add_items(wgtrGetNodeRef(ns,\"%STR&SYM\"), [",name);
	    while ((qy_obj = objQueryFetch(qy, O_RDONLY))) {
		// Label
		attr = objGetFirstAttr(qy_obj);
		if (!attr) {
		    objClose(qy_obj);
		    objQueryClose(qy);
		    mssError(1, "HTDD", "SQL query must have at least two attributes: label and value.");
		    return -1;
		}
		type = objGetAttrType(qy_obj, attr);
		rval = objGetAttrValue(qy_obj, attr, type,&od);

                // Check if anything was returned
                if(rval != 0){
                    objClose(qy_obj);
                    continue;
                }
                
		if (type == DATA_T_INTEGER || type == DATA_T_DOUBLE) {
		    str = objDataToStringTmp(type, (void*)(&od), DATA_F_QUOTED);
		} else {
		    str = objDataToStringTmp(type, (void*)(od.String), DATA_F_QUOTED);
		}
		if (flag) htrAddScriptInit(s,",");
		htrAddScriptInit_va(s,"{wname:null, label:%STR,",str);
		// Value
		attr = objGetNextAttr(qy_obj);
		if (!attr) {
		    objClose(qy_obj);
		    objQueryClose(qy);
		    mssError(1, "HTDD", "SQL query must have at least two attributes: label and value.");
		    return -1;
		}

		type = objGetAttrType(qy_obj, attr);
		rval = objGetAttrValue(qy_obj, attr, type,&od);
		if (type == DATA_T_INTEGER || type == DATA_T_DOUBLE) {
		    str = objDataToStringTmp(type, (void*)(&od), DATA_F_QUOTED);
		} else {
		    str = objDataToStringTmp(type, (void*)(od.String), DATA_F_QUOTED);
		}
		htrAddScriptInit_va(s,"value:%STR", str);

		/** is selected **/
		attr = objGetNextAttr(qy_obj);
		if (attr) {
		    type = objGetAttrType(qy_obj, attr);
		    rval = objGetAttrValue(qy_obj, attr, type, &od);
		    htrAddScriptInit_va(s, ",sel:%INT", type == DATA_T_INTEGER && rval == 0 && od.Integer != 0);

		    /** grouping **/
		    attr = objGetNextAttr(qy_obj);
		    if (attr) {
			type = objGetAttrType(qy_obj, attr);
			rval = objGetAttrValue(qy_obj, attr, type, &od);
			if (rval == 0 && type == DATA_T_INTEGER)
			    htrAddScriptInit_va(s, ",grp:%INT", od.Integer);
			else if (rval == 0 && type == DATA_T_STRING)
			    htrAddScriptInit_va(s, ",grp:\"%STR&JSSTR\"", od.String);

			/** hidden **/
			attr = objGetNextAttr(qy_obj);
			if (attr) {
			    type = objGetAttrType(qy_obj, attr);
			    rval = objGetAttrValue(qy_obj, attr, type, &od);
			    htrAddScriptInit_va(s, ",hide:%INT}", type == DATA_T_INTEGER && rval == 0 && od.Integer != 0);
			} else {
			    htrAddScriptInit(s, "}");
			}
		    } else {
			htrAddScriptInit(s, "}");
		    }
		} else {
		    htrAddScriptInit(s, "}");
		}

		objClose(qy_obj);
		flag=1;
	    }
	    htrAddScriptInit(s,"]);\n");
	    objQueryClose(qy);
	}
    }
    else if(mode==3) {
	/* get objects from form */
    }


    flag=0;
    for (i=0;i<xaCount(&(tree->Children));i++)
	{
	subtree = xaGetItem(&(tree->Children), i);
	if (!strcmp(subtree->Type, "widget/dropdownitem")) 
	    subtree->RenderFlags |= HT_WGTF_NOOBJECT;
	if (!strcmp(subtree->Type,"widget/dropdownitem") && mode == 0) 
	    {
	    if (wgtrGetPropertyValue(subtree,"label",DATA_T_STRING,POD(&ptr)) != 0) 
		{
		mssError(1,"HTDD","Drop Down widget must have a 'width' property");
		return -1;
		}
	    strtcpy(string, ptr, sizeof(string));
	    if (flag) 
		{
		xsConcatenate(&xs, ",", 1);
		}
	    else 
		{
		xsInit(&xs);
		xsConcatQPrintf(&xs, "    dd_add_items(wgtrGetNodeRef(ns,\"%STR&SYM\"), [", name);
		flag=1;
		}
	    wgtrGetPropertyValue(subtree,"name",DATA_T_STRING,POD(&ptr));
	    xsConcatQPrintf(&xs,"{wname:'%STR&SYM', label:'%STR&JSSTR',", ptr, string);

	    if (htrGetBoolean(subtree, "selected", 0) == 1)
		{
		xsConcatenate(&xs,"sel:1,",6);
		}

	    if (wgtrGetPropertyValue(subtree,"value",DATA_T_STRING,POD(&ptr)) != 0) 
		{
		mssError(1,"HTDD","Drop Down widget must have a 'value' property");
		return -1;
		}
	    strtcpy(string,ptr, sizeof(string));
	    xsConcatQPrintf(&xs,"value:'%STR&JSSTR'}", string);
	    } 
	else 
	    {
	    htrRenderWidget(s, subtree, z+1);
	    }
	}
    if (flag) 
	{
	xsConcatenate(&xs, "]);\n", 4);
	htrAddScriptInit(s,xs.String);
	xsDeInit(&xs);
	}


    return 0;
}
Esempio n. 19
0
/*** shlOpen - open an object.
 ***/
void*
shlOpen(pObject obj, int mask, pContentType systype, char* usrtype, pObjTrxTree* oxt)
    {
    pShlData inf;
    int rval;
    char* node_path;
    pSnNode node = NULL;
    char* ptr;
    pStructInf argStruct;
    pStructInf changeStruct;
    int i,j;
    pStruct paramdata;
    int nameindex;
    char* endorsement_name;

	/** Allocate the structure **/
	inf = (pShlData)nmMalloc(sizeof(ShlData));
	if (!inf) return NULL;
	memset(inf,0,sizeof(ShlData));
	inf->Obj = obj;
	inf->Mask = mask;

	obj->SubCnt=1;
	if(SHELL_DEBUG & SHELL_DEBUG_INIT) printf("%s was offered: (%i,%i,%i) %s\n",__FILE__,obj->SubPtr,
		obj->SubCnt,obj->Pathname->nElements,obj_internal_PathPart(obj->Pathname,0,0));

	/** Determine the node path **/
	node_path = obj_internal_PathPart(obj->Pathname, 0, obj->SubPtr);

	if(SHELL_DEBUG & SHELL_DEBUG_OPEN)
	    printf("opening: %s\n",node_path);

	/** If CREAT and EXCL, we only create, failing if already exists. **/
	if ((obj->Mode & O_CREAT) && (obj->Mode & O_EXCL) && (obj->SubPtr == obj->Pathname->nElements))
	    {
	    node = snNewNode(obj->Prev, usrtype);
	    if (!node)
		{
		nmFree(inf,sizeof(ShlData));
		mssError(0,"SHL","Could not create new node object");
		return NULL;
		}
	    }
	
	/** Otherwise, try to open it first. **/
	if (!node)
	    {
	    node = snReadNode(obj->Prev);
	    }

	/** If no node, and user said CREAT ok, try that. **/
	if (!node && (obj->Mode & O_CREAT) && (obj->SubPtr == obj->Pathname->nElements))
	    {
	    node = snNewNode(obj->Prev, usrtype);
	    }

	/** If _still_ no node, quit out. **/
	if (!node)
	    {
	    nmFree(inf,sizeof(ShlData));
	    mssError(0,"SHL","Could not open structure file");
	    return NULL;
	    }

	/** Set object params. **/
	inf->Node = node;
	strcpy(inf->Pathname, obj_internal_PathPart(obj->Pathname,0,0));
	inf->Node->OpenCnt++;

	/** Security check **/
	if (endVerifyEndorsements(node->Data, stGetObjAttrValue, &endorsement_name) < 0)
	    {
	    inf->Node->OpenCnt --;
	    nmFree(inf,sizeof(ShlData));
	    mssError(1,"SHL","Security check failed - endorsement '%s' required", endorsement_name);
	    return NULL;
	    }

	/** figure out command to run **/
	if(stAttrValue(stLookup(node->Data,"program"),NULL,&ptr,0)<0) ptr="";
	strncpy(inf->program,ptr,79);
	inf->program[79]='\0';
	if(SHELL_DEBUG & SHELL_DEBUG_PARAM) printf("program: %s\n",inf->program);	
	
	argStruct=stLookup(node->Data,"arg");

	/** init structures for holding arguments and environmental variables **/
	xaInit(&inf->argArray,argStruct?5:1);
	xaInit(&inf->envArray,3);
	xaInit(&inf->envList,3);
	xhInit(&inf->envHash,17,0);
	
	if(!argStruct)
	    {
	    /** no 'arg' value present -- no parameters **/
	    }
	else
	    {
	    if(argStruct->Value->NodeType == EXPR_N_LIST)
		{
		/** 'arg' value is present and is a list -- parameters > 1 **/
		int i;
		pXArray values;
		values = &argStruct->Value->Children;
		for(i=0;i<values->nItems;i++)
		    xaAddItem(&inf->argArray,((pExpression)(values->Items[i]))->String);
		}
	    else
		{
		char *ptr;
		/** 'arg' value is present and is exactly one value -- 1 parameter **/
		if(stAttrValue(argStruct,NULL,&ptr,0)<0)
		    ptr=NULL;
		xaAddItem(&inf->argArray,ptr);
		}
	    xaAddItem(&inf->argArray,NULL);
	    }

	for(i=0;i<node->Data->nSubInf;i++)
	    {
	    pStructInf str = node->Data->SubInf[i];
	    if (strcmp(str->Name, "program") && strcmp(str->Name,"arg") && strcmp(str->Name,"changeable") ) 
		{
		pEnvVar pEV = (pEnvVar)nmMalloc(sizeof(EnvVar));
		if(stAttrValue(str,NULL,&pEV->value,0)<0)
		    pEV->value=NULL;
		pEV->changeable = 0;
		pEV->shouldfree = 0;
		xhAdd(&inf->envHash,str->Name,(char*)pEV); // add it to the hash
		xaAddItem(&inf->envList,str->Name); // add the name to the list
		}
	    }

	changeStruct=stLookup(node->Data,"changeable");

	if(changeStruct)
	    {
	    if(changeStruct->Value->NodeType == EXPR_N_LIST)
		{
		/** 'arg' value is present and is a list -- parameters > 1 **/
		int i;
		pXArray values;
		pEnvVar pEV=NULL;
		values = &argStruct->Value->Children;
		for(i=0;i<values->nItems;i++)
		    {
		    pEV=(pEnvVar)xhLookup(&inf->envHash,((pExpression)(values->Items[i]))->String);
		    if(pEV)
			{
			pEV->changeable = 1;
			}
		    else
			mssError(0,"SHL","can't find %s to mark changeable\n",((pExpression)(values->Items[i]))->String);
		    }
		}
	    else
		{
		char *ptr;
		pEnvVar pEV=NULL;
		/** 'arg' value is present and is exactly one value -- 1 parameter **/
		if(stAttrValue(changeStruct,NULL,&ptr,0)<0)
		    ptr=NULL;
		if(ptr)
		    pEV=(pEnvVar)xhLookup(&inf->envHash,ptr);
		if(pEV)
		    {
		    pEV->changeable = 1;
		    }
		else
		    mssError(0,"SHL","can't find %s to mark changeable\n",ptr);
		}
	    }


	/** note that the child process hasn't been started yet **/
	inf->shell_pid = -1; 

	/** this is set to 1 when a read fails with EIO **/
	inf->done = 0;

	if(SHELL_DEBUG & SHELL_DEBUG_OPEN)
	    printf("SHELL: returning object: %p\n",inf);

	/** Set initial param values? **/
	nameindex = obj->SubPtr - 1 + obj->SubCnt - 1;
	if (obj->Pathname->OpenCtl[nameindex])
	    {
	    paramdata = obj->Pathname->OpenCtl[nameindex];
	    for(i=0;i<paramdata->nSubInf;i++)
		{
		shl_internal_SetParam(inf, paramdata->SubInf[i]->Name, DATA_T_STRING, POD(&(paramdata->SubInf[i]->StrVal)));
		}
	    }

    return (void*)inf;
    }
Esempio n. 20
0
int test_main(int, char **)
{
  BOOST_CHECK ( test( 0,1234 ) ) ;
  BOOST_CHECK ( test( 0.0,12.34 ) ) ;
  BOOST_CHECK ( test( POD(0,0,0.0), POD('a',1234,56.78) ) ) ;
  BOOST_CHECK ( test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ) ;

  NonPOD NonPOD_object( std::string("NonPOD_object") );
  BOOST_CHECK ( test<NonPOD *>( 0, &NonPOD_object ) ) ;

  AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 };
  AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 };
  BOOST_CHECK ( test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct) );

  StringAndInt stringAndInt0;
  StringAndInt stringAndInt1;
  stringAndInt0.i = 0;
  stringAndInt1.i = 1;
  stringAndInt1.s = std::string("1");
  BOOST_CHECK ( test(stringAndInt0, stringAndInt1) );

  StructWithDestructor structWithDestructor0;
  StructWithDestructor structWithDestructor1;
  structWithDestructor0.i = 0;
  structWithDestructor1.i = 1;
  BOOST_CHECK ( test(structWithDestructor0, structWithDestructor1) );

  StructWithVirtualFunction structWithVirtualFunction0;
  StructWithVirtualFunction structWithVirtualFunction1;
  structWithVirtualFunction0.i = 0;
  structWithVirtualFunction1.i = 1;
  BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) );

  DerivedFromAggregatePODStruct derivedFromAggregatePODStruct0;
  DerivedFromAggregatePODStruct derivedFromAggregatePODStruct1;
  static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct0) = zeroInitializedAggregatePODStruct;
  static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct1) = nonZeroInitializedAggregatePODStruct;
  BOOST_CHECK ( test(derivedFromAggregatePODStruct0, derivedFromAggregatePODStruct1) );

  AggregatePODStructWrapper aggregatePODStructWrapper0;
  AggregatePODStructWrapper aggregatePODStructWrapper1;
  aggregatePODStructWrapper0.dataMember = zeroInitializedAggregatePODStruct;
  aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct;
  BOOST_CHECK ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) );

  ArrayOfBytes zeroInitializedArrayOfBytes = { 0 };
  boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes;
  BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0);

  boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes2;
  valueInitializedArrayOfBytes2 = valueInitializedArrayOfBytes;
  BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), get(valueInitializedArrayOfBytes2), sizeof(ArrayOfBytes)) == 0);

  boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1;
  BOOST_CHECK ( ! get(copyFunctionCallTester1).is_copy_constructed);
  BOOST_CHECK ( ! get(copyFunctionCallTester1).is_assignment_called);

  boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
  BOOST_CHECK ( get(copyFunctionCallTester2).is_copy_constructed);
  BOOST_CHECK ( ! get(copyFunctionCallTester2).is_assignment_called);

  boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3;
  copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
  BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed);
  BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called);

  boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester1;
  boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester2;
  get(swapFunctionCallTester1).data = 1;
  get(swapFunctionCallTester2).data = 2;
  boost::swap(swapFunctionCallTester1, swapFunctionCallTester2);
  BOOST_CHECK( get(swapFunctionCallTester1).data == 2 );
  BOOST_CHECK( get(swapFunctionCallTester2).data == 1 );
  BOOST_CHECK( get(swapFunctionCallTester1).is_custom_swap_called );
  BOOST_CHECK( get(swapFunctionCallTester2).is_custom_swap_called );

  return 0;
}
Esempio n. 21
0
POD GetPODValue(Value value) {
  return value.type == TYPEID ? *reinterpret_cast<POD*>(value.value) : POD();
}
Esempio n. 22
0
/* 
   htosrcRender - generate the HTML code for the page.
   
   Don't know what this is, but we're keeping it for now - JJP, JDH
*/
int
htosrcRender(pHtSession s, pWgtrNode tree, int z)
   {
   int id;
   char name[40];
   char *ptr;
   int readahead;
   int scrollahead;
   int replicasize;
   char *sql;
   char *filter;
   char *baseobj;
   pWgtrNode sub_tree;
//   pObjQuery qy;
   enum htosrc_autoquery_types aq;
   int receive_updates;
   int send_updates;
   int refresh_interval;
   int count, i;
   int ind_activity;
   int use_having;
   int qy_reveal_only;
   char key_objname[32];

   if(!s->Capabilities.Dom0NS && !s->Capabilities.Dom1HTML)
       {
       mssError(1,"HTOSRC","Netscape DOM or W3C DOM1 HTML support required");
       return -1;
       }

   /** Get an id for this. **/
   id = (HTOSRC.idcnt++);

   /** Get name **/
   if (wgtrGetPropertyValue(tree,"name",DATA_T_STRING,POD(&ptr)) != 0) return -1;
   strtcpy(name,ptr,sizeof(name));

   if (wgtrGetPropertyValue(tree,"replicasize",DATA_T_INTEGER,POD(&replicasize)) != 0)
      replicasize=6;
   if (wgtrGetPropertyValue(tree,"readahead",DATA_T_INTEGER,POD(&readahead)) != 0)
      readahead=replicasize/2;
   if (wgtrGetPropertyValue(tree,"scrollahead",DATA_T_INTEGER,POD(&scrollahead)) != 0)
      scrollahead=readahead;

   /** do queries on this osrc indicate end-user activity? **/
   ind_activity = htrGetBoolean(tree, "indicates_activity", 1);

   /** refresh interval (disabled, setting=0, by default) **/
   if (wgtrGetPropertyValue(tree, "refresh_interval", DATA_T_INTEGER, POD(&refresh_interval)) != 0)
      refresh_interval = 0;

   /** use HAVING clause for query filtering instead of WHERE? **/
   use_having = htrGetBoolean(tree, "use_having_clause", 0);

   /** Delay query until osrc is visible? **/
   /*qy_reveal_only = htrGetBoolean(tree, "delay_query_until_reveal", 0);*/
   qy_reveal_only = htrGetBoolean(tree, "revealed_only", 0);

   /** try to catch mistakes that would probably make Netscape REALLY buggy... **/
   if(replicasize==1 && readahead==0) readahead=1;
   if(replicasize==1 && scrollahead==0) scrollahead=1;
   if(readahead>replicasize) replicasize=readahead;
   if(scrollahead>replicasize) replicasize=scrollahead;
   if(scrollahead<1) scrollahead=1;
   if(replicasize<1 || readahead<1)
      {
      mssError(1,"HTOSRC","You must give positive integer for replicasize and readahead");
      return -1;
      }

   /** Name/abbreviation of key object in SQL query **/
   if (wgtrGetPropertyValue(tree,"key_objname",DATA_T_STRING,POD(&ptr)) != 0)
      ptr = "";
   strtcpy(key_objname, ptr, sizeof(key_objname));

   /** Query autostart types **/
   if (wgtrGetPropertyValue(tree,"autoquery",DATA_T_STRING,POD(&ptr)) == 0)
      {
      if (!strcasecmp(ptr,"onLoad")) aq = OnLoad;
      else if (!strcasecmp(ptr,"onFirstReveal")) aq = OnFirstReveal;
      else if (!strcasecmp(ptr,"onEachReveal")) aq = OnEachReveal;
      else if (!strcasecmp(ptr,"never")) aq = Never;
      else
	 {
	 mssError(1,"HTOSRC","Invalid autostart type '%s' for objectsource '%s'",ptr,name);
	 return -1;
	 }
      }
   else
      {
      aq = Unset;
      }

   /** Get replication updates from server? **/
   receive_updates = htrGetBoolean(tree, "receive_updates", 0);

   /** Send updates to the server? **/
   send_updates = htrGetBoolean(tree, "send_updates", 1);

   if (wgtrGetPropertyValue(tree,"sql",DATA_T_STRING,POD(&ptr)) == 0)
      {
      sql = nmSysStrdup(ptr);
      }
   else
      {
      mssError(1,"HTOSRC","You must give a sql parameter");
      return -1;
      }

   if (wgtrGetPropertyValue(tree,"baseobj",DATA_T_STRING,POD(&ptr)) == 0)
      baseobj = nmSysStrdup(ptr);
   else
      baseobj = NULL;

   if (wgtrGetPropertyValue(tree,"filter",DATA_T_STRING,POD(&ptr)) == 0)
      filter = nmSysStrdup(ptr);
   else
      filter = nmSysStrdup("");

   /** create our instance variable **/
   htrAddWgtrObjLinkage_va(s, tree, "osrc%POSloader",id);
   htrAddWgtrCtrLinkage(s, tree, "_parentctr");

   htrAddScriptGlobal(s, "osrc_syncid", "0", 0);
   htrAddScriptGlobal(s, "osrc_relationships", "[]", 0);

   /** Ok, write the style header items. **/
   htrAddStylesheetItem_va(s,"        #osrc%POSloader { overflow:hidden; POSITION:absolute; VISIBILITY:hidden; LEFT:0px; TOP:1px;  WIDTH:1px; HEIGHT:1px; Z-INDEX:0; }\n",id);

   /** Script initialization call. **/
   htrAddScriptInit_va(s,"    osrc_init({loader:wgtrGetNodeRef(ns,\"%STR&SYM\"), readahead:%INT, scrollahead:%INT, replicasize:%INT, sql:\"%STR&JSSTR\", filter:\"%STR&JSSTR\", baseobj:\"%STR&JSSTR\", name:\"%STR&SYM\", autoquery:%INT, requestupdates:%INT, ind_act:%INT, use_having:%INT, qy_reveal_only:%INT, send_updates:%INT, key_objname:\"%STR&JSSTR\", refresh:%INT});\n",
	 name,readahead,scrollahead,replicasize,sql,filter,
	 baseobj?baseobj:"",name,aq,receive_updates, ind_activity,
	 use_having, qy_reveal_only, send_updates, key_objname, refresh_interval);
   //htrAddScriptCleanup_va(s,"    %s.layers.osrc%dloader.cleanup();\n", parentname, id);

   htrAddScriptInclude(s, "/sys/js/htdrv_osrc.js", 0);
   htrAddScriptInclude(s, "/sys/js/ht_utils_string.js", 0);
   htrAddScriptInclude(s, "/sys/js/ht_utils_hints.js", 0);

   /** HTML body element for the frame **/
   htrAddBodyItemLayerStart(s,HTR_LAYER_F_DYNAMIC,"osrc%POSloader",id);
   htrAddBodyItemLayerEnd(s,HTR_LAYER_F_DYNAMIC);
   htrAddBodyItem(s, "\n");

    count = xaCount(&(tree->Children));
    for (i=0;i<count;i++)
	{
	sub_tree = xaGetItem(&(tree->Children), i);
#if 00
	if (wgtrGetPropertyValue(sub_tree, "outer_type", DATA_T_STRING, POD(&ptr)) == 0 && !strcmp(ptr, "widget/osrc-rule"))
	    {
	    htosrc_internal_AddRule(s, tree, name, sub_tree);
	    }
	else
	    {
#endif
	    htrRenderWidget(s, sub_tree, z);
#if 00
	    }
#endif
	}

    nmSysFree(filter);
    if (baseobj) nmSysFree(baseobj);
    nmSysFree(sql);

   return 0;
}