本文整理汇总了C++中StringSetAdd函数的典型用法代码示例。如果您正苦于以下问题:C++ StringSetAdd函数的具体用法?C++ StringSetAdd怎么用?C++ StringSetAdd使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringSetAdd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StringSetAddSplit
void StringSetAddSplit(StringSet *set, const char *str, char delimiter)
{
assert(set != NULL);
if (str) // TODO: remove this inconsistency, add assert(str)
{
const char *prev = str;
const char *cur = str;
while (*cur != '\0')
{
if (*cur == delimiter)
{
size_t len = cur - prev;
if (len > 0)
{
StringSetAdd(set, xstrndup(prev, len));
}
else
{
StringSetAdd(set, xstrdup(""));
}
prev = cur + 1;
}
cur++;
}
if (cur > prev)
{
StringSetAdd(set, xstrndup(prev, cur - prev));
}
}
}
示例2: SelectOwnerMatch
static int SelectOwnerMatch(EvalContext *ctx, char *path, struct stat *lstatptr, Rlist *crit)
{
Rlist *rp;
char ownerName[CF_BUFSIZE];
int gotOwner;
StringSet *leafattrib = StringSetNew();
#ifndef __MINGW32__ // no uids on Windows
char buffer[CF_SMALLBUF];
snprintf(buffer, CF_SMALLBUF, "%jd", (uintmax_t) lstatptr->st_uid);
StringSetAdd(leafattrib, xstrdup(buffer));
#endif /* __MINGW32__ */
gotOwner = GetOwnerName(path, lstatptr, ownerName, sizeof(ownerName));
if (gotOwner)
{
StringSetAdd(leafattrib, xstrdup(ownerName));
}
else
{
StringSetAdd(leafattrib, xstrdup("none"));
}
for (rp = crit; rp != NULL; rp = rp->next)
{
if (EvalFileResult((char *) rp->item, leafattrib))
{
Log(LOG_LEVEL_DEBUG, "Select owner match");
StringSetDestroy(leafattrib);
return true;
}
if (gotOwner && (FullTextMatch(ctx, RlistScalarValue(rp), ownerName)))
{
Log(LOG_LEVEL_DEBUG, "Select owner match");
StringSetDestroy(leafattrib);
return true;
}
#ifndef __MINGW32__
if (FullTextMatch(ctx, RlistScalarValue(rp), buffer))
{
Log(LOG_LEVEL_DEBUG, "Select owner match");
StringSetDestroy(leafattrib);
return true;
}
#endif /* !__MINGW32__ */
}
StringSetDestroy(leafattrib);
return false;
}
示例3: TransformGidsToGroups
static void TransformGidsToGroups(StringSet **list)
{
StringSet *new_list = StringSetNew();
StringSetIterator i = StringSetIteratorInit(*list);
const char *data;
for (data = StringSetIteratorNext(&i); data; data = StringSetIteratorNext(&i))
{
if (strlen(data) != strspn(data, "0123456789"))
{
// Cannot possibly be a gid.
StringSetAdd(new_list, xstrdup(data));
continue;
}
// In groups vs gids, groups take precedence. So check if it exists.
struct group *group_info = GetGrEntry(data, &EqualGroupName);
if (!group_info)
{
if (errno == 0)
{
group_info = GetGrEntry(data, &EqualGid);
if (!group_info)
{
if (errno != 0)
{
Log(LOG_LEVEL_ERR, "Error while checking group name '%s': %s", data, GetErrorStr());
StringSetDestroy(new_list);
return;
}
// Neither group nor gid is found. This will lead to an error later, but we don't
// handle that here.
}
else
{
// Replace gid with group name.
StringSetAdd(new_list, xstrdup(group_info->gr_name));
}
}
else
{
Log(LOG_LEVEL_ERR, "Error while checking group name '%s': '%s'", data, GetErrorStr());
StringSetDestroy(new_list);
return;
}
}
else
{
StringSetAdd(new_list, xstrdup(data));
}
}
StringSet *old_list = *list;
*list = new_list;
StringSetDestroy(old_list);
}
示例4: Cf3ParseFile
static Policy *LoadPolicyFile(EvalContext *ctx, GenericAgentConfig *config, const char *policy_file, StringSet *parsed_files, StringSet *failed_files)
{
Policy *policy = Cf3ParseFile(config, policy_file);
StringSetAdd(parsed_files, xstrdup(policy_file));
if (!policy)
{
StringSetAdd(failed_files, xstrdup(policy_file));
return NULL;
}
PolicyResolve(ctx, policy, config);
Body *body_common_control = PolicyGetBody(policy, NULL, "common", "control");
Body *body_file_control = PolicyGetBody(policy, NULL, "file", "control");
if (body_common_control)
{
Seq *potential_inputs = BodyGetConstraint(body_common_control, "inputs");
Constraint *cp = EffectiveConstraint(ctx, potential_inputs);
SeqDestroy(potential_inputs);
if (cp)
{
Policy *aux_policy = LoadPolicyInputFiles(ctx, config, RvalRlistValue(cp->rval), parsed_files, failed_files);
if (aux_policy)
{
policy = PolicyMerge(policy, aux_policy);
}
}
}
PolicyResolve(ctx, policy, config);
if (body_file_control)
{
Seq *potential_inputs = BodyGetConstraint(body_file_control, "inputs");
Constraint *cp = EffectiveConstraint(ctx, potential_inputs);
SeqDestroy(potential_inputs);
if (cp)
{
Policy *aux_policy = LoadPolicyInputFiles(ctx, config, RvalRlistValue(cp->rval), parsed_files, failed_files);
if (aux_policy)
{
policy = PolicyMerge(policy, aux_policy);
}
}
}
return policy;
}
示例5: ClassInit
/**
* @param #tags is a comma separated string of words.
* Both "" or NULL are equivalent.
*/
static void ClassInit(Class *cls,
const char *ns, const char *name,
bool is_soft, ContextScope scope, const char *tags)
{
if (ns == NULL || strcmp(ns, "default") == 0)
{
cls->ns = NULL;
}
else
{
cls->ns = xstrdup(ns);
}
cls->name = xstrdup(name);
CanonifyNameInPlace(cls->name);
cls->is_soft = is_soft;
cls->scope = scope;
cls->tags = StringSetFromString(tags, ',');
if (!is_soft && !StringSetContains(cls->tags, "hardclass"))
{
StringSetAdd(cls->tags, xstrdup("hardclass"));
}
}
示例6: GroupGetUserMembership
static bool GroupGetUserMembership (const char *user, StringSet *result)
{
bool ret = true;
struct group *group_info;
setgrent();
while (true)
{
errno = 0;
group_info = getgrent();
if (!group_info)
{
if (errno)
{
Log(LOG_LEVEL_ERR, "Error while getting group list. (getgrent: '%s')", GetErrorStr());
ret = false;
}
break;
}
for (int i = 0; group_info->gr_mem[i] != NULL; i++)
{
if (strcmp(user, group_info->gr_mem[i]) == 0)
{
StringSetAdd(result, xstrdup(group_info->gr_name));
break;
}
}
}
endgrent();
return ret;
}
示例7: EvalContextStackFrameAddNegated
void EvalContextStackFrameAddNegated(EvalContext *ctx, const char *context)
{
StackFrame *frame = LastStackFrameBundle(ctx);
assert(frame);
StringSetAdd(frame->data.bundle.contexts_negated, xstrdup(context));
}
示例8: SelectGroupMatch
static int SelectGroupMatch(EvalContext *ctx, struct stat *lstatptr, Rlist *crit)
{
char buffer[CF_SMALLBUF];
struct group *gr;
Rlist *rp;
StringSet *leafattrib = StringSetNew();
snprintf(buffer, CF_SMALLBUF, "%jd", (uintmax_t) lstatptr->st_gid);
StringSetAdd(leafattrib, xstrdup(buffer));
if ((gr = getgrgid(lstatptr->st_gid)) != NULL)
{
StringSetAdd(leafattrib, xstrdup(gr->gr_name));
}
else
{
StringSetAdd(leafattrib, xstrdup("none"));
}
for (rp = crit; rp != NULL; rp = rp->next)
{
if (EvalFileResult((char *) rp->item, leafattrib))
{
Log(LOG_LEVEL_DEBUG, "Select group match");
StringSetDestroy(leafattrib);
return true;
}
if (gr && (FullTextMatch(ctx, (char *) rp->item, gr->gr_name)))
{
Log(LOG_LEVEL_DEBUG, "Select group match");
StringSetDestroy(leafattrib);
return true;
}
if (FullTextMatch(ctx, (char *) rp->item, buffer))
{
Log(LOG_LEVEL_DEBUG, "Select group match");
StringSetDestroy(leafattrib);
return true;
}
}
StringSetDestroy(leafattrib);
return false;
}
示例9: 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;
}
}
}
}
示例10: while
StringSet *StringSetAddAllMatchingIterator(StringSet* base, StringSetIterator it, const char *filter_regex)
{
const char *element = NULL;
while ((element = SetIteratorNext(&it)))
{
if (StringMatch(filter_regex, element))
{
StringSetAdd(base, xstrdup(element));
}
}
return base;
}
示例11: MarkPromiseHandleDone
void MarkPromiseHandleDone(EvalContext *ctx, const Promise *pp)
{
char name[CF_BUFSIZE];
const char *handle = PromiseGetHandle(pp);
if (handle == NULL)
{
return;
}
snprintf(name, CF_BUFSIZE, "%s:%s", PromiseGetNamespace(pp), handle);
StringSetAdd(ctx->dependency_handles, xstrdup(name));
}
示例12: GroupGetUserMembership
static bool GroupGetUserMembership (const char *user, StringSet *result)
{
bool ret = true;
struct group *group_info;
FILE *fptr = fopen("/etc/group", "r");
if (!fptr)
{
Log(LOG_LEVEL_ERR, "Could not open '/etc/group': %s", GetErrorStr());
return false;
}
while (true)
{
errno = 0;
// Use fgetgrent() instead of getgrent(), to guarantee that the
// returned group is a local group, and not for example from LDAP.
group_info = fgetgrent(fptr);
if (!group_info)
{
// Documentation among Unices is conflicting on return codes. When there
// are no more entries, this happens:
// Linux = ENOENT
// AIX = ESRCH
if (errno && errno != ENOENT && errno != ESRCH)
{
Log(LOG_LEVEL_ERR, "Error while getting group list. (fgetgrent: '%s')", GetErrorStr());
ret = false;
}
break;
}
for (int i = 0; group_info->gr_mem[i] != NULL; i++)
{
if (strcmp(user, group_info->gr_mem[i]) == 0)
{
StringSetAdd(result, xstrdup(group_info->gr_name));
break;
}
}
}
fclose(fptr);
return ret;
}
示例13: StringSetNew
StringSet *StringSetFromString(const char *str, char delimiter)
{
StringSet *set = StringSetNew();
char delimiters[2] = { 0 };
delimiters[0] = delimiter;
char *copy = xstrdup(str);
char *curr = NULL;
while ((curr = strsep(©, delimiters)))
{
StringSetAdd(set, xstrdup(curr));
}
free(copy);
return set;
}
示例14: MarkPromiseHandleDone
void MarkPromiseHandleDone(EvalContext *ctx, const Promise *pp)
{
if (pp == NULL)
{
return;
}
char name[CF_BUFSIZE];
char *handle = ConstraintGetRvalValue(ctx, "handle", pp, RVAL_TYPE_SCALAR);
if (handle == NULL)
{
return;
}
snprintf(name, CF_BUFSIZE, "%s:%s", PromiseGetNamespace(pp), handle);
StringSetAdd(ctx->dependency_handles, xstrdup(name));
}
示例15: SelectLeaf
int SelectLeaf(EvalContext *ctx, char *path, struct stat *sb, FileSelect fs)
{
int result = true;
Rlist *rp;
StringSet *leaf_attr = StringSetNew();
#ifdef __MINGW32__
if (fs.issymlinkto != NULL)
{
Log(LOG_LEVEL_VERBOSE,
"files_select.issymlinkto is ignored on Windows (symbolic links are not supported by Windows)");
}
if (fs.groups != NULL)
{
Log(LOG_LEVEL_VERBOSE,
"files_select.search_groups is ignored on Windows (file groups are not supported by Windows)");
}
if (fs.bsdflags != NULL)
{
Log(LOG_LEVEL_VERBOSE, "files_select.search_bsdflags is ignored on Windows");
}
#endif /* __MINGW32__ */
if (fs.name == NULL)
{
StringSetAdd(leaf_attr, xstrdup("leaf_name"));
}
for (rp = fs.name; rp != NULL; rp = rp->next)
{
if (SelectNameRegexMatch(ctx, path, rp->item))
{
StringSetAdd(leaf_attr, xstrdup("leaf_name"));
break;
}
}
if (fs.path == NULL)
{
StringSetAdd(leaf_attr, xstrdup("leaf_path"));
}
for (rp = fs.path; rp != NULL; rp = rp->next)
{
if (SelectPathRegexMatch(ctx, path, rp->item))
{
StringSetAdd(leaf_attr, xstrdup("path_name"));
break;
}
}
if (SelectTypeMatch(sb, fs.filetypes))
{
StringSetAdd(leaf_attr, xstrdup("file_types"));
}
if ((fs.owners) && (SelectOwnerMatch(ctx, path, sb, fs.owners)))
{
StringSetAdd(leaf_attr, xstrdup("owner"));
}
if (fs.owners == NULL)
{
StringSetAdd(leaf_attr, xstrdup("owner"));
}
#ifdef __MINGW32__
StringSetAdd(leaf_attr, xstrdup("group"));
#else /* !__MINGW32__ */
if ((fs.groups) && (SelectGroupMatch(ctx, sb, fs.groups)))
{
StringSetAdd(leaf_attr, xstrdup("group"));
}
if (fs.groups == NULL)
{
StringSetAdd(leaf_attr, xstrdup("group"));
}
#endif /* !__MINGW32__ */
if (SelectModeMatch(sb, fs.perms))
{
StringSetAdd(leaf_attr, xstrdup("mode"));
}
#if defined HAVE_CHFLAGS
if (SelectBSDMatch(sb, fs.bsdflags))
{
StringSetAdd(leaf_attr, xstrdup("bsdflags"));
}
#endif
if (SelectTimeMatch(sb->st_atime, fs.min_atime, fs.max_atime))
{
StringSetAdd(leaf_attr, xstrdup("atime"));
}
//.........这里部分代码省略.........