Return int not bool for all tmpl functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 5 Mar 2015 01:35:24 +0000 (20:35 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 5 Mar 2015 01:35:24 +0000 (20:35 -0500)
src/include/tmpl.h
src/main/map.c
src/main/modcall.c
src/main/parser.c
src/main/tmpl.c
src/modules/rlm_cache/serialize.c

index 979ef30..1fb35c3 100644 (file)
@@ -307,7 +307,7 @@ ssize_t                     tmpl_afrom_attr_str(TALLOC_CTX *ctx, value_pair_tmpl_t **out, char con
 ssize_t                        tmpl_afrom_str(TALLOC_CTX *ctx, value_pair_tmpl_t **out, char const *name, size_t inlen,
                                       FR_TOKEN type, request_refs_t request_def, pair_lists_t list_def, bool do_escape);
 
-bool                   tmpl_cast_in_place(value_pair_tmpl_t *vpt, PW_TYPE type, DICT_ATTR const *enumv);
+int                    tmpl_cast_in_place(value_pair_tmpl_t *vpt, PW_TYPE type, DICT_ATTR const *enumv);
 
 void                   tmpl_cast_in_place_str(value_pair_tmpl_t *vpt);
 
@@ -333,7 +333,7 @@ int                 tmpl_copy_vps(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request,
 
 int                    tmpl_find_vp(VALUE_PAIR **out, REQUEST *request, value_pair_tmpl_t const *vpt);
 
-bool                   tmpl_define_unknown_attr(value_pair_tmpl_t *vpt);
+int                    tmpl_define_unknown_attr(value_pair_tmpl_t *vpt);
 
 #ifdef __cplusplus
 }
index 5ed95f6..860bcfb 100644 (file)
@@ -214,7 +214,7 @@ int map_afrom_cp(TALLOC_CTX *ctx, value_pair_map_t **out, CONF_PAIR *cp,
                        goto marker;
                }
 
-               if (!tmpl_define_unknown_attr(map->lhs)) {
+               if (tmpl_define_unknown_attr(map->lhs) < 0) {
                        cf_log_err_cp(cp, "Failed creating attribute %s: %s",
                                      map->lhs->name, fr_strerror());
                        goto error;
@@ -233,7 +233,7 @@ int map_afrom_cp(TALLOC_CTX *ctx, value_pair_map_t **out, CONF_PAIR *cp,
        } else {
                slen = tmpl_afrom_str(map, &map->rhs, value, strlen(value), type, src_request_def, src_list_def, true);
                if (slen < 0) goto marker;
-               if (!tmpl_define_unknown_attr(map->rhs)) {
+               if (tmpl_define_unknown_attr(map->rhs) < 0) {
                        cf_log_err_cp(cp, "Failed creating attribute %s: %s", map->rhs->name, fr_strerror());
                        goto error;
                }
index 0c8cada..b21c157 100644 (file)
@@ -1652,7 +1652,7 @@ int modcall_fixup_update(value_pair_map_t *map, UNUSED void *ctx)
                    (cf_pair_value_type(cp) == T_SINGLE_QUOTED_STRING)) {
                        tmpl_cast_in_place_str(map->rhs);
                } else {
-                       if (!tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da)) {
+                       if (tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da) < 0) {
                                cf_log_err(map->ci, "%s", fr_strerror());
                                return -1;
                        }
@@ -3580,7 +3580,7 @@ bool modcall_pass2(modcallable *mc)
                                if (f->vpt->type == TMPL_TYPE_ATTR) {
                                        rad_assert(f->vpt->tmpl_da != NULL);
 
-                                       if (!tmpl_cast_in_place(g->vpt, f->vpt->tmpl_da->type, f->vpt->tmpl_da)) {
+                                       if (tmpl_cast_in_place(g->vpt, f->vpt->tmpl_da->type, f->vpt->tmpl_da) < 0) {
                                                cf_log_err_cs(g->cs, "Invalid argument for case statement: %s",
                                                              fr_strerror());
                                                return false;
index ae1f87c..48e1381 100644 (file)
@@ -710,7 +710,7 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st
                                return_P(fr_strerror());
                        }
 
-                       if (!tmpl_define_unknown_attr(map->lhs)) {
+                       if (tmpl_define_unknown_attr(map->lhs) < 0) {
                                return_lhs("Failed defining attribute");
                        return_lhs:
                                if (lhs) talloc_free(lhs);
@@ -756,7 +756,7 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st
                                        return_P(fr_strerror());
                                }
 
-                               if (!tmpl_define_unknown_attr(map->rhs)) {
+                               if (tmpl_define_unknown_attr(map->rhs) < 0) {
                                        return_rhs("Failed defining attribute");
                                }
                        }
@@ -813,7 +813,7 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st
                                 *      Cast it to the appropriate data type.
                                 */
                                if ((c->data.map->lhs->type == TMPL_TYPE_LITERAL) &&
-                                   !tmpl_cast_in_place(c->data.map->lhs, c->cast->type, c->cast)) {
+                                   (tmpl_cast_in_place(c->data.map->lhs, c->cast->type, c->cast) < 0)) {
                                        *error = "Failed to parse field";
                                        if (lhs) talloc_free(lhs);
                                        if (rhs) talloc_free(rhs);
@@ -827,7 +827,7 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st
                                 */
                                if ((c->data.map->lhs->type == TMPL_TYPE_DATA) &&
                                    (c->data.map->rhs->type == TMPL_TYPE_LITERAL) &&
-                                   !tmpl_cast_in_place(c->data.map->rhs, c->cast->type, c->cast)) {
+                                   (tmpl_cast_in_place(c->data.map->rhs, c->cast->type, c->cast) < 0)) {
                                        return_rhs("Failed to parse field");
                                }
 
@@ -1023,7 +1023,7 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st
                                 *      literal.  Cast the RHS to the type of the cast.
                                 */
                                if (c->cast && (c->data.map->rhs->type == TMPL_TYPE_LITERAL) &&
-                                   !tmpl_cast_in_place(c->data.map->rhs, c->cast->type, c->cast)) {
+                                   (tmpl_cast_in_place(c->data.map->rhs, c->cast->type, c->cast) < 0)) {
                                        return_rhs("Failed to parse field");
                                }
 
@@ -1054,7 +1054,7 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st
                                                break;
                                        }
 
-                                       if (!tmpl_cast_in_place(c->data.map->rhs, type, c->data.map->lhs->tmpl_da)) {
+                                       if (tmpl_cast_in_place(c->data.map->rhs, type, c->data.map->lhs->tmpl_da) < 0) {
                                                DICT_ATTR const *da = c->data.map->lhs->tmpl_da;
 
                                                if ((da->vendor == 0) &&
index 2f19643..e7601de 100644 (file)
@@ -1036,9 +1036,9 @@ ssize_t tmpl_afrom_str(TALLOC_CTX *ctx, value_pair_tmpl_t **out, char const *in,
  * @param[in,out] vpt The template to modify. Must be of type #TMPL_TYPE_LITERAL.
  * @param[in] type to cast to.
  * @param[in] enumv Enumerated dictionary values associated with a #DICT_ATTR.
- * @return true for success, false for failure.
+ * @return 0 on success, -1 on failure.
  */
-bool tmpl_cast_in_place(value_pair_tmpl_t *vpt, PW_TYPE type, DICT_ATTR const *enumv)
+int tmpl_cast_in_place(value_pair_tmpl_t *vpt, PW_TYPE type, DICT_ATTR const *enumv)
 {
        ssize_t ret;
 
@@ -1053,14 +1053,14 @@ bool tmpl_cast_in_place(value_pair_tmpl_t *vpt, PW_TYPE type, DICT_ATTR const *e
         *      Why do we pass a pointer to the tmpl type? Goddamn WiMAX.
         */
        ret = value_data_from_str(vpt, &vpt->tmpl_data_value, &vpt->tmpl_data_type, enumv, vpt->name, vpt->len, '\0');
-       if (ret < 0) return false;
+       if (ret < 0) return -1;
 
        vpt->type = TMPL_TYPE_DATA;
        vpt->tmpl_data_length = (size_t) ret;
 
        VERIFY_TMPL(vpt);
 
-       return true;
+       return 0;
 }
 
 /** Convert #value_pair_tmpl_t of type #TMPL_TYPE_LITERAL to #TMPL_TYPE_DATA of type #PW_TYPE_STRING
@@ -1150,27 +1150,27 @@ int tmpl_cast_to_vp(VALUE_PAIR **out, REQUEST *request,
  *
  * @param vpt to add. ``tmpl_da`` pointer will be updated to point to the
  *     #DICT_ATTR inserted into the dictionary.
- * @return true on success, false on failure.
+ * @return 0 on success, -1 on failure.
  */
-bool tmpl_define_unknown_attr(value_pair_tmpl_t *vpt)
+int tmpl_define_unknown_attr(value_pair_tmpl_t *vpt)
 {
        DICT_ATTR const *da;
 
-       if (!vpt) return false;
+       if (!vpt) return -1;
 
        VERIFY_TMPL(vpt);
 
        if ((vpt->type != TMPL_TYPE_ATTR) &&
            (vpt->type != TMPL_TYPE_DATA)) {
-               return true;
+               return 0;
        }
 
-       if (!vpt->tmpl_da->flags.is_unknown) return true;
+       if (!vpt->tmpl_da->flags.is_unknown) return 0;
 
        da = dict_unknown_add(vpt->tmpl_da);
-       if (!da) return false;
+       if (!da) return -1;
        vpt->tmpl_da = da;
-       return true;
+       return 0;
 }
 /* @} **/
 
index ad917fc..66f2b97 100644 (file)
@@ -171,7 +171,7 @@ int cache_deserialize(rlm_cache_entry_t *c, char *in, ssize_t inlen)
                 *      Convert literal to a type appropriate for
                 *      the VP.
                 */
-               if (!tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da)) goto error;
+               if (tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da) < 0) goto error;
 
                vp = pairalloc(c, map->lhs->tmpl_da);
                len = value_data_copy(vp, &vp->data, map->rhs->tmpl_data_type,