update chan_iax to use 64bit feature flags.
authorDavid Vossel <dvossel@digium.com>
Wed, 17 Jun 2009 14:42:06 +0000 (14:42 +0000)
committerDavid Vossel <dvossel@digium.com>
Wed, 17 Jun 2009 14:42:06 +0000 (14:42 +0000)
(closes issue #15335)
Reported by: lmadsen

Review: https://reviewboard.asterisk.org/r/284/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@201331 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index c90bc5f..4e0cc1e 100644 (file)
@@ -254,10 +254,10 @@ static const char tdesc[] = "Inter Asterisk eXchange Driver (Ver 2)";
 
 /*! \brief Maximum transmission unit for the UDP packet in the trunk not to be
     fragmented. This is based on 1516 - ethernet - ip - udp - iax minus one g711 frame = 1240 */
-#define MAX_TRUNK_MTU 1240 
+#define MAX_TRUNK_MTU 1240
 
-static int global_max_trunk_mtu;       /*!< Maximum MTU, 0 if not used */
-static int trunk_timed, trunk_untimed, trunk_maxmtu, trunk_nmaxmtu ;   /*!< Trunk MTU statistics */
+static int global_max_trunk_mtu;       /*!< Maximum MTU, 0 if not used */
+static int trunk_timed, trunk_untimed, trunk_maxmtu, trunk_nmaxmtu ;   /*!< Trunk MTU statistics */
 
 #define DEFAULT_CONTEXT "default"
 
@@ -308,24 +308,24 @@ static int defaultsockfd = -1;
 static int (*iax2_regfunk)(const char *username, int onoff) = NULL;
 
 /* Ethernet, etc */
-#define IAX_CAPABILITY_FULLBANDWIDTH   0xFFFF
+#define IAX_CAPABILITY_FULLBANDWIDTH   0xFFFF
 /* T1, maybe ISDN */
-#define IAX_CAPABILITY_MEDBANDWIDTH    (IAX_CAPABILITY_FULLBANDWIDTH &         \
-                                        ~AST_FORMAT_SLINEAR &                  \
-                                        ~AST_FORMAT_SLINEAR16 &                        \
-                                        ~AST_FORMAT_SIREN7 &                   \
-                                        ~AST_FORMAT_SIREN14 &                  \
-                                        ~AST_FORMAT_ULAW &                     \
-                                        ~AST_FORMAT_ALAW &                     \
-                                        ~AST_FORMAT_G722) 
+#define IAX_CAPABILITY_MEDBANDWIDTH (IAX_CAPABILITY_FULLBANDWIDTH & \
+                     ~AST_FORMAT_SLINEAR &      \
+                     ~AST_FORMAT_SLINEAR16 &    \
+                     ~AST_FORMAT_SIREN7 &       \
+                     ~AST_FORMAT_SIREN14 &      \
+                     ~AST_FORMAT_ULAW &         \
+                     ~AST_FORMAT_ALAW &         \
+                     ~AST_FORMAT_G722)
 /* A modem */
-#define IAX_CAPABILITY_LOWBANDWIDTH    (IAX_CAPABILITY_MEDBANDWIDTH &          \
-                                        ~AST_FORMAT_G726 &                     \
-                                        ~AST_FORMAT_G726_AAL2 &                \
-                                        ~AST_FORMAT_ADPCM)
+#define IAX_CAPABILITY_LOWBANDWIDTH (IAX_CAPABILITY_MEDBANDWIDTH & \
+                     ~AST_FORMAT_G726 &         \
+                     ~AST_FORMAT_G726_AAL2 &    \
+                     ~AST_FORMAT_ADPCM)
 
-#define IAX_CAPABILITY_LOWFREE         (IAX_CAPABILITY_LOWBANDWIDTH &          \
-                                        ~AST_FORMAT_G723_1)
+#define IAX_CAPABILITY_LOWFREE      (IAX_CAPABILITY_LOWBANDWIDTH & \
+                     ~AST_FORMAT_G723_1)
 
 
 #define DEFAULT_MAXMS          2000            /* Must be faster than 2 seconds by default */
@@ -334,7 +334,7 @@ static int (*iax2_regfunk)(const char *username, int onoff) = NULL;
 
 /* if a pvt has encryption setup done and is running on the call */
 #define IAX_CALLENCRYPTED(pvt) \
-       (ast_test_flag(pvt, IAX_ENCRYPTED) && ast_test_flag(pvt, IAX_KEYPOPULATED))
+       (ast_test_flag64(pvt, IAX_ENCRYPTED) && ast_test_flag64(pvt, IAX_KEYPOPULATED))
 
 #define IAX_DEBUGDIGEST(msg, key) do { \
                int idx; \
@@ -374,7 +374,7 @@ static int adsi = 0;
 static int delayreject = 0;
 static int iax2_encryption = 0;
 
-static struct ast_flags globalflags = { 0 };
+static struct ast_flags64 globalflags = { 0 };
 
 static pthread_t netthreadid = AST_PTHREADT_NULL;
 
@@ -389,41 +389,38 @@ struct iax2_context {
        struct iax2_context *next;
 };
 
-enum iax2_flags {
-       IAX_HASCALLERID =       (1 << 0),       /*!< CallerID has been specified */
-       IAX_DELME =             (1 << 1),       /*!< Needs to be deleted */
-       IAX_TEMPONLY =          (1 << 2),       /*!< Temporary (realtime) */
-       IAX_TRUNK =             (1 << 3),       /*!< Treat as a trunk */
-       IAX_NOTRANSFER =        (1 << 4),       /*!< Don't native bridge */
-       IAX_USEJITTERBUF =      (1 << 5),       /*!< Use jitter buffer */
-       IAX_DYNAMIC =           (1 << 6),       /*!< dynamic peer */
-       IAX_SENDANI =           (1 << 7),       /*!< Send ANI along with CallerID */
+
+#define        IAX_HASCALLERID         (uint64_t)(1 << 0)    /*!< CallerID has been specified */
+#define IAX_DELME               (uint64_t)(1 << 1)    /*!< Needs to be deleted */
+#define IAX_TEMPONLY            (uint64_t)(1 << 2)    /*!< Temporary (realtime) */
+#define IAX_TRUNK               (uint64_t)(1 << 3)    /*!< Treat as a trunk */
+#define IAX_NOTRANSFER          (uint64_t)(1 << 4)    /*!< Don't native bridge */
+#define IAX_USEJITTERBUF        (uint64_t)(1 << 5)    /*!< Use jitter buffer */
+#define IAX_DYNAMIC             (uint64_t)(1 << 6)    /*!< dynamic peer */
+#define IAX_SENDANI             (uint64_t)(1 << 7)    /*!< Send ANI along with CallerID */
         /* (1 << 8) is currently unused due to the deprecation of an old option. Go ahead, take it! */
-       IAX_ALREADYGONE =       (1 << 9),       /*!< Already disconnected */
-       IAX_PROVISION =         (1 << 10),      /*!< This is a provisioning request */
-       IAX_QUELCH =            (1 << 11),      /*!< Whether or not we quelch audio */
-       IAX_ENCRYPTED =         (1 << 12),      /*!< Whether we should assume encrypted tx/rx */
-       IAX_KEYPOPULATED =      (1 << 13),      /*!< Whether we have a key populated */
-       IAX_CODEC_USER_FIRST =  (1 << 14),      /*!< are we willing to let the other guy choose the codec? */
-       IAX_CODEC_NOPREFS =     (1 << 15),      /*!< Force old behaviour by turning off prefs */
-       IAX_CODEC_NOCAP =       (1 << 16),      /*!< only consider requested format and ignore capabilities*/
-       IAX_RTCACHEFRIENDS =    (1 << 17),      /*!< let realtime stay till your reload */
-       IAX_RTUPDATE =          (1 << 18),      /*!< Send a realtime update */
-       IAX_RTAUTOCLEAR =       (1 << 19),      /*!< erase me on expire */ 
-       IAX_FORCEJITTERBUF =    (1 << 20),      /*!< Force jitterbuffer, even when bridged to a channel that can take jitter */ 
-       IAX_RTIGNOREREGEXPIRE = (1 << 21),      /*!< When using realtime, ignore registration expiration */
-       IAX_TRUNKTIMESTAMPS =   (1 << 22),      /*!< Send trunk timestamps */
-       IAX_TRANSFERMEDIA =     (1 << 23),      /*!< When doing IAX2 transfers, transfer media only */
-       IAX_MAXAUTHREQ =        (1 << 24),      /*!< Maximum outstanding AUTHREQ restriction is in place */
-       IAX_DELAYPBXSTART =     (1 << 25),      /*!< Don't start a PBX on the channel until the peer sends us a
-                                                    response, so that we've achieved a three-way handshake with
-                                                    them before sending voice or anything else*/
-       IAX_ALLOWFWDOWNLOAD =   (1 << 26),      /*!< Allow the FWDOWNL command? */
-       IAX_IMMEDIATE =         (1 << 27),      /*!< Allow immediate off-hook to extension s */
-       IAX_SENDCONNECTEDLINE = (1 << 28), /*!< Allow sending of connected line updates */
-       IAX_RECVCONNECTEDLINE = (1 << 29), /*!< Allow receiving of connected line updates */
-       IAX_FORCE_ENCRYPT =     (1 << 30),      /*!< Forces call encryption, if encryption not possible hangup */
-};
+#define IAX_ALREADYGONE         (uint64_t)(1 << 9)    /*!< Already disconnected */
+#define IAX_PROVISION           (uint64_t)(1 << 10)   /*!< This is a provisioning request */
+#define IAX_QUELCH              (uint64_t)(1 << 11)   /*!< Whether or not we quelch audio */
+#define IAX_ENCRYPTED           (uint64_t)(1 << 12)   /*!< Whether we should assume encrypted tx/rx */
+#define IAX_KEYPOPULATED        (uint64_t)(1 << 13)   /*!< Whether we have a key populated */
+#define IAX_CODEC_USER_FIRST    (uint64_t)(1 << 14)   /*!< are we willing to let the other guy choose the codec? */
+#define IAX_CODEC_NOPREFS       (uint64_t)(1 << 15)   /*!< Force old behaviour by turning off prefs */
+#define IAX_CODEC_NOCAP         (uint64_t)(1 << 16)   /*!< only consider requested format and ignore capabilities*/
+#define IAX_RTCACHEFRIENDS      (uint64_t)(1 << 17)   /*!< let realtime stay till your reload */
+#define IAX_RTUPDATE            (uint64_t)(1 << 18)   /*!< Send a realtime update */
+#define IAX_RTAUTOCLEAR         (uint64_t)(1 << 19)   /*!< erase me on expire */
+#define IAX_FORCEJITTERBUF      (uint64_t)(1 << 20)   /*!< Force jitterbuffer, even when bridged to a channel that can take jitter */
+#define IAX_RTIGNOREREGEXPIRE   (uint64_t)(1 << 21)   /*!< When using realtime, ignore registration expiration */
+#define IAX_TRUNKTIMESTAMPS     (uint64_t)(1 << 22)   /*!< Send trunk timestamps */
+#define IAX_TRANSFERMEDIA       (uint64_t)(1 << 23)   /*!< When doing IAX2 transfers, transfer media only */
+#define IAX_MAXAUTHREQ          (uint64_t)(1 << 24)   /*!< Maximum outstanding AUTHREQ restriction is in place */
+#define IAX_DELAYPBXSTART       (uint64_t)(1 << 25)   /*!< Don't start a PBX on the channel until the peer sends us a response, so that we've achieved a three-way handshake with them before sending voice or anything else */
+#define IAX_ALLOWFWDOWNLOAD     (uint64_t)(1 << 26)   /*!< Allow the FWDOWNL command? */
+#define IAX_IMMEDIATE           (uint64_t)(1 << 27)   /*!< Allow immediate off-hook to extension s */
+#define IAX_SENDCONNECTEDLINE   (uint64_t)(1 << 28)   /*!< Allow sending of connected line updates */
+#define IAX_RECVCONNECTEDLINE   (uint64_t)(1 << 29)   /*!< Allow receiving of connected line updates */
+#define IAX_FORCE_ENCRYPT       (uint64_t)(1 << 30)   /*!< Forces call encryption, if encryption not possible hangup */
 
 static int global_rtautoclear = 120;
 
@@ -443,12 +440,12 @@ struct iax2_user {
                AST_STRING_FIELD(cid_name);
                AST_STRING_FIELD(parkinglot);           /*!< Default parkinglot for device */
        );
-       
+
        int authmethods;
        int encmethods;
        int amaflags;
        int adsi;
-       unsigned int flags;
+       uint64_t flags;
        int capability;
        int maxauthreq; /*!< Maximum allowed outstanding AUTHREQs */
        int curauthreq; /*!< Current number of outstanding AUTHREQs */
