예제 #1
0
/**
 * gnutls_srtp_get_profile_id
 * @name: The name of the profile to look up
 * @profile: Will hold the profile id
 *
 * This function allows you to look up a profile based on a string.
 *
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned,
 *   otherwise a negative error code is returned.
 *
 * Since 3.1.4
 **/
int gnutls_srtp_get_profile_id(const char *name,
			       gnutls_srtp_profile_t * profile)
{
	*profile = find_profile(name, NULL);
	if (*profile == 0) {
		return GNUTLS_E_ILLEGAL_PARAMETER;
	}
	return 0;
}
예제 #2
0
int switch_profile(configuration *config, const char* name)
{
    profile* p = find_profile(name, config, 0);
    if (!p) {
       return 1;
    }
    config->current_profile = p;
    return 0;
}
예제 #3
0
/**
 * gnutls_srtp_set_profile_direct:
 * @session: is a #gnutls_session_t type.
 * @profiles: is a string that contains the supported SRTP profiles,
 *   separated by colons.
 * @err_pos: In case of an error this will have the position in the string the error occurred, may be NULL.
 *
 * This function is to be used by both clients and servers, to declare
 * what SRTP profiles they support, to negotiate with the peer.
 *
 * Returns: On syntax error %GNUTLS_E_INVALID_REQUEST is returned,
 * %GNUTLS_E_SUCCESS on success, or an error code.
 *
 * Since 3.1.4
 **/
