<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE database PUBLIC "-//iptel.org//DTD DBSchema V1.0//EN"
  "http://iptel.org/dbschema/dtd/1.0/dbschema.dtd" [

<!ENTITY % entities SYSTEM "entities.xml">
%entities;

]>

<database xmlns:xi="http://www.w3.org/2001/XInclude">
  <name>ser</name>

  <!-- Accounting related tables -->
  <xi:include href="acc.xml"/>
  <xi:include href="missed_calls.xml"/>

  <!-- Table that stores credentials for digest and serweb authentication -->
  <xi:include href="credentials.xml"/>

  <!-- Attribute types -->
  <xi:include href="attr_types.xml"/>

  <!-- Various attribute tables -->
  <xi:include href="global_attrs.xml"/>
  <xi:include href="domain_attrs.xml"/>
  <xi:include href="user_attrs.xml"/>
  <xi:include href="uri_attrs.xml"/>

  <!-- Multi-domain support -->
  <xi:include href="domain.xml"/>

  <!-- Table containing text files, styles and other files specific for domain (used by serweb) -->
  <xi:include href="domain_settings.xml"/>

  <!-- User location database -->
  <xi:include href="location.xml"/>
  <xi:include href="contact_attrs.xml"/>

  <!-- Permissions module -->
  <xi:include href="trusted.xml"/>
  <xi:include href="ipmatch.xml"/>

  <!-- Table containing phonebook (used by serweb -->
  <xi:include href="phonebook.xml"/>

  <!-- Least Cost Routing related tables -->
  <xi:include href="gw.xml"/>
  <xi:include href="gw_grp.xml"/>
  <xi:include href="lcr.xml"/>

  <xi:include href="grp.xml"/>

  <!-- Instant Messages Scheduled for later delivery -->
  <xi:include href="silo.xml"/>

  <!-- The table mapping SIP URIs to subscribers -->
  <xi:include href="uri.xml"/>

  <!-- Speeddial module -->
  <xi:include href="speed_dial.xml"/>
  <xi:include href="sd_attrs.xml"/>

  <!-- Presence related tables -->
  <xi:include href="presentity.xml"/>
  <xi:include href="presentity_notes.xml"/>
  <xi:include href="presentity_extensions.xml"/>
  <xi:include href="presentity_contact.xml"/>
  <xi:include href="watcherinfo.xml"/>
  <xi:include href="tuple_notes.xml"/>
  <xi:include href="tuple_extensions.xml"/>
  <xi:include href="offline_winfo.xml"/>
  
  <!-- Resource-lists related tables -->
  <xi:include href="rls_subscription.xml"/>
  <xi:include href="rls_vs.xml"/>
  <xi:include href="rls_vs_names.xml"/>

  <xi:include href="i18n.xml"/>

  <xi:include href="pdt.xml"/>

  <xi:include href="cpl.xml"/>

  <!-- Customers -->
  <xi:include href="customers.xml"/>

  <verbatim db="mysql" id="func.active">
	<create>
	  <![CDATA[
drop function if exists active;
create function active (flags int unsigned) returns bool DETERMINISTIC
    return not flags&194;
]]>
	</create>
	<destroy>
	  drop function if exists active;
	</destroy>
  </verbatim>

  <verbatim db="mysql" id="func.canonical">
	<create>
	  <![CDATA[
drop function if exists canonical;
create function canonical (flags int unsigned) returns bool DETERMINISTIC
    return flags&4 and active(flags);
]]>
	</create>
	<destroy>
	  drop function if exists canonical;
	</destroy>
  </verbatim>

  <verbatim db="mysql" id="func.tostr">
	<create>
	  <![CDATA[
drop function if exists tostr;
delimiter //
create function tostr (flags int(10) unsigned) returns varchar(128)
    DETERMINISTIC
begin
    declare tres varchar(128) default "";
    if (flags&1) then 
        set tres = concat(tres, " SER");
    end if;
    if (flags&2) then
        set tres = concat(tres, " DISABLED");
    end if;
    if (flags&4) then
        set tres = concat(tres, " CANON");
    end if;
    if (flags&8) then
        set tres = concat(tres, " TO");
    end if;
    if (flags&16) then
        set tres = concat(tres, " FROM");
    end if;
    if (flags&32) then
        set tres = concat(tres, " SERWEB");
    end if;
    if (flags&64) then
        set tres = concat(tres, " PENDING");
    end if;
    if (flags&128) then
        set tres = concat(tres, " DELETED");
    end if;
    if (flags&256) then
        set tres = concat(tres, " CALLER_DELETED");
    end if;
    if (flags&512) then
        set tres = concat(tres, " CALLEE_DELETED");
    end if;
    if (flags&1024) then
        set tres = concat(tres, " MULTIVALUE");
    end if;
    if (flags&2048) then
        set tres = concat(tres, " FILLONREG");
    end if;
    if (flags&4096) then
        set tres = concat(tres, " REQUIRED");
    end if;
    if (flags&8192) then
        set tres = concat(tres, " DIR");
    end if;
    return ltrim(tres);
end
//
delimiter ;
]]>
	</create>
	<destroy>
	  drop function if exists tostr;
	</destroy>
  </verbatim>

  <!-- Include extra definitions if found, it is not
       an error if they are not present, although it
       would produce a warning
    -->
  <xi:include href="extra.xml" xpointer="xpointer(data/table)">
	<xi:fallback/>
  </xi:include>
</database>
