本文整理汇总了C++中IsDefinedClass函数的典型用法代码示例。如果您正苦于以下问题:C++ IsDefinedClass函数的具体用法?C++ IsDefinedClass怎么用?C++ IsDefinedClass使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsDefinedClass函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvalContextHeapAddHard
void EvalContextHeapAddHard(EvalContext *ctx, const char *context)
{
char context_copy[CF_MAXVARSIZE];
strcpy(context_copy, context);
if (Chop(context_copy, CF_EXPANDSIZE) == -1)
{
CfOut(OUTPUT_LEVEL_ERROR, "", "Chop was called on a string that seemed to have no terminator");
}
CanonifyNameInPlace(context_copy);
CfDebug("EvalContextHeapAddHard(%s)\n", context_copy);
if (strlen(context_copy) == 0)
{
return;
}
if (IsRegexItemIn(ctx, ctx->heap_abort_current_bundle, context_copy))
{
CfOut(OUTPUT_LEVEL_ERROR, "", "Bundle aborted on defined class \"%s\"\n", context_copy);
ABORTBUNDLE = true;
}
if (IsRegexItemIn(ctx, ctx->heap_abort, context_copy))
{
CfOut(OUTPUT_LEVEL_ERROR, "", "cf-agent aborted on defined class \"%s\"\n", context_copy);
exit(1);
}
if (EvalContextHeapContainsHard(ctx, context_copy))
{
return;
}
StringSetAdd(ctx->heap_hard, xstrdup(context_copy));
for (const Item *ip = ctx->heap_abort; ip != NULL; ip = ip->next)
{
if (IsDefinedClass(ctx, ip->name, NULL))
{
CfOut(OUTPUT_LEVEL_ERROR, "", "cf-agent aborted on defined class \"%s\" defined in bundle %s\n", ip->name, StackFrameOwnerName(LastStackFrame(ctx, 0)));
exit(1);
}
}
if (!ABORTBUNDLE)
{
for (const Item *ip = ctx->heap_abort_current_bundle; ip != NULL; ip = ip->next)
{
if (IsDefinedClass(ctx, ip->name, NULL))
{
CfOut(OUTPUT_LEVEL_ERROR, "", " -> Setting abort for \"%s\" when setting \"%s\"", ip->name, context_copy);
ABORTBUNDLE = true;
break;
}
}
}
}
示例2: VarClassExcluded
int VarClassExcluded(EvalContext *ctx, Promise *pp, char **classes)
{
Constraint *cp = PromiseGetConstraint(ctx, pp, "ifvarclass");
if (cp == NULL)
{
return false;
}
*classes = (char *) ConstraintGetRvalValue(ctx, "ifvarclass", pp, RVAL_TYPE_SCALAR);
if (*classes == NULL)
{
return true;
}
if (strchr(*classes, '$') || strchr(*classes, '@'))
{
CfDebug("Class expression did not evaluate");
return true;
}
if (*classes && IsDefinedClass(ctx, *classes, PromiseGetNamespace(pp)))
{
return false;
}
else
{
return true;
}
}
示例3: KeepServerPromise
static void KeepServerPromise(Promise *pp)
{
char *sp = NULL;
if (!IsDefinedClass(pp->classes))
{
CfOut(cf_verbose, "", "Skipping whole promise, as context is %s\n", pp->classes);
return;
}
if (VarClassExcluded(pp, &sp))
{
CfOut(cf_verbose, "", "\n");
CfOut(cf_verbose, "", ". . . . . . . . . . . . . . . . . . . . . . . . . . . . \n");
CfOut(cf_verbose, "", "Skipping whole next promise (%s), as var-context %s is not relevant\n", pp->promiser,
sp);
CfOut(cf_verbose, "", ". . . . . . . . . . . . . . . . . . . . . . . . . . . . \n");
return;
}
if (strcmp(pp->agentsubtype, "classes") == 0)
{
KeepClassContextPromise(pp);
return;
}
sp = (char *) GetConstraintValue("resource_type", pp, CF_SCALAR);
if (strcmp(pp->agentsubtype, "access") == 0 && sp && strcmp(sp, "literal") == 0)
{
KeepLiteralAccessPromise(pp, "literal");
return;
}
if (strcmp(pp->agentsubtype, "access") == 0 && sp && strcmp(sp, "query") == 0)
{
KeepQueryAccessPromise(pp, "query");
return;
}
if (strcmp(pp->agentsubtype, "access") == 0 && sp && strcmp(sp, "context") == 0)
{
KeepLiteralAccessPromise(pp, "context");
return;
}
/* Default behaviour is file access */
if (strcmp(pp->agentsubtype, "access") == 0)
{
KeepFileAccessPromise(pp);
return;
}
if (strcmp(pp->agentsubtype, "roles") == 0)
{
KeepServerRolePromise(pp);
return;
}
}
示例4: IsRegexItemIn
int IsRegexItemIn(EvalContext *ctx, Item *list, char *regex)
{
Item *ptr;
for (ptr = list; ptr != NULL; ptr = ptr->next)
{
if ((ptr->classes) && (!IsDefinedClass(ctx, ptr->classes)))
{
continue;
}
/* Avoid using regex if possible, due to memory leak */
if (strcmp(regex, ptr->name) == 0)
{
return true;
}
/* Make it commutative */
if ((StringMatchFull(regex, ptr->name)) || (StringMatchFull(ptr->name, regex)))
{
return true;
}
}
return false;
}
示例5: IsRegexItemIn
int IsRegexItemIn(const EvalContext *ctx, const Item *list, const char *regex)
{
for (const Item *ptr = list; ptr != NULL; ptr = ptr->next)
{
if (ctx != NULL && ptr->classes != NULL &&
!IsDefinedClass(ctx, ptr->classes))
{
continue;
}
/* Cheap pre-test: */
if (strcmp(regex, ptr->name) == 0)
{
return true;
}
/* Make it commutative */
if (StringMatchFull(regex, ptr->name) || StringMatchFull(ptr->name, regex))
{
return true;
}
}
return false;
}
示例6: ScheduleRun
int ScheduleRun()
{ time_t now;
char timekey[64];
struct Item *ip;
Verbose("Sleeping...\n");
sleep(60); /* 1 Minute resolution is enough */
now = time(NULL);
snprintf(timekey,63,"%s",ctime(&now));
AddTimeClass(timekey);
for (ip = SCHEDULE; ip != NULL; ip = ip->next)
{
Verbose("Checking schedule %s...\n",ip->name);
if (IsDefinedClass(ip->name))
{
Verbose("Waking up the agent at %s ~ %s \n",timekey,ip->name);
DeleteItemList(VHEAP);
VHEAP = NULL;
return true;
}
}
DeleteItemList(VHEAP);
VHEAP = NULL;
return false;
}
示例7: FnCallEvaluate
FnCallResult FnCallEvaluate(EvalContext *ctx, FnCall *fp, const Promise *caller)
{
Rlist *expargs;
const FnCallType *fp_type = FnCallTypeGet(fp->name);
if (fp_type)
{
if (DEBUG)
{
printf("EVALUATE FN CALL %s\n", fp->name);
FnCallShow(stdout, fp);
printf("\n");
}
}
else
{
if (caller)
{
CfOut(OUTPUT_LEVEL_ERROR, "", "No such FnCall \"%s()\" in promise @ %s near line %zd\n",
fp->name, PromiseGetBundle(caller)->source_path, caller->offset.line);
}
else
{
CfOut(OUTPUT_LEVEL_ERROR, "", "No such FnCall \"%s()\" - context info unavailable\n", fp->name);
}
return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } };
}
/* If the container classes seem not to be defined at this stage, then don't try to expand the function */
if ((caller != NULL) && !IsDefinedClass(ctx, caller->classes, PromiseGetNamespace(caller)))
{
return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } };
}
expargs = NewExpArgs(ctx, fp, caller);
if (UnresolvedArgs(expargs))
{
DeleteExpArgs(expargs);
return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } };
}
fp->caller = caller;
FnCallResult result = CallFunction(ctx, fp_type, fp, expargs);
if (result.status == FNCALL_FAILURE)
{
/* We do not assign variables to failed function calls */
DeleteExpArgs(expargs);
return (FnCallResult) { FNCALL_FAILURE, { FnCallCopy(fp), RVAL_TYPE_FNCALL } };
}
DeleteExpArgs(expargs);
return result;
}
示例8: EvaluateFunctionCall
FnCallResult EvaluateFunctionCall(FnCall *fp, Promise *pp)
{
Rlist *expargs;
const FnCallType *this = FindFunction(fp->name);
if (this)
{
if (DEBUG)
{
printf("EVALUATE FN CALL %s\n", fp->name);
ShowFnCall(stdout, fp);
printf("\n");
}
}
else
{
if (pp)
{
CfOut(cf_error, "", "No such FnCall \"%s()\" in promise @ %s near line %zd\n",
fp->name, pp->audit->filename, pp->offset.line);
}
else
{
CfOut(cf_error, "", "No such FnCall \"%s()\" - context info unavailable\n", fp->name);
}
return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } };
}
/* If the container classes seem not to be defined at this stage, then don't try to expand the function */
if ((pp != NULL) && !IsDefinedClass(pp->classes))
{
return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } };
}
expargs = NewExpArgs(fp, pp);
if (UnresolvedArgs(expargs))
{
DeleteExpArgs(expargs);
return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } };
}
FnCallResult result = CallFunction(this, fp, expargs);
if (result.status == FNCALL_FAILURE)
{
/* We do not assign variables to failed function calls */
DeleteExpArgs(expargs);
return (FnCallResult) { FNCALL_FAILURE, { CopyFnCall(fp), CF_FNCALL } };
}
DeleteExpArgs(expargs);
return result;
}
示例9: KeepServerRolePromise
/**
* The "roles" access promise is for remote class activation by means of
* cf-runagent -D:
*
* pp->promiser is a regex to match classes.
* pp->conlist is an slist of usernames.
*/
static void KeepServerRolePromise(EvalContext *ctx, const Promise *pp)
{
size_t pos = acl_SortedInsert(&roles_acl, pp->promiser);
if (pos == (size_t) -1)
{
/* Should never happen, besides when allocation fails. */
Log(LOG_LEVEL_CRIT, "acl_Insert: %s", GetErrorStr());
exit(255);
}
size_t i = SeqLength(pp->conlist);
while (i > 0)
{
i--;
Constraint *cp = SeqAt(pp->conlist, i);
char const * const authorizer =
CF_REMROLE_BODIES[REMOTE_ROLE_AUTHORIZE].lval;
if (strcmp(cp->lval, authorizer) == 0)
{
if (cp->rval.type != RVAL_TYPE_LIST)
{
Log(LOG_LEVEL_ERR,
"Right-hand side of authorize promise for '%s' should be a list",
pp->promiser);
}
else if (IsDefinedClass(ctx, cp->classes))
{
for (const Rlist *rp = cp->rval.item; rp != NULL; rp = rp->next)
{
/* The "roles" access promise currently only supports
* listing usernames to admit access to, nothing more. */
struct resource_acl *racl = &roles_acl->acls[pos];
size_t zret = StrList_Append(&racl->admit.usernames,
RlistScalarValue(rp));
if (zret == (size_t) -1)
{
/* Should never happen, besides when allocation fails. */
Log(LOG_LEVEL_CRIT, "StrList_Append: %s", GetErrorStr());
exit(255);
}
}
}
}
else if (strcmp(cp->lval, "comment") != 0 &&
strcmp(cp->lval, "handle") != 0 &&
/* Are there other known list constraints ? if not, skip this: */
cp->rval.type != RVAL_TYPE_LIST)
{
Log(LOG_LEVEL_WARNING,
"Unrecognised promise '%s' for %s",
cp->lval, pp->promiser);
}
}
}
示例10: ExpandPromise
PromiseResult ExpandPromise(EvalContext *ctx, const Promise *pp,
PromiseActuator *ActOnPromise, void *param)
{
Log(LOG_LEVEL_VERBOSE, "Evaluating promise '%s'", pp->promiser);
if (!IsDefinedClass(ctx, pp->classes))
{
if (LEGACY_OUTPUT)
{
Log(LOG_LEVEL_VERBOSE, ". . . . . . . . . . . . . . . . . . . . . . . . . . . . ");
Log(LOG_LEVEL_VERBOSE, "Skipping whole next promise (%s), as context %s is not relevant", pp->promiser,
pp->classes);
Log(LOG_LEVEL_VERBOSE, ". . . . . . . . . . . . . . . . . . . . . . . . . . . . ");
}
else
{
Log(LOG_LEVEL_VERBOSE, "Skipping next promise '%s', as context '%s' is not relevant", pp->promiser, pp->classes);
}
return PROMISE_RESULT_SKIPPED;
}
Rlist *lists = NULL;
Rlist *scalars = NULL;
Rlist *containers = NULL;
Promise *pcopy = DeRefCopyPromise(ctx, pp);
MapIteratorsFromRval(ctx, PromiseGetBundle(pp), (Rval) { pcopy->promiser, RVAL_TYPE_SCALAR }, &scalars, &lists, &containers);
if (pcopy->promisee.item != NULL)
{
MapIteratorsFromRval(ctx, PromiseGetBundle(pp), pp->promisee, &scalars, &lists, &containers);
}
for (size_t i = 0; i < SeqLength(pcopy->conlist); i++)
{
Constraint *cp = SeqAt(pcopy->conlist, i);
MapIteratorsFromRval(ctx, PromiseGetBundle(pp), cp->rval, &scalars, &lists, &containers);
}
CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), lists);
CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), scalars);
CopyLocalizedReferencesToBundleScope(ctx, PromiseGetBundle(pp), containers);
PromiseResult result = ExpandPromiseAndDo(ctx, pcopy, lists, containers, ActOnPromise, param);
PromiseDestroy(pcopy);
RlistDestroy(lists);
RlistDestroy(scalars);
RlistDestroy(containers);
return result;
}
示例11: KeepServerRolePromise
static void KeepServerRolePromise(EvalContext *ctx, Promise *pp)
{
Rlist *rp;
Auth *ap;
if (!GetAuthPath(pp->promiser, SV.roles))
{
InstallServerAuthPath(pp->promiser, &SV.roles, &SV.rolestop);
}
ap = GetAuthPath(pp->promiser, SV.roles);
for (size_t i = 0; i < SeqLength(pp->conlist); i++)
{
Constraint *cp = SeqAt(pp->conlist, i);
if (!IsDefinedClass(ctx, cp->classes, PromiseGetNamespace(pp)))
{
continue;
}
switch (cp->rval.type)
{
case RVAL_TYPE_LIST:
for (rp = (Rlist *) cp->rval.item; rp != NULL; rp = rp->next)
{
if (strcmp(cp->lval, CF_REMROLE_BODIES[REMOTE_ROLE_AUTHORIZE].lval) == 0)
{
PrependItem(&(ap->accesslist), rp->item, NULL);
continue;
}
}
break;
case RVAL_TYPE_FNCALL:
/* Shouldn't happen */
break;
default:
if ((strcmp(cp->lval, "comment") == 0) || (strcmp(cp->lval, "handle") == 0))
{
}
else
{
Log(LOG_LEVEL_ERR, "Right-hand side of authorize promise for '%s' should be a list", pp->promiser);
}
break;
}
}
}
示例12: UpdateDistributions
static void UpdateDistributions(EvalContext *ctx, char *timekey, Averages *av)
{
int position, day, i;
char filename[CF_BUFSIZE];
FILE *fp;
/* Take an interval of 4 standard deviations from -2 to +2, divided into CF_GRAINS
parts. Centre each measurement on CF_GRAINS/2 and scale each measurement by the
std-deviation for the current time.
*/
if (IsDefinedClass(ctx, "Min40_45", NULL))
{
day = Day2Number(timekey);
for (i = 0; i < CF_OBSERVABLES; i++)
{
position =
CF_GRAINS / 2 + (int) (0.5 + (CF_THIS[i] - av->Q[i].expect) * CF_GRAINS / (4 * sqrt((av->Q[i].var))));
if ((0 <= position) && (position < CF_GRAINS))
{
HISTOGRAM[i][day][position]++;
}
}
snprintf(filename, CF_BUFSIZE, "%s/state/histograms", CFWORKDIR);
if ((fp = fopen(filename, "w")) == NULL)
{
Log(LOG_LEVEL_ERR, "Unable to save histograms. (fopen: %s)", GetErrorStr());
return;
}
for (position = 0; position < CF_GRAINS; position++)
{
fprintf(fp, "%d ", position);
for (i = 0; i < CF_OBSERVABLES; i++)
{
for (day = 0; day < 7; day++)
{
fprintf(fp, "%.0lf ", HISTOGRAM[i][day][position]);
}
}
fprintf(fp, "\n");
}
fclose(fp);
}
}
示例13: KeepServerRolePromise
static void KeepServerRolePromise(Promise *pp)
{
Constraint *cp;
Rlist *rp;
Auth *ap;
if (!GetAuthPath(pp->promiser, ROLES))
{
InstallServerAuthPath(pp->promiser, &ROLES, &ROLESTOP);
}
ap = GetAuthPath(pp->promiser, ROLES);
for (cp = pp->conlist; cp != NULL; cp = cp->next)
{
if (!IsDefinedClass(cp->classes))
{
continue;
}
switch (cp->rval.rtype)
{
case CF_LIST:
for (rp = (Rlist *) cp->rval.item; rp != NULL; rp = rp->next)
{
if (strcmp(cp->lval, CF_REMROLE_BODIES[cfs_authorize].lval) == 0)
{
PrependItem(&(ap->accesslist), rp->item, NULL);
continue;
}
}
break;
case CF_FNCALL:
/* Shouldn't happen */
break;
default:
if (strcmp(cp->lval, "comment") == 0 || strcmp(cp->lval, "handle") == 0)
{
}
else
{
CfOut(cf_error, "", "RHS of authorize promise for %s should be a list\n", pp->promiser);
}
break;
}
}
}
示例14: ResolvePackageManagerBody
static void ResolvePackageManagerBody(EvalContext *ctx, const Body *pm_body)
{
PackageModuleBody *new_manager = xcalloc(1, sizeof(PackageModuleBody));
new_manager->name = SafeStringDuplicate(pm_body->name);
for (size_t i = 0; i < SeqLength(pm_body->conlist); i++)
{
Constraint *cp = SeqAt(pm_body->conlist, i);
Rval returnval = {0};
if (IsDefinedClass(ctx, cp->classes))
{
returnval = ExpandPrivateRval(ctx, NULL, "body",
cp->rval.item, cp->rval.type);
}
if (returnval.item == NULL || returnval.type == RVAL_TYPE_NOPROMISEE)
{
Log(LOG_LEVEL_VERBOSE, "have invalid constraint while resolving"
"package promise body: %s", cp->lval);
RvalDestroy(returnval);
continue;
}
if (strcmp(cp->lval, "query_installed_ifelapsed") == 0)
{
new_manager->installed_ifelapsed =
(int)IntFromString(RvalScalarValue(returnval));
}
else if (strcmp(cp->lval, "query_updates_ifelapsed") == 0)
{
new_manager->updates_ifelapsed =
(int)IntFromString(RvalScalarValue(returnval));
}
else if (strcmp(cp->lval, "default_options") == 0)
{
new_manager->options = RlistCopy(RvalRlistValue(returnval));
}
else
{
/* This should be handled by the parser. */
assert(0);
}
RvalDestroy(returnval);
}
AddPackageModuleToContext(ctx, new_manager);
}
示例15: KeepServerRolePromise
static void KeepServerRolePromise(EvalContext *ctx, const Promise *pp)
{
Rlist *rp;
Auth *ap;
ap = GetOrCreateAuth(pp->promiser, &SV.roles, &SV.rolestail);
for (size_t i = 0; i < SeqLength(pp->conlist); i++)
{
Constraint *cp = SeqAt(pp->conlist, i);
if (!IsDefinedClass(ctx, cp->classes))
{
continue;
}
switch (cp->rval.type)
{
case RVAL_TYPE_LIST:
for (rp = (Rlist *) cp->rval.item; rp != NULL; rp = rp->next)
{
/* This is for remote class activation by means of cf-runagent.*/
if (strcmp(cp->lval, CF_REMROLE_BODIES[REMOTE_ROLE_AUTHORIZE].lval) == 0)
{
PrependItem(&(ap->accesslist), RlistScalarValue(rp), NULL);
continue;
}
}
break;
case RVAL_TYPE_FNCALL:
UnexpectedError("Constraint of type FNCALL is invalid in this context!");
break;
default:
if ((strcmp(cp->lval, "comment") == 0) || (strcmp(cp->lval, "handle") == 0))
{
}
else
{
Log(LOG_LEVEL_ERR, "Right-hand side of authorize promise for '%s' should be a list", pp->promiser);
}
break;
}
}
}