# Functions

`handle_rls_subscription`

  Handle subscription to resource list uri.

  ## Parameters:

  create_error_response (integer)

    If set to 0 error responses are not sent to the client. This may be useful, if used together with PA module.

  This function handles resource list subscription. XCAP document containing the list must be loaded before using one of query function (, ).

  ## handling subscription

      ...
      if (method=="SUBSCRIBE") {
      	if (!t_newtran()) {
      		sl_reply_error();
      	};

      	if (query_rls_services()) {
      		handle_rls_subscription("1");
      	}
      	else {
      		# no such list exists -> process it with PA module
      		handle_subscription("registrar");
      	}
      	break;
      };
      ...

  In this case for every incomming SUBSCRIBE request SER asks for "global resource list". If such list exists, the subscription is processed like resource list subscription.

`is_simple_rls_target`

  Test uri according to given template.

  ## Parameters:

  template (string)

    Template to be compared with To URI.

  Function tries to compare username in To URI with given template. If there are different domains in To and From URIs, the function fails. There can be used "$uid" in template and it is replaced by value returned by get_from_uid.

  In the future should be this function replaced by AVP operations but I was not able to do it with them now...

  ## handling subscription

      ...
      if (method=="SUBSCRIBE") {
      	if (!t_newtran()) {
      		sl_reply_error();
      		break;
      	};

      	if (lookup_domain("From")) {
      		if (lookup_user("From")) {
      			if (is_simple_rls_target("$uid-list")) {
      				# takes From UID and makes XCAP query
      				# for user's list named "default"
      				if (!query_resource_list("default")) {
      					t_reply("500", "XCAP query error");
      					break;
      				}
      				handle_rls_subscription("1");
      				break;
      			}
      		}
      	}
      }
      ...

  In this case if SUBSCRIBE request arrives and From is smith@test-domain.com and To is smith-list@test-domain.com, the function returns true and the subscription is handled like subscription to "user's resource list" (not "global") as written above.

`query_rls_services`

  Get list from global rls-services document.

  Function loads "global resource list" from XCAP server. This list is then processed by RLS module using .

`query_resource_list`

  Get user's resource list.

  ## Parameters:

  list_name (string)

    Name of the requested list. If empty, it loads whole user's resource-lists document as one list.

  Function loads "user's resource list" from XCAP server. This list is then processed by RLS module using .

`have_flat_list`

  Test if a resource list is loaded.

  Function tests if a list was loaded using one of query functions ( or ) and returns 1 if yes and -1 otherwise.