All pastes #943037 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-03-14 22:32 UTC
rendered paste body
static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
{
    struct sip_request req;
    char from[256];
    char to[256];
    char tmp[80];
    char addr[80];
    struct sip_pvt *p;
    struct in_addr sin;
    int changed = 0;

    ast_log(LOG_DEBUG, "Transmit_Register\n");

    /* exit if we are already in process with this registrar ?*/
    if ( r == NULL || ((auth==NULL) && (r->regstate==REG_STATE_REGSENT || r->regstate==REG_STATE_AUTHSENT))) {
        ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname);
        return 0;
    }

    if (r->dnsmgr == NULL) {
        ast_dnsmgr_lookup(r->hostname, &sin, &r->dnsmgr);
        memcpy(&sin, &r->us.sin_addr, sizeof(sin));
        ast_log(LOG_DEBUG, "dnsmgr was NULL\n");
    } else {
        changed = ast_dnsmgr_changed(r->dnsmgr);
        ast_log(LOG_DEBUG, "Change status = %d\n", changed);
    }

    if (r->call && !changed) {  /* We have a registration and the IP has not changed*/
        if (!auth) {
            ast_log(LOG_WARNING, "Already have a REGISTER going on to %s@%s?? \n", r->username, r->hostname);
            return 0;
        } else {
            ast_log(LOG_DEBUG, "registration valid and authorized\n");
            p = r->call;
            make_our_tag(p->tag, sizeof(p->tag));   /* create a new local tag for every register attempt */
            ast_string_field_set(p, theirtag, NULL);    /* forget their old tag, so we don't match tags when getting response */
        }
    } else {
        if (changed) {
            ast_log(LOG_DEBUG, "IP change detected, cancelling current registration\n");
            //r->call = sip_destroy(r->call);
            // TODO: HELP?
        }

        /* Build callid for registration if we haven't registered before */
        /* Build callid for registration if we haven't registered before */
        if (!r->callid_valid) {
            build_callid_registry(r, internip.sin_addr, default_fromdomain);
            r->callid_valid = TRUE;
        }
        /* Allocate SIP dialog for registration */
        if (!(p = sip_alloc( r->callid, NULL, 0, SIP_REGISTER))) {
            ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n");
            return 0;
        }

        if (p->do_history)
            append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);

        p->outboundproxy = obproxy_get(p, NULL);

        /* Find address to hostname */
        if (create_addr(p, r->hostname)) {
            /* we have what we hope is a temporary network error,
             * probably DNS.  We need to reschedule a registration try */
            sip_destroy(p);
            if (r->timeout > -1) {
                AST_SCHED_REPLACE(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r);
                ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout);
            } else {
                r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r);
                ast_log(LOG_WARNING, "Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n", r->username, r->hostname, global_reg_timeout);
            }
....                                                                                                                                                                                             9162,1        42%