@@ -486,7 +483,7 @@ struct iax2_peer {
        int sockfd;                                     /*!< Socket to use for transmission */
        struct in_addr mask;
        int adsi;
-       unsigned int flags;
+       uint64_t flags;
 
        /* Dynamic Registration fields */
        struct sockaddr_in defaddr;                     /*!< Default address if there is one */
@@ -587,10 +584,10 @@ static AST_LIST_HEAD_STATIC(registrations, iax2_registry);
 
 /* Don't retry more frequently than every 10 ms, or less frequently than every 5 seconds */
 #define MIN_RETRY_TIME         100
-#define MAX_RETRY_TIME         10000
+#define MAX_RETRY_TIME         10000
 
-#define MAX_JITTER_BUFFER      50
-#define MIN_JITTER_BUFFER      10
+#define MAX_JITTER_BUFFER      50
+#define MIN_JITTER_BUFFER      10
 
 #define DEFAULT_TRUNKDATA      640 * 10        /*!< 40ms, uncompressed linear * 10 channels */
 
@@ -676,7 +673,7 @@ struct chan_iax2_pvt {
        /*! The jitterbuffer */
        jitterbuf *jb;
        /*! active jb read scheduler id */
-       int jbid;                       
+       int jbid;
        /*! LAG */
        int lag;
        /*! Error, as discovered by the manager */
@@ -758,7 +755,7 @@ struct chan_iax2_pvt {
        /*! Associated peer for poking */
        struct iax2_peer *peerpoke;
        /*! IAX_ flags */
-       unsigned int flags;
+       uint64_t flags;
        int adsi;
 
        /*! Transferring status */
@@ -777,7 +774,7 @@ struct chan_iax2_pvt {
 
        /*! Who we are bridged to */
        unsigned short bridgecallno;
-       
+
        int pingid;                     /*!< Transmit PING request */
        int lagid;                      /*!< Retransmit lag request */
        int autoid;                     /*!< Auto hangup for Dialplan requestor */
@@ -872,7 +869,7 @@ static void reg_source_db(struct iax2_peer *p);
 static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
 
 static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt);
-static char *complete_iax2_peers(const char *line, const char *word, int pos, int state, int flags);
+static char *complete_iax2_peers(const char *line, const char *word, int pos, int state, uint64_t flags);
 static char *complete_iax2_unregister(const char *line, const char *word, int pos, int state);
 
 enum iax2_thread_iostate {
@@ -1593,7 +1590,7 @@ static int iax2_getpeername(struct sockaddr_in sin, char *host, int len)
 static void iax2_destroy_helper(struct chan_iax2_pvt *pvt)
 {
        /* Decrement AUTHREQ count if needed */
-       if (ast_test_flag(pvt, IAX_MAXAUTHREQ)) {
+       if (ast_test_flag64(pvt, IAX_MAXAUTHREQ)) {
                struct iax2_user *user;
                struct iax2_user tmp_user = {
                        .name = pvt->username,
@@ -1602,10 +1599,10 @@ static void iax2_destroy_helper(struct chan_iax2_pvt *pvt)
                user = ao2_find(users, &tmp_user, OBJ_POINTER);
                if (user) {
                        ast_atomic_fetchadd_int(&user->curauthreq, -1);
-                       user_unref(user);       
+                       user_unref(user);
                }
 
-               ast_clear_flag(pvt, IAX_MAXAUTHREQ);
+               ast_clear_flag64(pvt, IAX_MAXAUTHREQ);
        }
        /* No more pings or lagrq's */
        AST_SCHED_DEL_SPINLOCK(ast_sched_thread_get_context(sched), pvt->pingid, &iaxsl[pvt->callno]);
@@ -1647,7 +1644,7 @@ static void pvt_destructor(void *obj)
        iax2_destroy_helper(pvt);
 
        /* Already gone */
-       ast_set_flag(pvt, IAX_ALREADYGONE);
+       ast_set_flag64(pvt, IAX_ALREADYGONE);
 
        AST_LIST_TRAVERSE(&frame_queue[pvt->callno], cur, list) {
                /* Cancel any pending transmissions */
@@ -2000,7 +1997,7 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s
                                break;
                        }
                        ast_mutex_unlock(&iaxsl[x]);
-                       
+
                        if (x == start - 1) {
                                break;
                        }
@@ -2026,7 +2023,7 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s
                        iaxs[x]->pingid = iax2_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
                        iaxs[x]->lagid = iax2_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
                        iaxs[x]->amaflags = amaflags;
-                       ast_copy_flags(iaxs[x], &globalflags, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
+                       ast_copy_flags64(iaxs[x], &globalflags, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
                        ast_string_field_set(iaxs[x], accountcode, accountcode);
                        ast_string_field_set(iaxs[x], mohinterpret, mohinterpret);
                        ast_string_field_set(iaxs[x], mohsuggest, mohsuggest);
@@ -2413,7 +2410,7 @@ static int __do_deliver(void *data)
        struct iax_frame *fr = data;
        fr->retrans = -1;
        ast_clear_flag(&fr->af, AST_FRFLAG_HAS_TIMING_INFO);
-       if (iaxs[fr->callno] && !ast_test_flag(iaxs[fr->callno], IAX_ALREADYGONE))
+       if (iaxs[fr->callno] && !ast_test_flag64(iaxs[fr->callno], IAX_ALREADYGONE))
                iax2_queue_frame(fr->callno, &fr->af);
        /* Free our iax frame */
        iax2_frame_free(fr);
@@ -2512,9 +2509,9 @@ static int iax2_predestroy(int callno)
        if (!pvt)
                return -1;
 
-       if (!ast_test_flag(pvt, IAX_ALREADYGONE)) {
+       if (!ast_test_flag64(pvt, IAX_ALREADYGONE)) {
                iax2_destroy_helper(pvt);
-               ast_set_flag(pvt, IAX_ALREADYGONE);     
+               ast_set_flag64(pvt, IAX_ALREADYGONE);
        }
 
        if ((c = pvt->owner)) {
@@ -2733,8 +2730,8 @@ static char *handle_cli_iax2_prune_realtime(struct ast_cli_entry *e, int cmd, st
        user = find_user(a->argv[3]);
        if (peer || user) {
                if (peer) {
-                       if (ast_test_flag(peer, IAX_RTCACHEFRIENDS)) {
-                               ast_set_flag(peer, IAX_RTAUTOCLEAR);
+                       if (ast_test_flag64(peer, IAX_RTCACHEFRIENDS)) {
+                               ast_set_flag64(peer, IAX_RTAUTOCLEAR);
                                expire_registry(peer_ref(peer));
                                ast_cli(a->fd, "Peer %s was removed from the cache.\n", a->argv[3]);
                        } else {
@@ -2743,8 +2740,8 @@ static char *handle_cli_iax2_prune_realtime(struct ast_cli_entry *e, int cmd, st
                        peer_unref(peer);
                }
                if (user) {
-                       if (ast_test_flag(user, IAX_RTCACHEFRIENDS)) {
-                               ast_set_flag(user, IAX_RTAUTOCLEAR);
+                       if (ast_test_flag64(user, IAX_RTCACHEFRIENDS)) {
+                               ast_set_flag64(user, IAX_RTAUTOCLEAR);
                                ast_cli(a->fd, "User %s was removed from the cache.\n", a->argv[3]);
                        } else {
                                ast_cli(a->fd, "User %s is not eligible for this operation.\n", a->argv[3]);
@@ -2909,8 +2906,8 @@ static char *handle_cli_iax2_show_peer(struct ast_cli_entry *e, int cmd, struct
                ast_cli(a->fd, "  Context      : %s\n", peer->context);
                ast_cli(a->fd, "  Parking lot  : %s\n", peer->parkinglot);
                ast_cli(a->fd, "  Mailbox      : %s\n", peer->mailbox);
-               ast_cli(a->fd, "  Dynamic      : %s\n", ast_test_flag(peer, IAX_DYNAMIC) ? "Yes" : "No");
-               ast_cli(a->fd, "  Trunk        : %s\n", ast_test_flag(peer, IAX_TRUNK) ? "Yes" : "No");
+               ast_cli(a->fd, "  Dynamic      : %s\n", ast_test_flag64(peer, IAX_DYNAMIC) ? "Yes" : "No");
+               ast_cli(a->fd, "  Trunk        : %s\n", ast_test_flag64(peer, IAX_TRUNK) ? "Yes" : "No");
                ast_cli(a->fd, "  Encryption   : %s\n", peer->encmethods ? ast_str_buffer(encmethods) : "No");
                ast_cli(a->fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>"));
                ast_cli(a->fd, "  Expire       : %d\n", peer->expire);
@@ -2950,7 +2947,7 @@ static char *handle_cli_iax2_show_peer(struct ast_cli_entry *e, int cmd, struct
        return CLI_SUCCESS;
 }
 
-static char *complete_iax2_peers(const char *line, const char *word, int pos, int state, int flags)
+static char *complete_iax2_peers(const char *line, const char *word, int pos, int state, uint64_t flags)
 {
        int which = 0;
        struct iax2_peer *peer;
@@ -2961,7 +2958,7 @@ static char *complete_iax2_peers(const char *line, const char *word, int pos, in
        i = ao2_iterator_init(peers, 0);
        while ((peer = ao2_iterator_next(&i))) {
                if (!strncasecmp(peer->name, word, wordlen) && ++which > state
-                       && (!flags || ast_test_flag(peer, flags))) {
+                       && (!flags || ast_test_flag64(peer, flags))) {
                        res = ast_strdup(peer->name);
                        peer_unref(peer);
                        break;
@@ -3235,7 +3232,7 @@ static void __get_from_jb(const void *p)
                        
                        /* queue the frame:  For consistency, we would call __do_deliver here, but __do_deliver wants an iax_frame,
                         * which we'd need to malloc, and then it would free it.  That seems like a drag */
-                       if (!ast_test_flag(iaxs[callno], IAX_ALREADYGONE)) {
+                       if (!ast_test_flag64(iaxs[callno], IAX_ALREADYGONE)) {
                                iax2_queue_frame(callno, &af);
                                /* iax2_queue_frame() could cause the call to disappear */
                                pvt = iaxs[callno];
@@ -3305,7 +3302,7 @@ static int schedule_delivery(struct iax_frame *fr, int updatehistory, int fromtr
                type = JB_TYPE_SILENCE;
        }
 
-       if ( (!ast_test_flag(iaxs[fr->callno], IAX_USEJITTERBUF)) ) {
+       if ( (!ast_test_flag64(iaxs[fr->callno], IAX_USEJITTERBUF)) ) {
                if (tsout)
                        *tsout = fr->ts;
                __do_deliver(fr);
@@ -3317,7 +3314,7 @@ static int schedule_delivery(struct iax_frame *fr, int updatehistory, int fromtr
 
        /* if the user hasn't requested we force the use of the jitterbuffer, and we're bridged to
         * a channel that can accept jitter, then flush and suspend the jb, and send this frame straight through */
-       if ( (!ast_test_flag(iaxs[fr->callno], IAX_FORCEJITTERBUF)) && owner && bridge && (bridge->tech->properties & AST_CHAN_TP_WANTSJITTER) ) {
+       if ( (!ast_test_flag64(iaxs[fr->callno], IAX_FORCEJITTERBUF)) && owner && bridge && (bridge->tech->properties & AST_CHAN_TP_WANTSJITTER) ) {
                jb_frame frame;
 
                /* deliver any frames in the jb */
@@ -3485,8 +3482,8 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
        if (!var)
                return NULL;
 
-       peer = build_peer(peername, var, NULL, ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
-       
+       peer = build_peer(peername, var, NULL, ast_test_flag64((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
+
        if (!peer) {
                ast_variables_destroy(var);
                return NULL;
@@ -3518,27 +3515,27 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
        if (!peer)
                return NULL;
 
-       if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
-               ast_copy_flags(peer, &globalflags, IAX_RTAUTOCLEAR|IAX_RTCACHEFRIENDS);
-               if (ast_test_flag(peer, IAX_RTAUTOCLEAR)) {
-                       if (peer->expire > -1) {
-                               if (!ast_sched_thread_del(sched, peer->expire)) {
-                                       peer->expire = -1;
-                                       peer_unref(peer);
-                               }
-                       }
-                       peer->expire = iax2_sched_add(sched, (global_rtautoclear) * 1000, expire_registry, peer_ref(peer));
-                       if (peer->expire == -1)
-                               peer_unref(peer);
+       if (ast_test_flag64((&globalflags), IAX_RTCACHEFRIENDS)) {
+               ast_copy_flags64(peer, &globalflags, IAX_RTAUTOCLEAR|IAX_RTCACHEFRIENDS);
+               if (ast_test_flag64(peer, IAX_RTAUTOCLEAR)) {
+                       if (peer->expire > -1) {
+                               if (!ast_sched_thread_del(sched, peer->expire)) {
+                                       peer->expire = -1;
+                                       peer_unref(peer);
+                               }
+                       }
+                       peer->expire = iax2_sched_add(sched, (global_rtautoclear) * 1000, expire_registry, peer_ref(peer));
+                       if (peer->expire == -1)
+                               peer_unref(peer);
                }
                ao2_link(peers, peer);
-               if (ast_test_flag(peer, IAX_DYNAMIC))
+               if (ast_test_flag64(peer, IAX_DYNAMIC))
                        reg_source_db(peer);
        } else {
-               ast_set_flag(peer, IAX_TEMPONLY);       
+               ast_set_flag64(peer, IAX_TEMPONLY);
        }
 
-       if (!ast_test_flag(&globalflags, IAX_RTIGNOREREGEXPIRE) && dynamic) {
+       if (!ast_test_flag64(&globalflags, IAX_RTIGNOREREGEXPIRE) && dynamic) {
                time(&nowtime);
                if ((nowtime - regseconds) > IAX_DEFAULT_REG_EXPIRE) {
                        memset(&peer->addr, 0, sizeof(peer->addr));
@@ -3609,18 +3606,18 @@ static struct iax2_user *realtime_user(const char *username, struct sockaddr_in
                tmp = tmp->next;
        }
 
-       user = build_user(username, var, NULL, !ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS));
+       user = build_user(username, var, NULL, !ast_test_flag64((&globalflags), IAX_RTCACHEFRIENDS));
 
        ast_variables_destroy(var);
 
        if (!user)
                return NULL;
 
-       if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
-               ast_set_flag(user, IAX_RTCACHEFRIENDS);
+       if (ast_test_flag64((&globalflags), IAX_RTCACHEFRIENDS)) {
+               ast_set_flag64(user, IAX_RTCACHEFRIENDS);
                ao2_link(users, user);
        } else {
-               ast_set_flag(user, IAX_TEMPONLY);       
+               ast_set_flag64(user, IAX_TEMPONLY);
        }
 
        return user;
@@ -3640,7 +3637,7 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin,
 
 struct create_addr_info {
        int capability;
-       unsigned int flags;
+       uint64_t flags;
        int maxtime;
        int encmethods;
        int found;
@@ -3665,7 +3662,7 @@ static int create_addr(const char *peername, struct ast_channel *c, struct socka
        int res = -1;
        struct ast_codec_pref ourprefs;
 
-       ast_clear_flag(cai, IAX_SENDANI | IAX_TRUNK);
+       ast_clear_flag64(cai, IAX_SENDANI | IAX_TRUNK);
        cai->sockfd = defaultsockfd;
        cai->maxtime = 0;
        sin->sin_family = AF_INET;
@@ -3696,7 +3693,7 @@ static int create_addr(const char *peername, struct ast_channel *c, struct socka
        if (peer->maxms && ((peer->lastms > peer->maxms) || (peer->lastms < 0)))
                goto return_unref;
 
-       ast_copy_flags(cai, peer, IAX_SENDANI | IAX_TRUNK | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
+       ast_copy_flags64(cai, peer, IAX_SENDANI | IAX_TRUNK | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
        cai->maxtime = peer->maxms;
        cai->capability = peer->capability;
        cai->encmethods = peer->encmethods;
@@ -3905,7 +3902,7 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
                ast_log(LOG_WARNING, "No address associated with '%s'\n", pds.peer);
                return -1;
        }
-       if (ast_strlen_zero(cai.secret) && ast_test_flag(iaxs[callno], IAX_FORCE_ENCRYPT)) {
+       if (ast_strlen_zero(cai.secret) && ast_test_flag64(iaxs[callno], IAX_FORCE_ENCRYPT)) {
                ast_log(LOG_WARNING, "Call terminated. No secret given and force encrypt enabled\n");
                return -1;
        }
@@ -3955,7 +3952,7 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
 
        if (n)
                iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, n);
-       if (ast_test_flag(iaxs[callno], IAX_SENDANI) && c->connected.ani)
+       if (ast_test_flag64(iaxs[callno], IAX_SENDANI) && c->connected.ani)
                iax_ie_append_str(&ied, IAX_IE_CALLING_ANI, c->connected.ani);
 
        if (!ast_strlen_zero(c->language))
@@ -4066,7 +4063,7 @@ static int iax2_hangup(struct ast_channel *c)
        ast_mutex_lock(&iaxsl[callno]);
        if (callno && iaxs[callno]) {
                ast_debug(1, "We're hanging up %s now...\n", c->name);
-               alreadygone = ast_test_flag(iaxs[callno], IAX_ALREADYGONE);
+               alreadygone = ast_test_flag64(iaxs[callno], IAX_ALREADYGONE);
                /* Send the hangup unless we have had a transmission error or are already gone */
                iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, (unsigned char)c->hangupcause);
                if (!iaxs[callno]->error && !alreadygone) {
@@ -4221,8 +4218,8 @@ static int iax2_start_transfer(unsigned short callno0, unsigned short callno1, i
 
        if (IAX_CALLENCRYPTED(iaxs[callno0]) || IAX_CALLENCRYPTED(iaxs[callno1])) {
                ast_debug(1, "transfers are not supported for encrypted calls at this time");
-               ast_set_flag(iaxs[callno0], IAX_NOTRANSFER);
-               ast_set_flag(iaxs[callno1], IAX_NOTRANSFER);
+               ast_set_flag64(iaxs[callno0], IAX_NOTRANSFER);
+               ast_set_flag64(iaxs[callno1], IAX_NOTRANSFER);
                return 0;
        }
 
@@ -4328,10 +4325,10 @@ static enum ast_bridge_result iax2_bridge(struct ast_channel *c0, struct ast_cha
                        return AST_BRIDGE_FAILED_NOWARN;
                }
                /* check if transfered and if we really want native bridging */
-               if (!transferstarted && !ast_test_flag(iaxs[callno0], IAX_NOTRANSFER) && !ast_test_flag(iaxs[callno1], IAX_NOTRANSFER)) {
+               if (!transferstarted && !ast_test_flag64(iaxs[callno0], IAX_NOTRANSFER) && !ast_test_flag64(iaxs[callno1], IAX_NOTRANSFER)) {
                        /* Try the transfer */
                        if (iax2_start_transfer(callno0, callno1, (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1)) ||
-                                                       ast_test_flag(iaxs[callno0], IAX_TRANSFERMEDIA) | ast_test_flag(iaxs[callno1], IAX_TRANSFERMEDIA)))
+                                                       ast_test_flag64(iaxs[callno0], IAX_TRANSFERMEDIA) | ast_test_flag64(iaxs[callno1], IAX_TRANSFERMEDIA)))
                                ast_log(LOG_WARNING, "Unable to start the transfer\n");
                        transferstarted = 1;
                }
@@ -4458,7 +4455,7 @@ static int iax2_indicate(struct ast_channel *c, int condition, const void *data,
                }
                break;
        case AST_CONTROL_CONNECTED_LINE:
-               if (!ast_test_flag(pvt, IAX_SENDCONNECTEDLINE))
+               if (!ast_test_flag64(pvt, IAX_SENDCONNECTEDLINE))
                        goto done;
                break;
        }
@@ -4501,7 +4498,7 @@ static int iax2_getpeertrunk(struct sockaddr_in sin)
        while ((peer = ao2_iterator_next(&i))) {
                if ((peer->addr.sin_addr.s_addr == sin.sin_addr.s_addr) &&
                    (peer->addr.sin_port == sin.sin_port)) {
-                       res = ast_test_flag(peer, IAX_TRUNK);
+                       res = ast_test_flag64(peer, IAX_TRUNK);
                        peer_unref(peer);
                        break;
                }
@@ -4913,7 +4910,7 @@ static int iax2_trunk_queue(struct chan_iax2_pvt *pvt, struct iax_frame *fr)
 
                /* Append to meta frame */
                ptr = tpeer->trunkdata + IAX2_TRUNK_PREFACE + tpeer->trunkdatalen;
-               if (ast_test_flag(&globalflags, IAX_TRUNKTIMESTAMPS)) {
+               if (ast_test_flag64(&globalflags, IAX_TRUNKTIMESTAMPS)) {
                        mtm = (struct ast_iax2_meta_trunk_mini *)ptr;
                        mtm->len = htons(f->datalen);
                        mtm->mini.callno = htons(pvt->callno);
@@ -5116,7 +5113,7 @@ static int encrypt_frame(ast_aes_encrypt_key *ecx, struct ast_iax2_full_hdr *fh,
 static int decrypt_frame(int callno, struct ast_iax2_full_hdr *fh, struct ast_frame *f, int *datalen)
 {
        int res=-1;
-       if (!ast_test_flag(iaxs[callno], IAX_KEYPOPULATED)) {
+       if (!ast_test_flag64(iaxs[callno], IAX_KEYPOPULATED)) {
                /* Search for possible keys, given secrets */
                struct MD5Context md5;
                unsigned char digest[16];
@@ -5132,7 +5129,7 @@ static int decrypt_frame(int callno, struct ast_iax2_full_hdr *fh, struct ast_fr
                        build_encryption_keys(digest, iaxs[callno]);
                        res = decode_frame(&iaxs[callno]->dcx, fh, f, datalen);
                        if (!res) {
-                               ast_set_flag(iaxs[callno], IAX_KEYPOPULATED);
+                               ast_set_flag64(iaxs[callno], IAX_KEYPOPULATED);
                                break;
                        }
                }
@@ -5188,7 +5185,7 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
                iax2_key_rotate(pvt);
        }
 
-       if ((ast_test_flag(pvt, IAX_TRUNK) || 
+       if ((ast_test_flag64(pvt, IAX_TRUNK) || 
                        (((fts & 0xFFFF0000L) == (lastsent & 0xFFFF0000L)) ||
                        ((fts & 0xFFFF0000L) == ((lastsent + 0x10000) & 0xFFFF0000L))))
                /* High two bytes are the same on timestamp, or sending on a trunk */ &&
@@ -5229,7 +5226,7 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
        if (now) {
                fr = &frb.fr2;
        } else
-               fr = iax_frame_new(DIRECTION_OUTGRESS, ast_test_flag(pvt, IAX_ENCRYPTED) ? f->datalen + 32 : f->datalen, (f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_VIDEO));
+               fr = iax_frame_new(DIRECTION_OUTGRESS, ast_test_flag64(pvt, IAX_ENCRYPTED) ? f->datalen + 32 : f->datalen, (f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_VIDEO));
        if (!fr) {
                ast_log(LOG_WARNING, "Out of memory\n");
                return -1;
@@ -5286,8 +5283,8 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
                        pvt->svoiceformat = f->subclass;
                else if (f->frametype == AST_FRAME_VIDEO)
                        pvt->svideoformat = f->subclass & ~0x1;
-               if (ast_test_flag(pvt, IAX_ENCRYPTED)) {
-                       if (ast_test_flag(pvt, IAX_KEYPOPULATED)) {
+               if (ast_test_flag64(pvt, IAX_ENCRYPTED)) {
+                       if (ast_test_flag64(pvt, IAX_KEYPOPULATED)) {
                                if (fr->transfer)
                                        iax_outputframe(fr, NULL, 2, &pvt->transfer, fr->datalen - sizeof(struct ast_iax2_full_hdr));
                                else
@@ -5306,7 +5303,7 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
                } else
                        res = iax2_transmit(fr);
        } else {
-               if (ast_test_flag(pvt, IAX_TRUNK)) {
+               if (ast_test_flag64(pvt, IAX_TRUNK)) {
                        iax2_trunk_queue(pvt, fr);
                        res = 0;
                } else if (fr->af.frametype == AST_FRAME_VIDEO) {
@@ -5334,8 +5331,8 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
                        fr->retries = -1;
                        if (pvt->transferring == TRANSFER_MEDIAPASS)
                                fr->transfer = 1;
-                       if (ast_test_flag(pvt, IAX_ENCRYPTED)) {
-                               if (ast_test_flag(pvt, IAX_KEYPOPULATED)) {
+                       if (ast_test_flag64(pvt, IAX_ENCRYPTED)) {
+                               if (ast_test_flag64(pvt, IAX_KEYPOPULATED)) {
                                        encrypt_frame(&pvt->ecx, (struct ast_iax2_full_hdr *)mh, pvt->semirand, &fr->datalen);
                                } else
                                        ast_log(LOG_WARNING, "Supposed to send packet encrypted, but no key?\n");
@@ -5391,21 +5388,21 @@ static char *handle_cli_iax2_show_users(struct ast_cli_entry *e, int cmd, struct
                user_unref(user), user = ao2_iterator_next(&i)) {
                if (havepattern && regexec(&regexbuf, user->name, 0, NULL, 0))
                        continue;
-               
+
                if (!ast_strlen_zero(user->secret)) {
-                       ast_copy_string(auth,user->secret, sizeof(auth));
+                       ast_copy_string(auth,user->secret, sizeof(auth));
                } else if (!ast_strlen_zero(user->inkeys)) {
-                       snprintf(auth, sizeof(auth), "Key: %-15.15s ", user->inkeys);
-               } else
+                       snprintf(auth, sizeof(auth), "Key: %-15.15s ", user->inkeys);
+               } else
                        ast_copy_string(auth, "-no secret-", sizeof(auth));
-               
-               if(ast_test_flag(user,IAX_CODEC_NOCAP))
+
+               if(ast_test_flag64(user, IAX_CODEC_NOCAP))
                        pstr = "REQ Only";
-               else if(ast_test_flag(user,IAX_CODEC_NOPREFS))
+               else if(ast_test_flag64(user, IAX_CODEC_NOPREFS))
                        pstr = "Disabled";
                else
-                       pstr = ast_test_flag(user,IAX_CODEC_USER_FIRST) ? "Caller" : "Host";
-               
+                       pstr = ast_test_flag64(user, IAX_CODEC_USER_FIRST) ? "Caller" : "Host";
+
                ast_cli(a->fd, FORMAT2, user->name, auth, user->authmethods, 
                        user->contexts ? user->contexts->context : DEFAULT_CONTEXT,
                        user->ha ? "Yes" : "No", pstr);
@@ -5519,17 +5516,17 @@ static int __iax2_show_peers(int manager, int fd, struct mansession *s, const in
                                name,
                                peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "-none-",
                                ntohs(peer->addr.sin_port),
-                               ast_test_flag(peer, IAX_DYNAMIC) ? "yes" : "no",
-                               ast_test_flag(peer, IAX_TRUNK) ? "yes" : "no",
+                               ast_test_flag64(peer, IAX_DYNAMIC) ? "yes" : "no",
+                               ast_test_flag64(peer, IAX_TRUNK) ? "yes" : "no",
                                peer->encmethods ? ast_str_buffer(encmethods) : "no",
                                status);
                } else {
                        ast_cli(fd, FORMAT, name,
                                peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
-                               ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
+                               ast_test_flag64(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
                                nm,
                                ntohs(peer->addr.sin_port),
-                               ast_test_flag(peer, IAX_TRUNK) ? "(T)" : "   ",
+                               ast_test_flag64(peer, IAX_TRUNK) ? "(T)" : "   ",
                                peer->encmethods ? "(E)" : "   ",
                                status,
                                term);
@@ -5792,8 +5789,8 @@ static int manager_iax2_show_peer_list(struct mansession *s, const struct messag
                ast_copy_string(nm, ast_inet_ntoa(peer->mask), sizeof(nm));
                astman_append(s, "Mask: %s\r\n", nm);
                astman_append(s, "Port: %d\r\n", ntohs(peer->addr.sin_port));
-               astman_append(s, "Dynamic: %s\r\n", ast_test_flag(peer, IAX_DYNAMIC) ? "Yes" : "No");
-               astman_append(s, "Trunk: %s\r\n", ast_test_flag(peer, IAX_TRUNK) ? "Yes" : "No");
+               astman_append(s, "Dynamic: %s\r\n", ast_test_flag64(peer, IAX_DYNAMIC) ? "Yes" : "No");
+               astman_append(s, "Trunk: %s\r\n", ast_test_flag64(peer, IAX_TRUNK) ? "Yes" : "No");
                astman_append(s, "Encryption: %s\r\n", peer->encmethods ? ast_str_buffer(encmethods) : "No");
                peer_status(peer, status, sizeof(status));
                astman_append(s, "Status: %s\r\n\r\n", status);
@@ -5946,7 +5943,7 @@ static char *handle_cli_iax2_show_channels(struct ast_cli_entry *e, int cmd, str
                if (iaxs[x]) {
                        int lag, jitter, localdelay;
                        jb_info jbinfo;
-                       if (ast_test_flag(iaxs[x], IAX_USEJITTERBUF)) {
+                       if (ast_test_flag64(iaxs[x], IAX_USEJITTERBUF)) {
                                jb_getinfo(iaxs[x]->jb, &jbinfo);
                                jitter = jbinfo.jitter;
                                localdelay = jbinfo.current - jbinfo.min;
@@ -5999,7 +5996,7 @@ static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt)
                        iax_frame_subclass2str(iaxs[x]->first_iax_message & ~MARK_IAX_SUBCLASS_TX, first_message, sizeof(first_message));
                        iax_frame_subclass2str(iaxs[x]->last_iax_message & ~MARK_IAX_SUBCLASS_TX, last_message, sizeof(last_message));
 
-                       if(ast_test_flag(iaxs[x], IAX_USEJITTERBUF)) {
+                       if(ast_test_flag64(iaxs[x], IAX_USEJITTERBUF)) {
                                jb_getinfo(iaxs[x]->jb, &jbinfo);
                                localjitter = jbinfo.jitter;
                                localdelay = jbinfo.current - jbinfo.min;
@@ -6199,12 +6196,12 @@ static int iax2_write(struct ast_channel *c, struct ast_frame *f)
        if (iaxs[callno]) {
        /* If there's an outstanding error, return failure now */
                if (!iaxs[callno]->error) {
-                       if (ast_test_flag(iaxs[callno], IAX_ALREADYGONE))
+                       if (ast_test_flag64(iaxs[callno], IAX_ALREADYGONE))
                                res = 0;
                                /* Don't waste bandwidth sending null frames */
                        else if (f->frametype == AST_FRAME_NULL)
                                res = 0;
-                       else if ((f->frametype == AST_FRAME_VOICE) && ast_test_flag(iaxs[callno], IAX_QUELCH))
+                       else if ((f->frametype == AST_FRAME_VOICE) && ast_test_flag64(iaxs[callno], IAX_QUELCH))
                                res = 0;
                        else if (!ast_test_flag(&iaxs[callno]->state, IAX_STATE_STARTED))
                                res = 0;
@@ -6425,15 +6422,15 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
                }
                /* If a max AUTHREQ restriction is in place, activate it */
                if (user->maxauthreq > 0)
-                       ast_set_flag(iaxs[callno], IAX_MAXAUTHREQ);
+                       ast_set_flag64(iaxs[callno], IAX_MAXAUTHREQ);
                iaxs[callno]->prefs = user->prefs;
-               ast_copy_flags(iaxs[callno], user, IAX_CODEC_USER_FIRST | IAX_IMMEDIATE | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP | IAX_FORCE_ENCRYPT);
+               ast_copy_flags64(iaxs[callno], user, IAX_CODEC_USER_FIRST | IAX_IMMEDIATE | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP | IAX_FORCE_ENCRYPT);
                iaxs[callno]->encmethods = user->encmethods;
                /* Store the requested username if not specified */
                if (ast_strlen_zero(iaxs[callno]->username))
                        ast_string_field_set(iaxs[callno], username, user->name);
                /* Store whether this is a trunked call, too, of course, and move if appropriate */
-               ast_copy_flags(iaxs[callno], user, IAX_TRUNK);
+               ast_copy_flags64(iaxs[callno], user, IAX_TRUNK);
                iaxs[callno]->capability = user->capability;
                /* And use the default context */
                if (ast_strlen_zero(iaxs[callno]->context)) {
@@ -6448,7 +6445,7 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
                iaxs[callno]->authmethods = user->authmethods;
                iaxs[callno]->adsi = user->adsi;
                /* If the user has callerid, override the remote caller id. */
-               if (ast_test_flag(user, IAX_HASCALLERID)) {
+               if (ast_test_flag64(user, IAX_HASCALLERID)) {
                        iaxs[callno]->calling_tns = 0;
                        iaxs[callno]->calling_ton = 0;
                        ast_string_field_set(iaxs[callno], cid_num, user->cid_num);
@@ -6470,7 +6467,7 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
                        iaxs[callno]->amaflags = user->amaflags;
                if (!ast_strlen_zero(user->language))
                        ast_string_field_set(iaxs[callno], language, user->language);
-               ast_copy_flags(iaxs[callno], user, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE); 
+               ast_copy_flags64(iaxs[callno], user, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);       
                /* Keep this check last */
                if (!ast_strlen_zero(user->dbsecret)) {
                        char *family, *key=NULL;
@@ -6502,7 +6499,7 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
                        res = 0;
                }
        }
-       ast_set2_flag(iaxs[callno], iax2_getpeertrunk(*sin), IAX_TRUNK);        
+       ast_set2_flag64(iaxs[callno], iax2_getpeertrunk(*sin), IAX_TRUNK);
        return res;
 }
 
@@ -6556,7 +6553,7 @@ static int authenticate_request(int call_num)
        memset(&ied, 0, sizeof(ied));
 
        /* If an AUTHREQ restriction is in place, make sure we can send an AUTHREQ back */
-       if (ast_test_flag(p, IAX_MAXAUTHREQ)) {
+       if (ast_test_flag64(p, IAX_MAXAUTHREQ)) {
                struct iax2_user *user, tmp_user = {
                        .name = p->username,    
                };
@@ -6594,7 +6591,7 @@ static int authenticate_request(int call_num)
        res = send_command(p, AST_FRAME_IAX, IAX_COMMAND_AUTHREQ, 0, ied.buf, ied.pos, -1);
 
        if (p->encmethods)
-               ast_set_flag(p, IAX_ENCRYPTED);
+               ast_set_flag64(p, IAX_ENCRYPTED);
 
        return res;
 }
@@ -6616,14 +6613,14 @@ static int authenticate_verify(struct chan_iax2_pvt *p, struct iax_ies *ies)
        }
        user = ao2_find(users, &tmp_user, OBJ_POINTER);
        if (user) {
-               if (ast_test_flag(p, IAX_MAXAUTHREQ)) {
+               if (ast_test_flag64(p, IAX_MAXAUTHREQ)) {
                        ast_atomic_fetchadd_int(&user->curauthreq, -1);
-                       ast_clear_flag(p, IAX_MAXAUTHREQ);
+                       ast_clear_flag64(p, IAX_MAXAUTHREQ);
                }
                ast_string_field_set(p, host, user->name);
                user = user_unref(user);
        }
-       if (ast_test_flag(p, IAX_FORCE_ENCRYPT) && !p->encmethods) { 
+       if (ast_test_flag64(p, IAX_FORCE_ENCRYPT) && !p->encmethods) { 
                ast_log(LOG_NOTICE, "Call Terminated, Incomming call is unencrypted while force encrypt is enabled.");
                return res;
        }
@@ -6741,7 +6738,7 @@ static int register_verify(int callno, struct sockaddr_in *sin, struct iax_ies *
                goto return_unref;
        }
 
-       if (!ast_test_flag(p, IAX_DYNAMIC)) {
+       if (!ast_test_flag64(p, IAX_DYNAMIC)) {
                if (authdebug)
                        ast_log(LOG_NOTICE, "Peer '%s' is not dynamic (from %s)\n", peer, ast_inet_ntoa(sin->sin_addr));
                goto return_unref;
@@ -6963,8 +6960,8 @@ static int authenticate_reply(struct chan_iax2_pvt *p, struct sockaddr_in *sin,
        }
 
        if (ies->encmethods) {
-               ast_set_flag(p, IAX_ENCRYPTED | IAX_KEYPOPULATED);
-       } else if (ast_test_flag(iaxs[callno], IAX_FORCE_ENCRYPT)) {
+               ast_set_flag64(p, IAX_ENCRYPTED | IAX_KEYPOPULATED);
+       } else if (ast_test_flag64(iaxs[callno], IAX_FORCE_ENCRYPT)) {
                ast_log(LOG_NOTICE, "Call initiated without encryption while forceencryption=yes option is set");
                return -1;             /* if force encryption is yes, and no encryption methods, then return -1 to hangup */
        }
@@ -7333,21 +7330,21 @@ static void __expire_registry(const void *data)
        peer->expire = -1;
 
        ast_debug(1, "Expiring registration for peer '%s'\n", peer->name);
-       if (ast_test_flag((&globalflags), IAX_RTUPDATE) && (ast_test_flag(peer, IAX_TEMPONLY|IAX_RTCACHEFRIENDS)))
+       if (ast_test_flag64((&globalflags), IAX_RTUPDATE) && (ast_test_flag64(peer, IAX_TEMPONLY|IAX_RTCACHEFRIENDS)))
                realtime_update_peer(peer->name, &peer->addr, 0);
        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
        /* Reset the address */
        memset(&peer->addr, 0, sizeof(peer->addr));
        /* Reset expiry value */
        peer->expiry = min_reg_expire;
-       if (!ast_test_flag(peer, IAX_TEMPONLY))
+       if (!ast_test_flag64(peer, IAX_TEMPONLY))
                ast_db_del("IAX/Registry", peer->name);
        register_peer_exten(peer, 0);
        ast_devstate_changed(AST_DEVICE_UNAVAILABLE, "IAX2/%s", peer->name); /* Activate notification */
        if (iax2_regfunk)
                iax2_regfunk(peer->name, 0);
 
-       if (ast_test_flag(peer, IAX_RTAUTOCLEAR))
+       if (ast_test_flag64(peer, IAX_RTAUTOCLEAR))
                unlink_peer(peer);
 
        peer_unref(peer);
@@ -7369,7 +7366,7 @@ static void reg_source_db(struct iax2_peer *p)
        char data[80];
        struct in_addr in;
        char *c, *d;
-       if (!ast_test_flag(p, IAX_TEMPONLY) && (!ast_db_get("IAX/Registry", p->name, data, sizeof(data)))) {
+       if (!ast_test_flag64(p, IAX_TEMPONLY) && (!ast_db_get("IAX/Registry", p->name, data, sizeof(data)))) {
                c = strchr(data, ':');
                if (c) {
                        *c = '\0';
@@ -7439,7 +7436,7 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
        if (!iaxs[callno])
                goto return_unref;
 
-       if (ast_test_flag((&globalflags), IAX_RTUPDATE) && (ast_test_flag(p, IAX_TEMPONLY|IAX_RTCACHEFRIENDS))) {
+       if (ast_test_flag64((&globalflags), IAX_RTUPDATE) && (ast_test_flag64(p, IAX_TEMPONLY|IAX_RTCACHEFRIENDS))) {
                if (sin->sin_addr.s_addr) {
                        time_t nowtime;
                        time(&nowtime);
@@ -7454,14 +7451,14 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
                /* Stash the IP address from which they registered */
                memcpy(&p->addr, sin, sizeof(p->addr));
                snprintf(data, sizeof(data), "%s:%d:%d", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port), p->expiry);
-               if (!ast_test_flag(p, IAX_TEMPONLY) && sin->sin_addr.s_addr) {
+               if (!ast_test_flag64(p, IAX_TEMPONLY) && sin->sin_addr.s_addr) {
                        ast_db_put("IAX/Registry", p->name, data);
                        ast_verb(3, "Registered IAX2 '%s' (%s) at %s:%d\n", p->name,
                                            ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
                        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Registered\r\n", p->name);
                        register_peer_exten(p, 1);
                        ast_devstate_changed(AST_DEVICE_UNKNOWN, "IAX2/%s", p->name); /* Activate notification */
-               } else if (!ast_test_flag(p, IAX_TEMPONLY)) {
+               } else if (!ast_test_flag64(p, IAX_TEMPONLY)) {
                        ast_verb(3, "Unregistered IAX2 '%s' (%s)\n", p->name,
                                            ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED");
                        manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unregistered\r\n", p->name);
@@ -7545,7 +7542,7 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
 
                        iax_ie_append_short(&ied, IAX_IE_MSGCOUNT, msgcount);
                }
-               if (ast_test_flag(p, IAX_HASCALLERID)) {
+               if (ast_test_flag64(p, IAX_HASCALLERID)) {
                        iax_ie_append_str(&ied, IAX_IE_CALLING_NUMBER, p->cid_num);
                        iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, p->cid_name);
                }
@@ -7806,7 +7803,7 @@ static int send_trunk(struct iax2_trunk_peer *tpeer, struct timeval *now)
                /* We're actually sending a frame, so fill the meta trunk header and meta header */
                meta->zeros = 0;
                meta->metacmd = IAX_META_TRUNK;
-               if (ast_test_flag(&globalflags, IAX_TRUNKTIMESTAMPS))
+               if (ast_test_flag64(&globalflags, IAX_TRUNKTIMESTAMPS))
                        meta->cmddata = IAX_META_TRUNK_MINI;
                else
                        meta->cmddata = IAX_META_TRUNK_SUPERMINI;
@@ -8121,7 +8118,7 @@ static void log_jitterstats(unsigned short callno)
 
        ast_mutex_lock(&iaxsl[callno]);
        if (iaxs[callno] && iaxs[callno]->owner && iaxs[callno]->owner->name) {
-               if(ast_test_flag(iaxs[callno], IAX_USEJITTERBUF)) {
+               if(ast_test_flag64(iaxs[callno], IAX_USEJITTERBUF)) {
                        jb_getinfo(iaxs[callno]->jb, &jbinfo);
                        localjitter = jbinfo.jitter;
                        localdelay = jbinfo.current - jbinfo.min;
@@ -8646,7 +8643,7 @@ static int socket_process(struct iax2_thread *thread)
                        ast_mutex_unlock(&iaxsl[fr->callno]);
                return 1;
        }
-       if (ast_test_flag(iaxs[fr->callno], IAX_ENCRYPTED)) {
+       if (ast_test_flag64(iaxs[fr->callno], IAX_ENCRYPTED)) {
                if (decrypt_frame(fr->callno, fh, &f, &res)) {
                        ast_log(LOG_NOTICE, "Packet Decrypt Failed!\n");
                        ast_mutex_unlock(&iaxsl[fr->callno]);
@@ -8847,8 +8844,8 @@ static int socket_process(struct iax2_thread *thread)
                if ((f.frametype == AST_FRAME_VOICE) ||
                    (f.frametype == AST_FRAME_VIDEO) ||
                    (f.frametype == AST_FRAME_IAX)) {
-                       if (ast_test_flag(iaxs[fr->callno], IAX_DELAYPBXSTART)) {
-                               ast_clear_flag(iaxs[fr->callno], IAX_DELAYPBXSTART);
+                       if (ast_test_flag64(iaxs[fr->callno], IAX_DELAYPBXSTART)) {
+                               ast_clear_flag64(iaxs[fr->callno], IAX_DELAYPBXSTART);
                                if (!ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->chosenformat)) {
                                        ast_mutex_unlock(&iaxsl[fr->callno]);
                                        return 1;
@@ -8995,7 +8992,7 @@ retryowner:
                                                        iaxs[fr->callno]->owner->uniqueid);
                                        }
 
-                                       ast_set_flag(iaxs[fr->callno], IAX_QUELCH);
+                                       ast_set_flag64(iaxs[fr->callno], IAX_QUELCH);
                                        if (ies.musiconhold) {
                                                if (iaxs[fr->callno]->owner && ast_bridged_channel(iaxs[fr->callno]->owner)) {
                                                        const char *moh_suggest = iaxs[fr->callno]->mohsuggest;
@@ -9013,7 +9010,7 @@ retryowner:
                        case IAX_COMMAND_UNQUELCH:
                                if (ast_test_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED)) {
                                        /* Generate Manager Unhold event, if necessary*/
-                                       if (iaxs[fr->callno]->owner && ast_test_flag(iaxs[fr->callno], IAX_QUELCH)) {
+                                       if (iaxs[fr->callno]->owner && ast_test_flag64(iaxs[fr->callno], IAX_QUELCH)) {
                                                manager_event(EVENT_FLAG_CALL, "Hold",
                                                        "Status: Off\r\n"
                                                        "Channel: %s\r\n"
@@ -9022,7 +9019,7 @@ retryowner:
                                                        iaxs[fr->callno]->owner->uniqueid);
                                        }
 
-                                       ast_clear_flag(iaxs[fr->callno], IAX_QUELCH);
+                                       ast_clear_flag64(iaxs[fr->callno], IAX_QUELCH);
                                        if (iaxs[fr->callno]->owner && ast_bridged_channel(iaxs[fr->callno]->owner)) {
                                                iax2_queue_control_data(fr->callno, AST_CONTROL_UNHOLD, NULL, 0);
                                                if (!iaxs[fr->callno]) {
@@ -9061,7 +9058,7 @@ retryowner:
                                        }
                                }
                                /* If we're in trunk mode, do it now, and update the trunk number in our frame before continuing */
-                               if (ast_test_flag(iaxs[fr->callno], IAX_TRUNK)) {
+                               if (ast_test_flag64(iaxs[fr->callno], IAX_TRUNK)) {
                                        int new_callno;
                                        if ((new_callno = make_trunk(fr->callno, 1)) != -1)
                                                fr->callno = new_callno;
@@ -9076,7 +9073,7 @@ retryowner:
                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, who was trying to reach '%s@%s'\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->exten, iaxs[fr->callno]->context);
                                        break;
                                }
-                               if (ast_strlen_zero(iaxs[fr->callno]->secret) && ast_test_flag(iaxs[fr->callno], IAX_FORCE_ENCRYPT)) {
+                               if (ast_strlen_zero(iaxs[fr->callno]->secret) && ast_test_flag64(iaxs[fr->callno], IAX_FORCE_ENCRYPT)) {
                                        auth_fail(fr->callno, IAX_COMMAND_REJECT);
                                        ast_log(LOG_WARNING, "Rejected connect attempt.  No secret present while force encrypt enabled.\n");
                                        break;
@@ -9116,8 +9113,8 @@ retryowner:
                                        } else {
                                                /* Select an appropriate format */
 
-                                               if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
-                                                       if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
+                                               if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
+                                                       if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
                                                                using_prefs = "reqonly";
                                                        } else {
                                                                using_prefs = "disabled";
@@ -9133,7 +9130,7 @@ retryowner:
                                                                ast_codec_pref_convert(&iaxs[fr->callno]->rprefs, ies.codec_prefs, 32, 0);
                                                        if (ast_codec_pref_index(&iaxs[fr->callno]->rprefs, 0)) {
                                                                /* If we are codec_first_choice we let the caller have the 1st shot at picking the codec.*/
-                                                               if (ast_test_flag(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
+                                                               if (ast_test_flag64(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
                                                                        pref = iaxs[fr->callno]->rprefs;
                                                                        using_prefs = "caller";
                                                                } else {
@@ -9141,13 +9138,13 @@ retryowner:
                                                                }
                                                        } else
                                                                pref = iaxs[fr->callno]->prefs;
-                                                       
+
                                                        format = ast_codec_choose(&pref, iaxs[fr->callno]->capability & iaxs[fr->callno]->peercapability, 0);
                                                        ast_codec_pref_string(&iaxs[fr->callno]->rprefs, caller_pref_buf, sizeof(caller_pref_buf) - 1);
                                                        ast_codec_pref_string(&iaxs[fr->callno]->prefs, host_pref_buf, sizeof(host_pref_buf) - 1);
                                                }
                                                if (!format) {
-                                                       if(!ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP))
+                                                       if(!ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP))
                                                                format = iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability;
                                                        if (!format) {
                                                                memset(&ied0, 0, sizeof(ied0));
@@ -9159,19 +9156,19 @@ retryowner:
                                                                        return 1;
                                                                }
                                                                if (authdebug) {
-                                                                       if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP))
+                                                                       if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP))
                                                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested 0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat, iaxs[fr->callno]->capability);
                                                                        else 
                                                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat, iaxs[fr->callno]->peercapability, iaxs[fr->callno]->capability);
                                                                }
                                                        } else {
                                                                /* Pick one... */
-                                                               if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
+                                                               if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
                                                                        if(!(iaxs[fr->callno]->peerformat & iaxs[fr->callno]->capability))
                                                                                format = 0;
                                                                } else {
-                                                                       if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
-                                                                               using_prefs = ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP) ? "reqonly" : "disabled";
+                                                                       if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
+                                                                               using_prefs = ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP) ? "reqonly" : "disabled";
                                                                                memset(&pref, 0, sizeof(pref));
                                                                                format = ast_best_codec(iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability);
                                                                                strcpy(caller_pref_buf,"disabled");
@@ -9180,16 +9177,15 @@ retryowner:
                                                                                using_prefs = "mine";
                                                                                if (ast_codec_pref_index(&iaxs[fr->callno]->rprefs, 0)) {
                                                                                        /* Do the opposite of what we tried above. */
-                                                                                       if (ast_test_flag(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
-                                                                                               pref = iaxs[fr->callno]->prefs;                                                         
+                                                                                       if (ast_test_flag64(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
+                                                                                               pref = iaxs[fr->callno]->prefs;
                                                                                        } else {
                                                                                                pref = iaxs[fr->callno]->rprefs;
                                                                                                using_prefs = "caller";
                                                                                        }
                                                                                        format = ast_codec_choose(&pref, iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability, 1);
-                                                                       
                                                                                } else /* if no codec_prefs IE do it the old way */
-                                                                                       format = ast_best_codec(iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability);       
+                                                                                       format = ast_best_codec(iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability);
                                                                        }
                                                                }
 
@@ -9205,7 +9201,7 @@ retryowner:
                                                                        }
                                                                        if (authdebug)
                                                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat, iaxs[fr->callno]->peercapability, iaxs[fr->callno]->capability);
-                                                                       ast_set_flag(iaxs[fr->callno], IAX_ALREADYGONE);        
+                                                                       ast_set_flag64(iaxs[fr->callno], IAX_ALREADYGONE);
                                                                        break;
                                                                }
                                                        }
@@ -9234,9 +9230,9 @@ retryowner:
                                                                                                host_pref_buf, 
                                                                                                VERBOSE_PREFIX_4,
                                                                                                using_prefs);
-                                                               
+
                                                                iaxs[fr->callno]->chosenformat = format;
-                                                               ast_set_flag(iaxs[fr->callno], IAX_DELAYPBXSTART);
+                                                               ast_set_flag64(iaxs[fr->callno], IAX_DELAYPBXSTART);
                                                        } else {
                                                                ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_TBD);
                                                                /* If this is a TBD call, we're ready but now what...  */
@@ -9271,7 +9267,7 @@ retryowner:
                                }
                                break;
                        case IAX_COMMAND_HANGUP:
-                               ast_set_flag(iaxs[fr->callno], IAX_ALREADYGONE);
+                               ast_set_flag64(iaxs[fr->callno], IAX_ALREADYGONE);
                                ast_debug(1, "Immediately destroying %d, having received hangup\n", fr->callno);
                                /* Set hangup cause according to remote */
                                if (ies.causecode && iaxs[fr->callno]->owner)
@@ -9285,7 +9281,7 @@ retryowner:
                                if (ies.causecode && iaxs[fr->callno]->owner)
                                        iaxs[fr->callno]->owner->hangupcause = ies.causecode;
 
-                               if (!ast_test_flag(iaxs[fr->callno], IAX_PROVISION)) {
+                               if (!ast_test_flag64(iaxs[fr->callno], IAX_PROVISION)) {
                                        if (iaxs[fr->callno]->owner && authdebug)
                                                ast_log(LOG_WARNING, "Call rejected by %s: %s\n",
                                                        ast_inet_ntoa(iaxs[fr->callno]->addr.sin_addr),
@@ -9296,7 +9292,7 @@ retryowner:
                                /* Send ack immediately, before we destroy */
                                send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK,
                                                       fr->ts, NULL, 0, fr->iseqno);
-                               if (!ast_test_flag(iaxs[fr->callno], IAX_PROVISION))
+                               if (!ast_test_flag64(iaxs[fr->callno], IAX_PROVISION))
                                        iaxs[fr->callno]->error = EPERM;
                                iax2_destroy(fr->callno);
                                break;
@@ -9344,7 +9340,7 @@ retryowner:
                                /* Ignore if call is already up or needs authentication or is a TBD */
                                if (ast_test_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED | IAX_STATE_TBD | IAX_STATE_AUTHENTICATED))
                                        break;
-                               if (ast_test_flag(iaxs[fr->callno], IAX_PROVISION)) {
+                               if (ast_test_flag64(iaxs[fr->callno], IAX_PROVISION)) {
                                        /* Send ack immediately, before we destroy */
                                        send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
                                        iax2_destroy(fr->callno);
@@ -9545,8 +9541,8 @@ retryowner2:
                                        }
                                } else {
                                        /* Select an appropriate format */
-                                       if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
-                                               if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
+                                       if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
+                                               if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
                                                        using_prefs = "reqonly";
                                                } else {
                                                        using_prefs = "disabled";
@@ -9560,7 +9556,7 @@ retryowner2:
                                                if (ies.codec_prefs)
                                                        ast_codec_pref_convert(&iaxs[fr->callno]->rprefs, ies.codec_prefs, 32, 0);
                                                if (ast_codec_pref_index(&iaxs[fr->callno]->rprefs, 0)) {
-                                                       if (ast_test_flag(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
+                                                       if (ast_test_flag64(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
                                                                pref = iaxs[fr->callno]->rprefs;
                                                                using_prefs = "caller";
                                                        } else {
@@ -9568,19 +9564,18 @@ retryowner2:
                                                        }
                                                } else /* if no codec_prefs IE do it the old way */
                                                        pref = iaxs[fr->callno]->prefs;
-                                       
                                                format = ast_codec_choose(&pref, iaxs[fr->callno]->capability & iaxs[fr->callno]->peercapability, 0);
                                                ast_codec_pref_string(&iaxs[fr->callno]->rprefs, caller_pref_buf, sizeof(caller_pref_buf) - 1);
                                                ast_codec_pref_string(&iaxs[fr->callno]->prefs, host_pref_buf, sizeof(host_pref_buf) - 1);
                                        }
                                        if (!format) {
-                                               if(!ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
+                                               if(!ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
                                                        ast_debug(1, "We don't do requested format %s, falling back to peer capability %d\n", ast_getformatname(iaxs[fr->callno]->peerformat), iaxs[fr->callno]->peercapability);
                                                        format = iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability;
                                                }
                                                if (!format) {
                                                        if (authdebug) {
-                                                               if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP)) 
+                                                               if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP))
                                                                        ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested 0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat, iaxs[fr->callno]->capability);
                                                                else
                                                                        ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat, iaxs[fr->callno]->peercapability, iaxs[fr->callno]->capability);
@@ -9595,14 +9590,14 @@ retryowner2:
                                                        }
                                                } else {
                                                        /* Pick one... */
-                                                       if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
+                                                       if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP)) {
                                                                if(!(iaxs[fr->callno]->peerformat & iaxs[fr->callno]->capability))
                                                                        format = 0;
                                                        } else {
-                                                               if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
-                                                                       using_prefs = ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP) ? "reqonly" : "disabled";
+                                                               if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOPREFS)) {
+                                                                       using_prefs = ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP) ? "reqonly" : "disabled";
                                                                        memset(&pref, 0, sizeof(pref));
-                                                                       format = ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP) ?
+                                                                       format = ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP) ?
                                                                                iaxs[fr->callno]->peerformat : ast_best_codec(iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability);
                                                                        strcpy(caller_pref_buf,"disabled");
                                                                        strcpy(host_pref_buf,"disabled");
@@ -9610,8 +9605,8 @@ retryowner2:
                                                                        using_prefs = "mine";
                                                                        if (ast_codec_pref_index(&iaxs[fr->callno]->rprefs, 0)) {
                                                                                /* Do the opposite of what we tried above. */
-                                                                               if (ast_test_flag(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
-                                                                                       pref = iaxs[fr->callno]->prefs;                                         
+                                                                               if (ast_test_flag64(iaxs[fr->callno], IAX_CODEC_USER_FIRST)) {
+                                                                                       pref = iaxs[fr->callno]->prefs;
                                                                                } else {
                                                                                        pref = iaxs[fr->callno]->rprefs;
                                                                                        using_prefs = "caller";
@@ -9624,7 +9619,7 @@ retryowner2:
                                                        if (!format) {
                                                                ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr->callno]->peercapability & iaxs[fr->callno]->capability);
                                                                if (authdebug) {
-                                                                       if(ast_test_flag(iaxs[fr->callno], IAX_CODEC_NOCAP))
+                                                                       if(ast_test_flag64(iaxs[fr->callno], IAX_CODEC_NOCAP))
                                                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested 0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat, iaxs[fr->callno]->capability);
                                                                        else
                                                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible with our capability 0x%x.\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat, iaxs[fr->callno]->peercapability, iaxs[fr->callno]->capability);
@@ -9707,7 +9702,7 @@ retryowner2:
                                                        ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_TBD);
                                                        /* If this is a TBD call, we're ready but now what...  */
                                                        ast_verb(3, "Accepted AUTHENTICATED TBD call from %s\n", ast_inet_ntoa(sin.sin_addr));
-                                                       if (ast_test_flag(iaxs[fr->callno], IAX_IMMEDIATE)) {
+                                                       if (ast_test_flag64(iaxs[fr->callno], IAX_IMMEDIATE)) {
                                                                goto immediatedial;
                                                        }
                                                }
@@ -9906,8 +9901,8 @@ immediatedial:
 
                                                                iaxs[iaxs[fr->callno]->bridgecallno]->transferring = TRANSFER_RELEASED;
                                                                iaxs[fr->callno]->transferring = TRANSFER_RELEASED;
-                                                               ast_set_flag(iaxs[iaxs[fr->callno]->bridgecallno], IAX_ALREADYGONE);
-                                                               ast_set_flag(iaxs[fr->callno], IAX_ALREADYGONE);
+                                                               ast_set_flag64(iaxs[iaxs[fr->callno]->bridgecallno], IAX_ALREADYGONE);
+                                                               ast_set_flag64(iaxs[fr->callno], IAX_ALREADYGONE);
 
                                                                /* Stop doing lag & ping requests */
                                                                stop_stuff(fr->callno);
@@ -9971,7 +9966,7 @@ immediatedial:
                                break;
                        case IAX_COMMAND_FWDOWNL:
                                /* Firmware download */
-                               if (!ast_test_flag(&globalflags, IAX_ALLOWFWDOWNLOAD)) {
+                               if (!ast_test_flag64(&globalflags, IAX_ALLOWFWDOWNLOAD)) {
                                        send_command_final(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_UNSUPPORT, 0, NULL, 0, -1);
                                        break;
                                }
@@ -10075,7 +10070,7 @@ immediatedial:
        if (f.frametype == AST_FRAME_CONTROL && f.subclass == AST_CONTROL_CONNECTED_LINE) {
                struct ast_party_connected_line connected;
 
-               if (!ast_test_flag(iaxs[fr->callno], IAX_RECVCONNECTEDLINE)) {
+               if (!ast_test_flag64(iaxs[fr->callno], IAX_RECVCONNECTEDLINE)) {
                        ast_mutex_unlock(&iaxsl[fr->callno]);
                        return 1;
                }
@@ -10371,7 +10366,7 @@ static int iax2_provision(struct sockaddr_in *end, int sockfd, const char *dest,
                /* Schedule autodestruct in case they don't ever give us anything back */
                iaxs[callno]->autoid = iax2_sched_replace(iaxs[callno]->autoid, 
                        sched, 15000, auto_hangup, (void *)(long)callno);
-               ast_set_flag(iaxs[callno], IAX_PROVISION);
+               ast_set_flag64(iaxs[callno], IAX_PROVISION);
                /* Got a call number now, so go ahead and send the provisioning information */
                send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_PROVISION, 0, ied.buf, ied.pos, -1);
        }
@@ -10591,7 +10586,7 @@ static struct ast_channel *iax2_request(const char *type, int format, void *data
        memset(&cai, 0, sizeof(cai));
        cai.capability = iax2_capability;
 
-       ast_copy_flags(&cai, &globalflags, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+       ast_copy_flags64(&cai, &globalflags, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
        
        /* Populate our address from the given */
        if (create_addr(pds.peer, NULL, &sin, &cai)) {
@@ -10610,8 +10605,8 @@ static struct ast_channel *iax2_request(const char *type, int format, void *data
        }
 
        /* If this is a trunk, update it now */
-       ast_copy_flags(iaxs[callno], &cai, IAX_TRUNK | IAX_SENDANI | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
-       if (ast_test_flag(&cai, IAX_TRUNK)) {
+       ast_copy_flags64(iaxs[callno], &cai, IAX_TRUNK | IAX_SENDANI | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+       if (ast_test_flag64(&cai, IAX_TRUNK)) {
                int new_callno;
                if ((new_callno = make_trunk(callno, 1)) != -1)
                        callno = new_callno;
@@ -10852,7 +10847,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
 
        if (!temponly) {
                peer = ao2_find(peers, &tmp_peer, OBJ_POINTER);
-               if (peer && !ast_test_flag(peer, IAX_DELME))
+               if (peer && !ast_test_flag64(peer, IAX_DELME))
                        firstpass = 0;
        }
 
@@ -10873,7 +10868,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
 
        if (peer) {
                if (firstpass) {
-                       ast_copy_flags(peer, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
+                       ast_copy_flags64(peer, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
                        peer->encmethods = iax2_encryption;
                        peer->adsi = adsi;
                        ast_string_field_set(peer,secret,"");
@@ -10889,7 +10884,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
                        peer->pokefreqnotok = DEFAULT_FREQ_NOTOK;
                        ast_string_field_set(peer,context,"");
                        ast_string_field_set(peer,peercontext,"");
-                       ast_clear_flag(peer, IAX_HASCALLERID);
+                       ast_clear_flag64(peer, IAX_HASCALLERID);
                        ast_string_field_set(peer, cid_name, "");
                        ast_string_field_set(peer, cid_num, "");
                        ast_string_field_set(peer, mohinterpret, mohinterpret);
@@ -10916,42 +10911,42 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
                        } else if (!strcasecmp(v->name, "dbsecret")) {
                                ast_string_field_set(peer, dbsecret, v->value);
                        } else if (!strcasecmp(v->name, "trunk")) {
-                               ast_set2_flag(peer, ast_true(v->value), IAX_TRUNK);     
-                               if (ast_test_flag(peer, IAX_TRUNK) && !timer) {
+                               ast_set2_flag64(peer, ast_true(v->value), IAX_TRUNK);   
+                               if (ast_test_flag64(peer, IAX_TRUNK) && !timer) {
                                        ast_log(LOG_WARNING, "Unable to support trunking on peer '%s' without a timing interface\n", peer->name);
-                                       ast_clear_flag(peer, IAX_TRUNK);
+                                       ast_clear_flag64(peer, IAX_TRUNK);
                                }
                        } else if (!strcasecmp(v->name, "auth")) {
                                peer->authmethods = get_auth_methods(v->value);
                        } else if (!strcasecmp(v->name, "encryption")) {
                                peer->encmethods |= get_encrypt_methods(v->value);
                                if (!peer->encmethods) {
-                                       ast_clear_flag(peer, IAX_FORCE_ENCRYPT);
+                                       ast_clear_flag64(peer, IAX_FORCE_ENCRYPT);
                                }
                        } else if (!strcasecmp(v->name, "forceencryption")) {
                                if (ast_false(v->value)) {
-                                       ast_clear_flag(peer, IAX_FORCE_ENCRYPT);
+                                       ast_clear_flag64(peer, IAX_FORCE_ENCRYPT);
                                } else {
                                        peer->encmethods |= get_encrypt_methods(v->value);
                                        if (peer->encmethods) {
-                                               ast_set_flag(peer, IAX_FORCE_ENCRYPT);
+                                               ast_set_flag64(peer, IAX_FORCE_ENCRYPT);
                                        }
                                }
                        } else if (!strcasecmp(v->name, "transfer")) {
                                if (!strcasecmp(v->value, "mediaonly")) {
-                                       ast_set_flags_to(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);    
+                                       ast_set_flags_to64(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);
                                } else if (ast_true(v->value)) {
-                                       ast_set_flags_to(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, 0);
-                               } else 
-                                       ast_set_flags_to(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_NOTRANSFER);
+                                       ast_set_flags_to64(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, 0);
+                               } else
+                                       ast_set_flags_to64(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_NOTRANSFER);
                        } else if (!strcasecmp(v->name, "jitterbuffer")) {
-                               ast_set2_flag(peer, ast_true(v->value), IAX_USEJITTERBUF);      
+                               ast_set2_flag64(peer, ast_true(v->value), IAX_USEJITTERBUF);
                        } else if (!strcasecmp(v->name, "forcejitterbuffer")) {
-                               ast_set2_flag(peer, ast_true(v->value), IAX_FORCEJITTERBUF);    
+                               ast_set2_flag64(peer, ast_true(v->value), IAX_FORCEJITTERBUF);
                        } else if (!strcasecmp(v->name, "host")) {
                                if (!strcasecmp(v->value, "dynamic")) {
                                        /* They'll register with us */
-                                       ast_set_flag(peer, IAX_DYNAMIC);        
+                                       ast_set_flag64(peer, IAX_DYNAMIC);
                                        if (!found) {
                                                /* Initialize stuff iff we're not found, otherwise
                                                   we keep going with what we had */
@@ -10965,7 +10960,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
                                } else {
                                        /* Non-dynamic.  Make sure we become that way if we're not */
                                        ast_sched_thread_del(sched, peer->expire);
-                                       ast_clear_flag(peer, IAX_DYNAMIC);
+                                       ast_clear_flag64(peer, IAX_DYNAMIC);
                                        if (ast_dnsmgr_lookup(v->value, &peer->addr, &peer->dnsmgr, srvlookup ? "_iax._udp" : NULL))
                                                return peer_unref(peer);
                                        if (!peer->addr.sin_port)
@@ -10991,7 +10986,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
                        } else if (!strcasecmp(v->name, "peercontext")) {
                                ast_string_field_set(peer, peercontext, v->value);
                        } else if (!strcasecmp(v->name, "port")) {
-                               if (ast_test_flag(peer, IAX_DYNAMIC))
+                               if (ast_test_flag64(peer, IAX_DYNAMIC))
                                        peer->defaddr.sin_port = htons(atoi(v->value));
                                else
                                        peer->addr.sin_port = htons(atoi(v->value));
@@ -11012,15 +11007,15 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
                                        ast_string_field_set(peer, cid_name, "");
                                        ast_string_field_set(peer, cid_num, "");
                                }
-                               ast_set_flag(peer, IAX_HASCALLERID);
+                               ast_set_flag64(peer, IAX_HASCALLERID);
                        } else if (!strcasecmp(v->name, "fullname")) {
                                ast_string_field_set(peer, cid_name, S_OR(v->value, ""));
-                               ast_set_flag(peer, IAX_HASCALLERID);
+                               ast_set_flag64(peer, IAX_HASCALLERID);
                        } else if (!strcasecmp(v->name, "cid_number")) {
                                ast_string_field_set(peer, cid_num, S_OR(v->value, ""));
-                               ast_set_flag(peer, IAX_HASCALLERID);
+                               ast_set_flag64(peer, IAX_HASCALLERID);
                        } else if (!strcasecmp(v->name, "sendani")) {
-                               ast_set2_flag(peer, ast_true(v->value), IAX_SENDANI);   
+                               ast_set2_flag64(peer, ast_true(v->value), IAX_SENDANI);
                        } else if (!strcasecmp(v->name, "inkeys")) {
                                ast_string_field_set(peer, inkeys, v->value);
                        } else if (!strcasecmp(v->name, "outkey")) {
@@ -11050,15 +11045,15 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
                                peer->adsi = ast_true(v->value);
                        } else if (!strcasecmp(v->name, "connectedline")) {
                                if (ast_true(v->value)) {
-                                       ast_set_flag(peer, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+                                       ast_set_flag64(peer, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
                                } else if (!strcasecmp(v->value, "send")) {
-                                       ast_clear_flag(peer, IAX_RECVCONNECTEDLINE);
-                                       ast_set_flag(peer, IAX_SENDCONNECTEDLINE);
+                                       ast_clear_flag64(peer, IAX_RECVCONNECTEDLINE);
+                                       ast_set_flag64(peer, IAX_SENDCONNECTEDLINE);
                                } else if (!strcasecmp(v->value, "receive")) {
-                                       ast_clear_flag(peer, IAX_SENDCONNECTEDLINE);
-                                       ast_set_flag(peer, IAX_RECVCONNECTEDLINE);
+                                       ast_clear_flag64(peer, IAX_SENDCONNECTEDLINE);
+                                       ast_set_flag64(peer, IAX_RECVCONNECTEDLINE);
                                } else {
-                                       ast_clear_flag(peer, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+                                       ast_clear_flag64(peer, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
                                }
                        }/* else if (strcasecmp(v->name,"type")) */
                        /*      ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
@@ -11070,7 +11065,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
                }
                if (!peer->authmethods)
                        peer->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
-               ast_clear_flag(peer, IAX_DELME);        
+               ast_clear_flag64(peer, IAX_DELME);
                /* Make sure these are IPv4 addresses */
                peer->addr.sin_family = AF_INET;
        }
@@ -11124,7 +11119,7 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
 
        if (!temponly) {
                user = ao2_find(users, &tmp_user, OBJ_POINTER);
-               if (user && !ast_test_flag(user, IAX_DELME))
+               if (user && !ast_test_flag64(user, IAX_DELME))
                        firstpass = 0;
        }
 
@@ -11158,8 +11153,8 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
                        user->adsi = adsi;
                        ast_string_field_set(user, name, name);
                        ast_string_field_set(user, language, language);
-                       ast_copy_flags(user, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_CODEC_USER_FIRST | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
-                       ast_clear_flag(user, IAX_HASCALLERID);
+                       ast_copy_flags64(user, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_CODEC_USER_FIRST | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
+                       ast_clear_flag64(user, IAX_HASCALLERID);
                        ast_string_field_set(user, cid_name, "");
                        ast_string_field_set(user, cid_num, "");
                        ast_string_field_set(user, accountcode, accountcode);
@@ -11198,49 +11193,49 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
                        } else if (!strcasecmp(v->name, "disallow")) {
                                ast_parse_allow_disallow(&user->prefs, &user->capability,v->value, 0);
                        } else if (!strcasecmp(v->name, "trunk")) {
-                               ast_set2_flag(user, ast_true(v->value), IAX_TRUNK);     
-                               if (ast_test_flag(user, IAX_TRUNK) && !timer) {
+                               ast_set2_flag64(user, ast_true(v->value), IAX_TRUNK);   
+                               if (ast_test_flag64(user, IAX_TRUNK) && !timer) {
                                        ast_log(LOG_WARNING, "Unable to support trunking on user '%s' without a timing interface\n", user->name);
-                                       ast_clear_flag(user, IAX_TRUNK);
+                                       ast_clear_flag64(user, IAX_TRUNK);
                                }
                        } else if (!strcasecmp(v->name, "auth")) {
                                user->authmethods = get_auth_methods(v->value);
                        } else if (!strcasecmp(v->name, "encryption")) {
                                user->encmethods |= get_encrypt_methods(v->value);
                                if (!user->encmethods) {
-                                       ast_clear_flag(user, IAX_FORCE_ENCRYPT);
+                                       ast_clear_flag64(user, IAX_FORCE_ENCRYPT);
                                }
                        } else if (!strcasecmp(v->name, "forceencryption")) {
                                if (ast_false(v->value)) {
-                                       ast_clear_flag(user, IAX_FORCE_ENCRYPT);
+                                       ast_clear_flag64(user, IAX_FORCE_ENCRYPT);
                                } else {
                                        user->encmethods |= get_encrypt_methods(v->value);
                                        if (user->encmethods) {
-                                               ast_set_flag(user, IAX_FORCE_ENCRYPT);
+                                               ast_set_flag64(user, IAX_FORCE_ENCRYPT);
                                        }
                                }
                        } else if (!strcasecmp(v->name, "transfer")) {
                                if (!strcasecmp(v->value, "mediaonly")) {
-                                       ast_set_flags_to(user, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);    
+                                       ast_set_flags_to64(user, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);
                                } else if (ast_true(v->value)) {
-                                       ast_set_flags_to(user, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, 0);
-                               } else 
-                                       ast_set_flags_to(user, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_NOTRANSFER);
+                                       ast_set_flags_to64(user, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, 0);
+                               } else
+                                       ast_set_flags_to64(user, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_NOTRANSFER);
                        } else if (!strcasecmp(v->name, "codecpriority")) {
                                if(!strcasecmp(v->value, "caller"))
-                                       ast_set_flag(user, IAX_CODEC_USER_FIRST);
+                                       ast_set_flag64(user, IAX_CODEC_USER_FIRST);
                                else if(!strcasecmp(v->value, "disabled"))
-                                       ast_set_flag(user, IAX_CODEC_NOPREFS);
+                                       ast_set_flag64(user, IAX_CODEC_NOPREFS);
                                else if(!strcasecmp(v->value, "reqonly")) {
-                                       ast_set_flag(user, IAX_CODEC_NOCAP);
-                                       ast_set_flag(user, IAX_CODEC_NOPREFS);
+                                       ast_set_flag64(user, IAX_CODEC_NOCAP);
+                                       ast_set_flag64(user, IAX_CODEC_NOPREFS);
                                }
                        } else if (!strcasecmp(v->name, "immediate")) {
-                               ast_set2_flag(user, ast_true(v->value), IAX_IMMEDIATE);
+                               ast_set2_flag64(user, ast_true(v->value), IAX_IMMEDIATE);
                        } else if (!strcasecmp(v->name, "jitterbuffer")) {
-                               ast_set2_flag(user, ast_true(v->value), IAX_USEJITTERBUF);
+                               ast_set2_flag64(user, ast_true(v->value), IAX_USEJITTERBUF);
                        } else if (!strcasecmp(v->name, "forcejitterbuffer")) {
-                               ast_set2_flag(user, ast_true(v->value), IAX_FORCEJITTERBUF);
+                               ast_set2_flag64(user, ast_true(v->value), IAX_FORCEJITTERBUF);
                        } else if (!strcasecmp(v->name, "dbsecret")) {
                                ast_string_field_set(user, dbsecret, v->value);
                        } else if (!strcasecmp(v->name, "secret")) {
@@ -11257,29 +11252,29 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
                                        ast_callerid_split(v->value, name2, sizeof(name2), num2, sizeof(num2));
                                        ast_string_field_set(user, cid_name, name2);
                                        ast_string_field_set(user, cid_num, num2);
-                                       ast_set_flag(user, IAX_HASCALLERID);
+                                       ast_set_flag64(user, IAX_HASCALLERID);
                                } else {
-                                       ast_clear_flag(user, IAX_HASCALLERID);
+                                       ast_clear_flag64(user, IAX_HASCALLERID);
                                        ast_string_field_set(user, cid_name, "");
                                        ast_string_field_set(user, cid_num, "");
                                }
                        } else if (!strcasecmp(v->name, "fullname")) {
                                if (!ast_strlen_zero(v->value)) {
                                        ast_string_field_set(user, cid_name, v->value);
-                                       ast_set_flag(user, IAX_HASCALLERID);
+                                       ast_set_flag64(user, IAX_HASCALLERID);
                                } else {
                                        ast_string_field_set(user, cid_name, "");
                                        if (ast_strlen_zero(user->cid_num))
-                                               ast_clear_flag(user, IAX_HASCALLERID);
+                                               ast_clear_flag64(user, IAX_HASCALLERID);
                                }
                        } else if (!strcasecmp(v->name, "cid_number")) {
                                if (!ast_strlen_zero(v->value)) {
                                        ast_string_field_set(user, cid_num, v->value);
-                                       ast_set_flag(user, IAX_HASCALLERID);
+                                       ast_set_flag64(user, IAX_HASCALLERID);
                                } else {
                                        ast_string_field_set(user, cid_num, "");
                                        if (ast_strlen_zero(user->cid_name))
-                                               ast_clear_flag(user, IAX_HASCALLERID);
+                                               ast_clear_flag64(user, IAX_HASCALLERID);
                                }
                        } else if (!strcasecmp(v->name, "accountcode")) {
                                ast_string_field_set(user, accountcode, v->value);
@@ -11308,15 +11303,15 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
                                user->adsi = ast_true(v->value);
                        } else if (!strcasecmp(v->name, "connectedline")) {
                                if (ast_true(v->value)) {
-                                       ast_set_flag(user, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+                                       ast_set_flag64(user, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
                                } else if (!strcasecmp(v->value, "send")) {
-                                       ast_clear_flag(user, IAX_RECVCONNECTEDLINE);
-                                       ast_set_flag(user, IAX_SENDCONNECTEDLINE);
+                                       ast_clear_flag64(user, IAX_RECVCONNECTEDLINE);
+                                       ast_set_flag64(user, IAX_SENDCONNECTEDLINE);
                                } else if (!strcasecmp(v->value, "receive")) {
-                                       ast_clear_flag(user, IAX_SENDCONNECTEDLINE);
-                                       ast_set_flag(user, IAX_RECVCONNECTEDLINE);
+                                       ast_clear_flag64(user, IAX_SENDCONNECTEDLINE);
+                                       ast_set_flag64(user, IAX_RECVCONNECTEDLINE);
                                } else {
-                                       ast_clear_flag(user, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+                                       ast_clear_flag64(user, IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
                                }
                        }/* else if (strcasecmp(v->name,"type")) */
                        /*      ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
@@ -11337,7 +11332,7 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
                                user->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
                        }
                }
-               ast_clear_flag(user, IAX_DELME);
+               ast_clear_flag64(user, IAX_DELME);
        }
 cleanup:
        if (oldha)
@@ -11351,7 +11346,7 @@ static int peer_delme_cb(void *obj, void *arg, int flags)
 {
        struct iax2_peer *peer = obj;
 
-       ast_set_flag(peer, IAX_DELME);
+       ast_set_flag64(peer, IAX_DELME);
 
        return 0;
 }
@@ -11360,7 +11355,7 @@ static int user_delme_cb(void *obj, void *arg, int flags)
 {
        struct iax2_user *user = obj;
 
-       ast_set_flag(user, IAX_DELME);
+       ast_set_flag64(user, IAX_DELME);
 
        return 0;
 }
@@ -11401,7 +11396,7 @@ static void prune_users(void)
 
        i = ao2_iterator_init(users, 0);
        while ((user = ao2_iterator_next(&i))) {
-               if (ast_test_flag(user, IAX_DELME) || ast_test_flag(user, IAX_RTCACHEFRIENDS)) {
+               if (ast_test_flag64(user, IAX_DELME) || ast_test_flag64(user, IAX_RTCACHEFRIENDS)) {
                        ao2_unlink(users, user);
                }
                user_unref(user);
@@ -11416,7 +11411,7 @@ static void prune_peers(void)
 
        i = ao2_iterator_init(peers, 0);
        while ((peer = ao2_iterator_next(&i))) {
-               if (ast_test_flag(peer, IAX_DELME) || ast_test_flag(peer, IAX_RTCACHEFRIENDS)) {
+               if (ast_test_flag64(peer, IAX_DELME) || ast_test_flag64(peer, IAX_RTCACHEFRIENDS)) {
                        unlink_peer(peer);
                }
                peer_unref(peer);
@@ -11432,7 +11427,7 @@ static void set_config_destroy(void)
        trunkmaxsize = MAX_TRUNKDATA;
        amaflags = 0;
        delayreject = 0;
-       ast_clear_flag((&globalflags), IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF |
+       ast_clear_flag64((&globalflags), IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF |
                IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
        delete_users();
 }
@@ -11490,13 +11485,13 @@ static int set_config(char *config_file, int reload)
                set_config_destroy();
        }
 
-       /* Reset global codec prefs */  
+       /* Reset global codec prefs */
        memset(&prefs, 0 , sizeof(struct ast_codec_pref));
-       
+
        /* Reset Global Flags */
        memset(&globalflags, 0, sizeof(globalflags));
-       ast_set_flag(&globalflags, IAX_RTUPDATE);
-       
+       ast_set_flag64(&globalflags, IAX_RTUPDATE);
+
 #ifdef SO_NO_CHECK
        nochecksums = 0;
 #endif
@@ -11608,67 +11603,67 @@ static int set_config(char *config_file, int reload)
                } else if (!strcasecmp(v->name, "encryption")) {
                                iax2_encryption |= get_encrypt_methods(v->value);
                                if (!iax2_encryption) {
-                                       ast_clear_flag((&globalflags), IAX_FORCE_ENCRYPT);
+                                       ast_clear_flag64((&globalflags), IAX_FORCE_ENCRYPT);
                                }
                } else if (!strcasecmp(v->name, "forceencryption")) {
                        if (ast_false(v->value)) {
-                               ast_clear_flag((&globalflags), IAX_FORCE_ENCRYPT);
+                               ast_clear_flag64((&globalflags), IAX_FORCE_ENCRYPT);
                        } else {
                                iax2_encryption |= get_encrypt_methods(v->value);
                                if (iax2_encryption) {
-                                       ast_set_flag((&globalflags), IAX_FORCE_ENCRYPT);
+                                       ast_set_flag64((&globalflags), IAX_FORCE_ENCRYPT);
                                }
                        }
                } else if (!strcasecmp(v->name, "transfer")) {
                        if (!strcasecmp(v->value, "mediaonly")) {
-                               ast_set_flags_to((&globalflags), IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);  
+                               ast_set_flags_to64((&globalflags), IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);
                        } else if (ast_true(v->value)) {
-                               ast_set_flags_to((&globalflags), IAX_NOTRANSFER|IAX_TRANSFERMEDIA, 0);
-                       } else 
-                               ast_set_flags_to((&globalflags), IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_NOTRANSFER);
+                               ast_set_flags_to64((&globalflags), IAX_NOTRANSFER|IAX_TRANSFERMEDIA, 0);
+                       } else
+                               ast_set_flags_to64((&globalflags), IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_NOTRANSFER);
                } else if (!strcasecmp(v->name, "codecpriority")) {
                        if(!strcasecmp(v->value, "caller"))
-                               ast_set_flag((&globalflags), IAX_CODEC_USER_FIRST);
+                               ast_set_flag64((&globalflags), IAX_CODEC_USER_FIRST);
                        else if(!strcasecmp(v->value, "disabled"))
-                               ast_set_flag((&globalflags), IAX_CODEC_NOPREFS);
+                               ast_set_flag64((&globalflags), IAX_CODEC_NOPREFS);
                        else if(!strcasecmp(v->value, "reqonly")) {
-                               ast_set_flag((&globalflags), IAX_CODEC_NOCAP);
-                               ast_set_flag((&globalflags), IAX_CODEC_NOPREFS);
+                               ast_set_flag64((&globalflags), IAX_CODEC_NOCAP);
+                               ast_set_flag64((&globalflags), IAX_CODEC_NOPREFS);
                        }
                } else if (!strcasecmp(v->name, "jitterbuffer"))
-                       ast_set2_flag((&globalflags), ast_true(v->value), IAX_USEJITTERBUF);    
+                       ast_set2_flag64((&globalflags), ast_true(v->value), IAX_USEJITTERBUF);
                else if (!strcasecmp(v->name, "forcejitterbuffer"))
-                       ast_set2_flag((&globalflags), ast_true(v->value), IAX_FORCEJITTERBUF);  
+                       ast_set2_flag64((&globalflags), ast_true(v->value), IAX_FORCEJITTERBUF);
                else if (!strcasecmp(v->name, "delayreject"))
                        delayreject = ast_true(v->value);
                else if (!strcasecmp(v->name, "allowfwdownload"))
-                       ast_set2_flag((&globalflags), ast_true(v->value), IAX_ALLOWFWDOWNLOAD);
+                       ast_set2_flag64((&globalflags), ast_true(v->value), IAX_ALLOWFWDOWNLOAD);
                else if (!strcasecmp(v->name, "rtcachefriends"))
-                       ast_set2_flag((&globalflags), ast_true(v->value), IAX_RTCACHEFRIENDS);  
+                       ast_set2_flag64((&globalflags), ast_true(v->value), IAX_RTCACHEFRIENDS);
                else if (!strcasecmp(v->name, "rtignoreregexpire"))
-                       ast_set2_flag((&globalflags), ast_true(v->value), IAX_RTIGNOREREGEXPIRE);       
+                       ast_set2_flag64((&globalflags), ast_true(v->value), IAX_RTIGNOREREGEXPIRE);
                else if (!strcasecmp(v->name, "rtupdate"))
-                       ast_set2_flag((&globalflags), ast_true(v->value), IAX_RTUPDATE);
+                       ast_set2_flag64((&globalflags), ast_true(v->value), IAX_RTUPDATE);
                else if (!strcasecmp(v->name, "trunktimestamps"))
-                       ast_set2_flag(&globalflags, ast_true(v->value), IAX_TRUNKTIMESTAMPS);
+                       ast_set2_flag64(&globalflags, ast_true(v->value), IAX_TRUNKTIMESTAMPS);
                else if (!strcasecmp(v->name, "rtautoclear")) {
                        int i = atoi(v->value);
                        if(i > 0)
                                global_rtautoclear = i;
                        else
                                i = 0;
-                       ast_set2_flag((&globalflags), i || ast_true(v->value), IAX_RTAUTOCLEAR);        
+                       ast_set2_flag64((&globalflags), i || ast_true(v->value), IAX_RTAUTOCLEAR);
                } else if (!strcasecmp(v->name, "trunkfreq")) {
                        trunkfreq = atoi(v->value);
                        if (trunkfreq < 10)
                                trunkfreq = 10;
                } else if (!strcasecmp(v->name, "trunkmtu")) {
                        mtuv = atoi(v->value);
-                       if (mtuv  == 0 )  
-                               global_max_trunk_mtu = 0; 
-                       else if (mtuv >= 172 && mtuv < 4000) 
-                               global_max_trunk_mtu = mtuv; 
-                       else 
+                       if (mtuv  == 0 )
+                               global_max_trunk_mtu = 0;
+                       else if (mtuv >= 172 && mtuv < 4000)
+                               global_max_trunk_mtu = mtuv;
+                       else
                                ast_log(LOG_NOTICE, "trunkmtu value out of bounds (%d) at line %d\n",
                                        mtuv, v->lineno);
                } else if (!strcasecmp(v->name, "trunkmaxsize")) {
@@ -11740,15 +11735,15 @@ static int set_config(char *config_file, int reload)
                        srvlookup = ast_true(v->value);
                } else if (!strcasecmp(v->name, "connectedline")) {
                        if (ast_true(v->value)) {
-                               ast_set_flag((&globalflags), IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+                               ast_set_flag64((&globalflags), IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
                        } else if (!strcasecmp(v->value, "send")) {
-                               ast_clear_flag((&globalflags), IAX_RECVCONNECTEDLINE);
-                               ast_set_flag((&globalflags), IAX_SENDCONNECTEDLINE);
+                               ast_clear_flag64((&globalflags), IAX_RECVCONNECTEDLINE);
+                               ast_set_flag64((&globalflags), IAX_SENDCONNECTEDLINE);
                        } else if (!strcasecmp(v->value, "receive")) {
-                               ast_clear_flag((&globalflags), IAX_SENDCONNECTEDLINE);
-                               ast_set_flag((&globalflags), IAX_RECVCONNECTEDLINE);
+                               ast_clear_flag64((&globalflags), IAX_SENDCONNECTEDLINE);
+                               ast_set_flag64((&globalflags), IAX_RECVCONNECTEDLINE);
                        } else {
-                               ast_clear_flag((&globalflags), IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
+                               ast_clear_flag64((&globalflags), IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE);
                        }
                } /*else if (strcasecmp(v->name,"type")) */
                /*      ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */
@@ -11804,7 +11799,7 @@ static int set_config(char *config_file, int reload)
                                        }
                                        peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
                                        if (peer) {
-                                               if (ast_test_flag(peer, IAX_DYNAMIC))
+                                               if (ast_test_flag64(peer, IAX_DYNAMIC))
                                                        reg_source_db(peer);
                                                ao2_link(peers, peer);
                                                peer = peer_unref(peer);
@@ -11850,7 +11845,7 @@ static int set_config(char *config_file, int reload)
                                if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
                                        peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
                                        if (peer) {
-                                               if (ast_test_flag(peer, IAX_DYNAMIC))
+                                               if (ast_test_flag64(peer, IAX_DYNAMIC))
                                                        reg_source_db(peer);
                                                ao2_link(peers, peer);
                                                peer = peer_unref(peer);
@@ -12287,7 +12282,7 @@ static int function_iaxpeer(struct ast_channel *chan, const char *cmd, char *dat
        } else  if (!strcasecmp(colname, "expire")) {
                snprintf(buf, len, "%d", peer->expire);
        } else  if (!strcasecmp(colname, "dynamic")) {
-               ast_copy_string(buf, (ast_test_flag(peer, IAX_DYNAMIC) ? "yes" : "no"), len);
+               ast_copy_string(buf, (ast_test_flag64(peer, IAX_DYNAMIC) ? "yes" : "no"), len);
        } else  if (!strcasecmp(colname, "callerid_name")) {
                ast_copy_string(buf, peer->cid_name, len);
        } else  if (!strcasecmp(colname, "callerid_num")) {