pespin submitted this change.
sccp_user: Move lookup to helper function to simplify code
Keep lookup logic separate from already complex function with lots of
logic involved.
Change-Id: Ia2c8f9598e28be747bb3f1a61a1d8b0aa3d267b3
---
M src/sccp_user.c
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/sccp_user.c b/src/sccp_user.c
index cada057..d60d66a 100644
--- a/src/sccp_user.c
+++ b/src/sccp_user.c
@@ -491,6 +491,18 @@
* Convenience function for CLIENT
***********************************************************************/
+ /* Returns whether AS is already associated to any AS.
+ * Helper function for osmo_sccp_simple_client_on_ss7_id(). */
+static bool asp_serves_some_as(const struct osmo_ss7_asp *asp)
+{
+ struct osmo_ss7_as *as_i;
+ llist_for_each_entry(as_i, &asp->inst->as_list, list) {
+ if (osmo_ss7_as_has_asp(as_i, asp))
+ return true;
+ }
+ return false;
+}
+
/*! \brief request an sccp client instance
* \param[in] ctx talloc context
* \param[in] ss7_id of the SS7/CS7 instance
@@ -610,18 +622,11 @@
/* Check if the user has created an ASP for this proto that is not added on any AS yet. */
struct osmo_ss7_asp *asp_i;
llist_for_each_entry(asp_i, &ss7->asp_list, list) {
- struct osmo_ss7_as *as_i;
- bool is_on_as = false;
if (asp_i->cfg.proto != prot)
continue;
- llist_for_each_entry(as_i, &ss7->as_list, list) {
- if (!osmo_ss7_as_has_asp(as_i, asp_i))
- continue;
- is_on_as = true;
- break;
- }
- if (is_on_as) {
- /* This ASP is already on another AS. If it was on this AS, we'd have found it above. */
+ if (asp_serves_some_as(asp_i)) {
+ /* This ASP is already on another AS.
+ * If it was on this AS, we'd have found it above. */
continue;
}
/* This ASP matches the protocol and is not yet associated to any AS. Use it. */
To view, visit change 39674. To unsubscribe, or for help writing mail filters, visit settings.