Пример #1
0
static void cpl_remove(rpc_t* rpc, void* c)
{
	char* user;
	int user_len;

	DBG("DEBUG:cpl-c:cpl_remove: \"REMOVE_CPL\" FIFO command received!\n");

	if (rpc->scan(c, "s", &user) < 1) {
		rpc->fault(c, 400, "Username parameter not found");
		return;
	}
	user_len = strlen(user);

	/* check user+host */
	if (check_userhost( user, user+user_len)!=0) {
		LOG(L_ERR,"ERROR:cpl-c:cpl_remove: invalid user@host [%.*s]\n",
		    user_len,user);
		rpc->fault(c, 400, "Bad user@host: '%s'", user);
		return;
	}
	
	if (rmv_from_db(user)!=1) {
		rpc->fault(c, 400, "Error while removing CPL script of %s from database", user);
		return;
	}
}
Пример #2
0
static inline int do_script_action(struct sip_msg *msg, int action)
{
	str  body = {0,0};
	str  bin  = {0,0};
	str  log  = {0,0};
	str  username = {0,0};
	str  domain   = {0,0};

	if ( get_body(msg, &body)!=0 ) {
		LM_ERR("failed to look for body!\n");
		goto error;
	}

	/* get the user name */
	if (get_dest_user( msg, &username, &domain)==-1)
		goto error;

	/* we have the script and the user */
	switch (action) {
		case STORE_SCRIPT :
			/* check the len -> it must not be 0 */
			if (body.len==0) {
				LM_ERR("0 content-len found for store\n");
				goto error_1;
			}
			/* now compile the script and place it into database */
			/* get the binary coding for the XML file */
			if ( encodeCPL( &body, &bin, &log)!=1) {
				cpl_err = &bad_cpl;
				goto error_1;
			}

			/* write both the XML and binary formats into database */
			if (write_to_db( &username, cpl_env.use_domain?&domain:0,
			&body,&bin)!=1) {
				cpl_err = &intern_err;
				goto error_1;
			}
			break;
		case REMOVE_SCRIPT:
			/* check the len -> it must be 0 */
			if (body.len!=0) {
				LM_ERR("non-0 content-len found for remove\n");
				goto error_1;
			}
			/* remove the script for the user */
			if (rmv_from_db( &username, cpl_env.use_domain?&domain:0)!=1) {
				cpl_err = &intern_err;
				goto error_1;
			}
			break;
	}

	if (log.s) pkg_free( log.s );
	return 0;
error_1:
	if (log.s) pkg_free( log.s );
error:
	return -1;
}
Пример #3
0
struct mi_root * mi_cpl_remove(struct mi_root *cmd_tree, void *param)
{
	struct mi_node *cmd;
	struct sip_uri uri;
	str user;

	LM_DBG("\"REMOVE_CPL\" MI command received!\n");
	cmd = &cmd_tree->node;

	/* check if there is only one parameter*/
	if(!(cmd->kids && cmd->kids->next== NULL))
		return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);

	user = cmd->kids->value;

	/* check user+host */
	if (parse_uri( user.s, user.len, &uri)!=0){
		LM_ERR("invalid SIP uri [%.*s]\n",
			user.len,user.s);
		return init_mi_tree( 400, USRHOST_ERR_S, USRHOST_ERR_LEN );
	}
	LM_DBG("user@host=%.*s@%.*s\n",
		uri.user.len,uri.user.s,uri.host.len,uri.host.s);

	if (rmv_from_db( &uri.user, cpl_env.use_domain?&uri.host:0)!=1)
		return init_mi_tree( 500, DB_RMV_ERR_S, DB_RMV_ERR_LEN );

	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
}
Пример #4
0
static inline int do_script_action(struct sip_msg *msg, int action)
{
	str  body = {0,0};
	str  bin  = {0,0};
	str  log  = {0,0};
	str  username = {0,0};
	str  domain   = {0,0};

	/* content-length (if present) */
	if ( !msg->content_length &&
	((parse_headers(msg,HDR_CONTENTLENGTH_F,0)==-1)||!msg->content_length)) {
		LM_ERR("no Content-Length hdr found!\n");
		goto error;
	}
	body.len = get_content_length( msg );

	/* get the user name */
	if (get_dest_user( msg, &username, &domain)==-1)
		goto error;

	/* we have the script and the user */
	switch (action) {
		case STORE_SCRIPT :
			/* check the len -> it must not be 0 */
			if (body.len==0) {
				LM_ERR("0 content-len found for store\n");
				goto error_1;
			}
			/* get the message's body */
			body.s = get_body( msg );
			if (body.s==0) {
				LM_ERR("cannot extract body from msg!\n");
				goto error_1;
			}
			/* now compile the script and place it into database */
			/* get the binary coding for the XML file */
			if ( encodeCPL( &body, &bin, &log)!=1) {
				cpl_err = &bad_cpl;
				goto error_1;
			}

			/* write both the XML and binary formats into database */
			if (write_to_db( &username, cpl_env.use_domain?&domain:0,
			&body,&bin)!=1) {
				cpl_err = &intern_err;
				goto error_1;
			}
			break;
		case REMOVE_SCRIPT:
			/* check the len -> it must be 0 */
			if (body.len!=0) {
				LM_ERR("non-0 content-len found for remove\n");
				goto error_1;
			}
			/* remove the script for the user */
			if (rmv_from_db( &username, cpl_env.use_domain?&domain:0)!=1) {
				cpl_err = &intern_err;
				goto error_1;
			}
			break;
	}

	if (log.s) pkg_free( log.s );
	return 0;
error_1:
	if (log.s) pkg_free( log.s );
error:
	return -1;
}