[asterisk-commits] rizzo: branch rizzo/astobj2 r48546 -
/team/rizzo/astobj2/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sun Dec 17 08:20:03 MST 2006
Author: rizzo
Date: Sun Dec 17 09:20:02 2006
New Revision: 48546
URL: http://svn.digium.com/view/asterisk?view=rev&rev=48546
Log:
more normalization of the foo2str() functions.
Modified:
team/rizzo/astobj2/channels/chan_sip.c
Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=48546&r1=48545&r2=48546
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sun Dec 17 09:20:02 2006
@@ -883,20 +883,6 @@
int x;
const char *s;
};
-
-static const struct c_referstatusstring {
- enum referstatus status;
- char *text;
-} referstatusstrings[] = {
- { REFER_IDLE, "<none>" },
- { REFER_SENT, "Request sent" },
- { REFER_RECEIVED, "Request received" },
- { REFER_ACCEPTED, "Accepted" },
- { REFER_RINGING, "Target ringing" },
- { REFER_200OK, "Done" },
- { REFER_FAILED, "Failed" },
- { REFER_NOAUTH, "Failed - auth failure" }
-} ;
/*! \brief Structure to handle SIP transfers. Dynamically allocated when needed */
/* OEJ: Should be moved to string fields */
@@ -1498,8 +1484,8 @@
/*--- Applications, functions, CLI and manager command helpers */
static const char *sip_nat_mode(const struct sip_pvt *p);
static int sip_show_inuse(int fd, int argc, char *argv[]);
-static char *transfermode2str(enum transfermodes mode) attribute_const;
-static char *nat2str(int nat) attribute_const;
+static const char *transfermode2str(enum transfermodes mode) attribute_const;
+static const char *nat2str(int nat) attribute_const;
static int peer_status(struct sip_peer *peer, char *status, int statuslen);
static int sip_show_users(int fd, int argc, char *argv[]);
static int _sip_show_peers(int fd, int *total, struct mansession *s, struct message *m, int argc, char *argv[]);
@@ -1578,7 +1564,7 @@
/*--- Internal UA client handling (outbound registrations) */
static int ast_sip_ouraddrfor(struct in_addr *them, struct in_addr *us);
static int sip_register(char *value, int lineno);
-static char *regstate2str(enum sipregistrystate regstate) attribute_const;
+static const char *regstate2str(enum sipregistrystate regstate) attribute_const;
static int sip_reregister(void *data);
static int sip_reg_timeout(void *data);
static void sip_send_all_registers(void);
@@ -1839,17 +1825,22 @@
set_udptl_peer: sip_set_udptl_peer,
};
+static const struct _map_x_s referstatusstrings[] = {
+ { REFER_IDLE, "<none>" },
+ { REFER_SENT, "Request sent" },
+ { REFER_RECEIVED, "Request received" },
+ { REFER_ACCEPTED, "Accepted" },
+ { REFER_RINGING, "Target ringing" },
+ { REFER_200OK, "Done" },
+ { REFER_FAILED, "Failed" },
+ { REFER_NOAUTH, "Failed - auth failure" },
+ { -1, NULL} /* terminator */
+} ;
+
/*! \brief Convert transfer status to string */
static const char *referstatus2str(enum referstatus rstatus)
{
- int i = (sizeof(referstatusstrings) / sizeof(referstatusstrings[0]));
- int x;
-
- for (x = 0; x < i; x++) {
- if (referstatusstrings[x].status == rstatus)
- return referstatusstrings[x].text;
- }
- return "";
+ return map_x_s(referstatusstrings, rstatus, "");
}
/*! \brief Initialize the initital request packet in the pvt structure.
@@ -7472,29 +7463,22 @@
return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
}
+static const struct _map_x_s regstatestrings[] = {
+ { REG_STATE_FAILED, "Failed" },
+ { REG_STATE_UNREGISTERED, "Unregistered"},
+ { REG_STATE_REGSENT, "Request Sent"},
+ { REG_STATE_AUTHSENT, "Auth. Sent"},
+ { REG_STATE_REGISTERED, "Registered"},
+ { REG_STATE_REJECTED, "Rejected"},
+ { REG_STATE_TIMEOUT, "Timeout"},
+ { REG_STATE_NOAUTH, "No Authentication"},
+ { -1, NULL } /* terminator */
+};
+
/*! \brief Convert registration state status to string */
-static char *regstate2str(enum sipregistrystate regstate)
-{
- switch(regstate) {
- case REG_STATE_FAILED:
- return "Failed";
- case REG_STATE_UNREGISTERED:
- return "Unregistered";
- case REG_STATE_REGSENT:
- return "Request Sent";
- case REG_STATE_AUTHSENT:
- return "Auth. Sent";
- case REG_STATE_REGISTERED:
- return "Registered";
- case REG_STATE_REJECTED:
- return "Rejected";
- case REG_STATE_TIMEOUT:
- return "Timeout";
- case REG_STATE_NOAUTH:
- return "No Authentication";
- default:
- return "Unknown";
- }
+static const char *regstate2str(enum sipregistrystate regstate)
+{
+ return map_x_s(regstatestrings, regstate, "Unknown");
}
/*!
@@ -9908,7 +9892,7 @@
}
/*! \brief Convert transfer mode to text string */
-static char *transfermode2str(enum transfermodes mode)
+static const char *transfermode2str(enum transfermodes mode)
{
if (mode == TRANSFER_OPENFORALL)
return "open";
@@ -9917,21 +9901,18 @@
return "strict";
}
+static struct _map_x_s natmodes[] = {
+ { SIP_NAT_NEVER, "No"},
+ { SIP_NAT_ROUTE, "Route"},
+ { SIP_NAT_ALWAYS, "Always"},
+ { SIP_NAT_RFC3581, "RFC3581"},
+ { -1, NULL}, /* terminator */
+};
+
/*! \brief Convert NAT setting to text string */
-static char *nat2str(int nat)
-{
- switch(nat) {
- case SIP_NAT_NEVER:
- return "No";
- case SIP_NAT_ROUTE:
- return "Route";
- case SIP_NAT_ALWAYS:
- return "Always";
- case SIP_NAT_RFC3581:
- return "RFC3581";
- default:
- return "Unknown";
- }
+static const char *nat2str(int nat)
+{
+ return map_x_s(natmodes, nat, "Unknown");
}
/*! \brief Report Peer status in character string
More information about the asterisk-commits
mailing list