int
gnutls_srtp_set_profile_direct(gnutls_session_t session,
			       const char *profiles, const char **err_pos)
{
	int ret;
	srtp_ext_st *priv;
	extension_priv_data_t epriv;
	int set = 0;
	const char *col;
	gnutls_srtp_profile_t id;

	ret =
	    _gnutls_ext_get_session_data(session, GNUTLS_EXTENSION_SRTP,
					 &epriv);
	if (ret < 0) {
		set = 1;
		priv = gnutls_calloc(1, sizeof(*priv));
		if (priv == NULL) {
			if (err_pos != NULL)
				*err_pos = profiles;
			gnutls_assert();
			return GNUTLS_E_MEMORY_ERROR;
		}
		epriv = priv;
	} else
		priv = epriv;

	do {
		col = strchr(profiles, ':');
		id = find_profile(profiles, col);
		if (id == 0) {
			if (set != 0)
				gnutls_free(priv);
			if (err_pos != NULL)
				*err_pos = profiles;
			return GNUTLS_E_INVALID_REQUEST;
		}

		if (priv->profiles_size < MAX_SRTP_PROFILES) {
			priv->profiles_size++;
		}
		priv->profiles[priv->profiles_size - 1] = id;
		profiles = col + 1;
	} while (col != NULL);

	if (set != 0)
		_gnutls_ext_set_session_data(session,
					     GNUTLS_EXTENSION_SRTP, epriv);

	return 0;
}
예제 #4
0
//----------------------------------------------------------------------------------------------------------------------------------
// Main function for decompressing a ROHC-packet.
// Param state: pointer to decompressor
// Param ibuf: pointer to incoming packet
// Param isize: size of incoming packet
// Param obuf: pointer to output buffer
// Param osize: size of output buffer
// Param ddata: struct that holds important information to pass between several functions
// Return: size of decompressed packet
//----------------------------------------------------------------------------------------------------------------------------------
int d_decode_header(struct sd_rohc * state, unsigned char * ibuf, int isize, unsigned char * obuf, int osize, struct sd_decode_data * ddata)
{
	int largecid=0, size, irdynvar=0, casenew=0;

	struct s_profile * profile;
	unsigned char * walk = ibuf;

	if(isize < 2)
		return(ROHC_ERROR_NO_CONTEXT);
	ddata->cid = d_decode_feedback_first(state, &walk, isize);
	if(ddata->cid == ROHC_FEEDBACK_ONLY || ddata->cid == ROHC_ERROR_NO_CONTEXT)
		return(ddata->cid);

	if(ddata->cid > 0 && state->medium->cid_type == ROHC_SMALL_CID)
		ddata->addcidUsed=1;

	if(!ddata->addcidUsed && state->medium->cid_type == ROHC_LARGE_CID) {		// check if large cids are used
		largecid = d_sdvalue_size(walk+1);
		if(largecid >0 && largecid < 3) {
			ddata->cid = d_sdvalue_decode(walk+1);
			ddata->largecidUsed=1;
		} else
			return(ROHC_ERROR_NO_CONTEXT);
	}

	if(d_is_ir(walk)) {
		profile = find_profile(walk[largecid+1]);

		if(!rohc_ir_packet_crc_ok(walk, largecid, ddata->addcidUsed, profile))
			return(ROHC_ERROR_CRC);

		if(ddata->cid >= state->context_array_size)
			context_array_increase(state, ddata->cid);

		if(state->context[ddata->cid] && state->context[ddata->cid]->profile == profile) {
			ddata->active = state->context[ddata->cid];
			state->context[ddata->cid] = NULL;
		} else {
			casenew=1;
			ddata->active = context_create(state, ddata->cid, profile);
			if(!ddata->active)
				return(ROHC_ERROR_NO_CONTEXT);
		}

		ddata->active->num_recv_ir ++;
		size = ddata->active->profile->decode_ir(state, ddata->active, walk+largecid+3, (isize-(walk-ibuf))-3-largecid, GET_BIT_0(walk), obuf);
		if(size>0) {
			context_free(state->context[ddata->cid]);
			state->context[ddata->cid] = ddata->active;
			return(size);
		}
		if(casenew)
			context_free(ddata->active);
		else
			state->context[ddata->cid] = ddata->active;

		return(size);
	} else {
		ddata->active = find_context(state, ddata->cid);	// find context
		if(ddata->active && ddata->active->profile) {		// context is valid
			ddata->active->latest_used = get_milliseconds();
			if(d_is_irdyn(walk)) {
				ddata->active->num_recv_ir_dyn ++;
				profile = find_profile(walk[largecid+1]);
				if(profile != ddata->active->profile) {		// if IR-DYN changes profile, make comp. transit to NO_CONTEXT-state
					state->curval = state->maxval;
					rohc_debugf(2,"IR-DYN changed profile, sending S-NACK.\n");
					return(ROHC_ERROR_NO_CONTEXT);
				}
				if(!rohc_ir_dyn_packet_crc_ok(walk, largecid, ddata->addcidUsed, profile, ddata->active))
					return(ROHC_ERROR_CRC);
				irdynvar += 2;
			}
			return(ddata->active->profile->decode(state, ddata->active, walk, (isize-(walk-ibuf)), (ddata->largecidUsed ? (1+largecid+irdynvar) : 1+irdynvar), obuf));
		} else
			return(ROHC_ERROR_NO_CONTEXT);
	}
	return(ROHC_ERROR_NO_CONTEXT);
}
예제 #5
0
int ini_file_handler (void* pconfig, const char* section,
        const char* key, const char* value)
{
#define MATCH_SECTION(s) strcmp(section, s) == 0
#define MATCH_KEY(s) strcmp(key,s) == 0
    configuration* config = (configuration*)pconfig;
    int handled = 1;
    if (MATCH_SECTION("listen")) {
        if (MATCH_KEY("ip")) {
            config->listen_ip = strdup(value);
        } else if (MATCH_KEY("port")) {
            config->listen_port = atoi(value);
        } else if (MATCH_KEY("visible")) {
            config->listen_visible = atoi(value);
        } else if (MATCH_KEY("debuginfo")) {
            config->listen_debuginfo = atoi(value);
        } else {
            handled = 0;
        }
    } else if (MATCH_SECTION("gae")) {
        if (MATCH_KEY("appid")) {
            config->gae_appid = strdup(value);
        } else if (MATCH_KEY("password")) {
            config->gae_password = strdup(value);
        } else if (MATCH_KEY("path")) {
            config->gae_path = strdup(value);
        } else if (MATCH_KEY("profile")) {
            config->gae_profile = strdup(value);
        } else if (MATCH_KEY("crlf")) {
            config->gae_crlf = atoi(value);
        } else if (MATCH_KEY("validate")) {
            config->gae_validate = atoi(value);
        } else {
            handled = 0;
        }
    } else if (strstr(section,"google_") == section) {
        profile* p = find_profile(section,config,1);
        if (MATCH_KEY("mode")) {
            p->mode = strdup(value);
        } else if (MATCH_KEY("window")) {
            p->window = atoi(value);
        } else if (MATCH_KEY("hosts")) {
            p->hosts = strdup(value);
        } else if (MATCH_KEY("sites")) {
            p->sites = strdup(value);
        } else if (MATCH_KEY("forcehttps")) {
            p->forcehttps = strdup(value);
        } else if (MATCH_KEY("withgae")) {
            p->withgae = strdup(value);
        } else if (MATCH_KEY("withdns")) {
            p->withdns = strdup(value);
        } else {
            handled = 0;
        }
    } else if (MATCH_SECTION("crlf")) {
        if (MATCH_KEY("enable")) {
            config->crlf_enable = atoi(value);
        } else if (MATCH_KEY("dns")) {
            config->crlf_dns = strdup(value);
        } else if (MATCH_KEY("sites")) {
            config->crlf_sites = strdup(value);
        }
    }
    if (!handled) {
        fprintf(stderr,"Unrecognized section:%s key:%s\r\n", section, key);
    }
    return 1;
}