Add macros to simplify usage of several _add() functions.
authorJennifer Richards <jennifer@painless-security.com>
Mon, 26 Sep 2016 17:07:35 +0000 (13:07 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Mon, 26 Sep 2016 17:07:35 +0000 (13:07 -0400)
common/tr_apc.c
common/tr_comm.c
common/tr_config.c
common/tr_idp.c
common/tr_rp.c
include/tr_apc.h
include/tr_comm.h
include/tr_idp.h
include/tr_rp.h

index b810fd8..1a629a0 100644 (file)
@@ -71,7 +71,8 @@ static TR_APC *tr_apc_tail(TR_APC *apc)
   return apc;
 }
 
-TR_APC *tr_apc_add(TR_APC *head, TR_APC *new)
+/* do not call this directly, use the tr_apc_add() macro */
+TR_APC *tr_apc_add_func(TR_APC *head, TR_APC *new)
 {
   if (head==NULL)
     head=new;
index fe4476a..56261b9 100644 (file)
@@ -105,9 +105,9 @@ static TR_COMM *tr_comm_tail(TR_COMM *comm)
 
 /* All list members are in the talloc context of the head.
  * This will require careful thought if entries are ever removed
- * or shuffled between lists. 
- * Call like comms=tr_comm_add(comms, new_comm); */
-TR_COMM *tr_comm_add(TR_COMM *comms, TR_COMM *new)
+ * Call like comms=tr_comm_add_func(comms, new_comm);
+ * or just use the tr_comm_add(comms, new) macro. */
+TR_COMM *tr_comm_add_func(TR_COMM *comms, TR_COMM *new)
 {
   if (comms==NULL)
     comms=new;
index 0bdaab6..f199082 100644 (file)
@@ -651,7 +651,7 @@ static TR_APC *tr_cfg_parse_apcs(TALLOC_CTX *mem_ctx, json_t *japcs, TR_CFG_RC *
       *rc=TR_CFG_NOPARSE;
       goto cleanup;
     }
-    apcs=tr_apc_add(apcs, new_apc);
+    tr_apc_add(apcs, new_apc);
   }
 
   talloc_steal(mem_ctx, apcs);
@@ -932,7 +932,7 @@ static TR_IDP_REALM *tr_cfg_parse_idp_realms(TALLOC_CTX *mem_ctx, json_t *jrealm
         *rc=TR_CFG_NOPARSE;
         goto cleanup;
       }
-      realms=tr_idp_realm_add(realms, new_realm);
+      tr_idp_realm_add(realms, new_realm);
     } else if (tr_cfg_is_remote_realm(this_jrealm)) {
       new_realm=tr_cfg_parse_one_remote_realm(tmp_ctx, this_jrealm, rc);
       if ((*rc)!=TR_CFG_SUCCESS) {
@@ -940,7 +940,7 @@ static TR_IDP_REALM *tr_cfg_parse_idp_realms(TALLOC_CTX *mem_ctx, json_t *jrealm
         *rc=TR_CFG_NOPARSE;
         goto cleanup;
       }
-      realms=tr_idp_realm_add(realms, new_realm);
+      tr_idp_realm_add(realms, new_realm);
     }
   }
   
@@ -1313,7 +1313,7 @@ static TR_RP_CLIENT *tr_cfg_parse_rp_clients(TALLOC_CTX *mem_ctx, json_t *jrealm
         *rc=TR_CFG_NOPARSE;
         goto cleanup;
       }
-      clients=tr_rp_client_add(clients, new_client);
+      tr_rp_client_add(clients, new_client);
     }
   }
   
@@ -1378,7 +1378,7 @@ static TR_COMM *tr_cfg_comm_idp_update(TALLOC_CTX *mem_ctx, TR_COMM *comms, TR_I
         comm->expiration_interval=TR_DEFAULT_APC_EXPIRATION_INTERVAL;
         comm->id=tr_dup_name(apc->id);
         tr_comm_add_idp_realm(comm, realm);
-        new_comms=tr_comm_add(new_comms, comm);
+        tr_comm_add(new_comms, comm);
       } else {
         /* add this realm to the comm */
         tr_comm_add_idp_realm(comm, realm);
@@ -1387,7 +1387,7 @@ static TR_COMM *tr_cfg_comm_idp_update(TALLOC_CTX *mem_ctx, TR_COMM *comms, TR_I
   }
 
   /* we successfully built a list, add it to the other list */
-  comms=tr_comm_add(comms, new_comms);
+  tr_comm_add(comms, new_comms);
   talloc_steal(mem_ctx, comms);
  cleanup:
   talloc_free(tmp_ctx);
@@ -1443,12 +1443,12 @@ cleanup:
   /* if we succeeded, link things to the configuration and move out of tmp context */
   if (retval==TR_CFG_SUCCESS) {
     if (new_idp_realms!=NULL) {
-      trc->idp_realms=tr_idp_realm_add(trc->idp_realms, new_idp_realms); /* fixes talloc contexts except for head*/
+      tr_idp_realm_add(trc->idp_realms, new_idp_realms); /* fixes talloc contexts except for head*/
       talloc_steal(trc, trc->idp_realms); /* make sure the head is in the right context */
     }
 
     if (new_rp_clients!=NULL) {
-      trc->rp_clients=tr_rp_client_add(trc->rp_clients, new_rp_clients); /* fixes talloc contexts */
+      tr_rp_client_add(trc->rp_clients, new_rp_clients); /* fixes talloc contexts */
       talloc_steal(trc, trc->rp_clients); /* make sure head is in the right context */
     }
   }
index 2ef9e93..b035d5a 100644 (file)
@@ -123,8 +123,8 @@ static TR_IDP_REALM *tr_idp_realm_tail(TR_IDP_REALM *idp)
   return idp;
 }
 
-/* for correct behavior, call like: idp_realms=tr_idp_realm_add(idp_realms, new_realm); */
-TR_IDP_REALM *tr_idp_realm_add(TR_IDP_REALM *head, TR_IDP_REALM *new)
+/* do not call directly, use the tr_idp_realm_add() macro */
+TR_IDP_REALM *tr_idp_realm_add_func(TR_IDP_REALM *head, TR_IDP_REALM *new)
 {
   if (head==NULL)
     head=new;
index 96c7254..3897e58 100644 (file)
@@ -75,7 +75,8 @@ static TR_RP_CLIENT *tr_rp_client_tail(TR_RP_CLIENT *client)
   return client;
 }
 
-TR_RP_CLIENT *tr_rp_client_add(TR_RP_CLIENT *clients, TR_RP_CLIENT *new)
+/* do not call directly, use the tr_rp_client_add() macro */
+TR_RP_CLIENT *tr_rp_client_add_func(TR_RP_CLIENT *clients, TR_RP_CLIENT *new)
 {
   if (clients==NULL)
     clients=new;
@@ -133,7 +134,7 @@ static TR_RP_REALM *tr_rp_realm_tail(TR_RP_REALM *realm)
 }
 
 /* for correct behavior, call like: rp_realms=tr_rp_realm_add(rp_realms, new_realm); */
-TR_RP_REALM *tr_rp_realm_add(TR_RP_REALM *head, TR_RP_REALM *new)
+TR_RP_REALM *tr_rp_realm_add_func(TR_RP_REALM *head, TR_RP_REALM *new)
 {
   if (head==NULL)
     head=new;
index 80b35b3..6257d24 100644 (file)
@@ -47,7 +47,8 @@ typedef struct tr_apc {
 
 TR_APC *tr_apc_new(TALLOC_CTX *mem_ctx);
 void tr_apc_free(TR_APC *apc);
-TR_APC *tr_apc_add(TR_APC *apcs, TR_APC *new);
+TR_APC *tr_apc_add_func(TR_APC *apcs, TR_APC *new);
+#define tr_apc_add(apcs,new) ((apcs)=tr_apc_add_func((apcs),(new)))
 TR_APC *tr_apc_dup(TALLOC_CTX *mem_ctx, TR_APC *apc);
 
 void tr_apc_set_id(TR_APC *apc, TR_NAME *id);
index 2d753b6..8b7f445 100644 (file)
@@ -57,7 +57,8 @@ typedef struct tr_comm {
 
 TR_COMM *tr_comm_new(TALLOC_CTX *mem_ctx);
 void tr_comm_free(TR_COMM *comm);
-TR_COMM *tr_comm_add(TR_COMM *comms, TR_COMM *new);
+TR_COMM *tr_comm_add_func(TR_COMM *comms, TR_COMM *new); /* use the macro instead */
+#define tr_comm_add(comms, new) ((comms)=tr_comm_add_func((comms), (new)))
 void tr_comm_add_idp_realm(TR_COMM *comm, TR_IDP_REALM *realm);
 void tr_comm_add_rp_realm(TR_COMM *comm, TR_RP_REALM *realm);
 TR_COMM *tr_comm_lookup(TR_COMM *comms, TR_NAME *comm_name);
index 9af36d2..9b44cf0 100644 (file)
@@ -64,7 +64,8 @@ typedef struct tr_idp_realm {
 } TR_IDP_REALM;
   
 TR_IDP_REALM *tr_idp_realm_new(TALLOC_CTX *mem_ctx);
-TR_IDP_REALM *tr_idp_realm_add(TR_IDP_REALM *head, TR_IDP_REALM *new);
+TR_IDP_REALM *tr_idp_realm_add_func(TR_IDP_REALM *head, TR_IDP_REALM *new);
+#define tr_idp_realm_add(head,new) ((head)=tr_idp_realm_add_func((head),(new)))
 char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp);
 
 TR_AAA_SERVER *tr_aaa_server_new(TALLOC_CTX *mem_ctx, TR_NAME *hostname);
index 9db8c15..aab3ce1 100644 (file)
@@ -56,10 +56,12 @@ typedef struct tr_rp_realm {
 /* prototypes */
 TR_RP_CLIENT *tr_rp_client_new(TALLOC_CTX *mem_ctx);
 void tr_rp_client_free(TR_RP_CLIENT *client);
-TR_RP_CLIENT *tr_rp_client_add(TR_RP_CLIENT *clients, TR_RP_CLIENT *new);
+TR_RP_CLIENT *tr_rp_client_add_func(TR_RP_CLIENT *clients, TR_RP_CLIENT *new);
+#define tr_rp_client_add(clients,new) ((clients)=tr_rp_client_add_func((clients),(new)))
 int tr_rp_client_add_gss_name(TR_RP_CLIENT *client, TR_NAME *name);
 int tr_rp_client_set_filter(TR_RP_CLIENT *client, TR_FILTER *filt);
 
 TR_RP_CLIENT *tr_rp_client_lookup(TR_RP_CLIENT *rp_clients, TR_NAME *gss_name);
-TR_RP_REALM *tr_rp_realm_add(TR_RP_REALM *head, TR_RP_REALM *new);
+TR_RP_REALM *tr_rp_realm_add_func(TR_RP_REALM *head, TR_RP_REALM *new);
+#define tr_rp_realm_add(head,new) ((head)=tr_rp_realm_add_func((head),(new)))
 #endif