Browse code

- added seperate installation routine for presence related tables - fix permissions for the SERIAL sequences - fix some SQL bugs introduced by last commit

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1588 689a6050-402a-0410-94f2-e92a70836424

Klaus Darilion authored on 06/02/2007 13:59:18
Showing 1 changed files
... ...
@@ -46,7 +46,9 @@
46 46
 # 2006-10-19  Added address table (bogdan)
47 47
 # 2006-10-27  subscriber table cleanup; some columns are created only if
48 48
 #             serweb is installed (bogdan)
49
-#
49
+# 2007-01-26  added seperate installation routine for presence related tables
50
+#             and fix permissions for the SERIAL sequences.
51
+
50 52
 
51 53
 
52 54
 PATH=$PATH:/usr/local/sbin
... ...
@@ -139,6 +141,7 @@ cat <<EOF
139 139
 usage: $COMMAND create
140 140
        $COMMAND drop   (!!entirely deletes tables)
141 141
        $COMMAND reinit (!!entirely deletes and than re-creates tables
142
+       $COMMAND presence (adds the presence related tables)
142 143
        $COMMAND serweb (adds the SERWEB specific tables)
143 144
 
144 145
  NOTE: the following commands are not tested with postgresql,
... ...
@@ -280,21 +283,60 @@ fi
280 280
 USE_CMD='\connect'
281 281
 GRANT_CMD="CREATE USER $DBRWUSER WITH PASSWORD '$DEFAULT_PW';
282 282
 	CREATE USER $DBROUSER WITH PASSWORD '$RO_PW';
283
-	GRANT ALL PRIVILEGES ON TABLE version, acc, aliases, dbaliases, grp,
284
-		location, missed_calls, subscriber, silo, silo_mid_seq, domain,
285
-		uri, usr_preferences, trusted, re_grp, pdt,
286
-		speed_dial, gw, gw_grp, gw_grp_grp_id_seq, lcr, address,
287
-		sip_trace, domainpolicy TO $DBRWUSER;
288
-	GRANT SELECT ON TABLE version, acc, aliases, dbaliases, grp,
289
-		location, missed_calls, subscriber, silo, silo_mid_seq, domain,
290
-		uri, usr_preferences, trusted, re_grp, pdt,
291
-		speed_dial, gw, gw_grp, gw_grp_grp_id_seq, lcr, address,
292
-		sip_trace, domainpolicy TO $DBROUSER;"
283
+	GRANT ALL PRIVILEGES ON TABLE 
284
+		version, 
285
+		acc, acc_id_seq, 
286
+		address, address_id_seq, 
287
+		aliases, aliases_id_seq,
288
+		dbaliases, dbaliases_id_seq, 
289
+		domain, domain_id_seq, 
290
+		domainpolicy, domainpolicy_id_seq, 
291
+		grp, grp_id_seq,
292
+		gw, gw_id_seq, 
293
+		gw_grp, gw_grp_grp_id_seq, 
294
+		lcr, lcr_id_seq, 
295
+		location, location_id_seq, 
296
+		missed_calls, missed_calls_id_seq, 
297
+		pdt, pdt_id_seq, 
298
+		re_grp, re_grp_id_seq, 
299
+		silo, silo_id_seq, 
300
+		sip_trace, sip_trace_id_seq, 
301
+		speed_dial, speed_dial_id_seq, 
302
+		subscriber, subscriber_id_seq, 
303
+		trusted, trusted_id_seq, 
304
+		uri, uri_id_seq, 
305
+		usr_preferences, usr_preferences_id_seq
306
+		TO $DBRWUSER;
307
+	GRANT SELECT ON TABLE 
308
+		version, 
309
+		acc, 
310
+		address, 
311
+		aliases, 
312
+		dbaliases, 
313
+		domain, 
314
+		domainpolicy, 
315
+		grp, 
316
+		gw, 
317
+		gw_grp, 
318
+		lcr, 
319
+		location, 
320
+		missed_calls, 
321
+		pdt, 
322
+		re_grp, 
323
+		silo, 
324
+		sip_trace, 
325
+		speed_dial, 
326
+		subscriber, 
327
+		trusted, 
328
+		uri, 
329
+		usr_preferences
330
+		TO $DBROUSER;"
293 331
 TIMESTAMP="timestamp NOT NULL DEFAULT NOW()"
294 332
 DATETIME="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DUMMY_DATE'"
295 333
 DATETIMEALIAS="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DEFAULT_ALIASES_EXPIRES'"
296 334
 DATETIMELOCATION="TIMESTAMP WITHOUT TIME ZONE NOT NULL default '$DEFAULT_LOCATION_EXPIRES'"
297 335
 FLOAT="NUMERIC(10,2)"
336
+TINYINT="NUMERIC(4,0)"
298 337
 AUTO_INCREMENT="SERIAL PRIMARY KEY"
299 338
 
300 339
 echo "creating database $1 ..."
... ...
@@ -437,7 +479,7 @@ CREATE TABLE aliases (
437 437
   cflags int NOT NULL default '0',
438 438
   user_agent varchar(255) NOT NULL default '',
439 439
   socket varchar(128) default NULL,
440
-  methods int default NULL,
440
+  methods int default NULL
441 441
 ) $TABLE_TYPE;
442 442
 CREATE INDEX aliases_udc_indx ON aliases ($USERCOL, domain, contact);
443 443
 
... ...
@@ -477,7 +519,7 @@ CREATE TABLE grp (
477 477
 CREATE TABLE re_grp (
478 478
   id $AUTO_INCREMENT,
479 479
   reg_exp varchar(128) NOT NULL default '',
480
-  group_id int NOT NULL default '0',
480
+  group_id int NOT NULL default '0'
481 481
 ) $TABLE_TYPE;
482 482
 CREATE INDEX gid_grp_indx ON re_grp (group_id);
483 483
 
... ...
@@ -491,11 +533,11 @@ CREATE TABLE silo(
491 491
   dst_addr varchar(255) NOT NULL DEFAULT '',
492 492
   $USERCOL varchar(64) NOT NULL DEFAULT '',
493 493
   domain varchar(128) NOT NULL DEFAULT '',
494
-  inc_time INTEGER NOT NULL DEFAULT 0,
495
-  exp_time INTEGER NOT NULL DEFAULT 0,
496
-  snd_time INTEGER NOT NULL DEFAULT 0,
494
+  inc_time int NOT NULL DEFAULT 0,
495
+  exp_time int NOT NULL DEFAULT 0,
496
+  snd_time int NOT NULL DEFAULT 0,
497 497
   ctype varchar(32) NOT NULL DEFAULT 'text/plain',
498
-  body TEXT NOT NULL DEFAULT '',
498
+  body TEXT NOT NULL DEFAULT ''
499 499
 ) $TABLE_TYPE;
500 500
 CREATE INDEX silo_idx ON silo($USERCOL, domain);
501 501
 
... ...
@@ -650,7 +692,7 @@ CREATE TABLE address (
650 650
   id $AUTO_INCREMENT,
651 651
   grp smallint NOT NULL default '0',
652 652
   ip_addr varchar(15) NOT NULL default '',
653
-  mask tinyint NOT NULL default 32,
653
+  mask $TINYINT NOT NULL default 32,
654 654
   port smallint NOT NULL default '0'
655 655
 ) $TABLE_TYPE; 
656 656
 
... ...
@@ -690,6 +732,13 @@ $GRANT_CMD
690 690
 
691 691
 EOF
692 692
 
693
+echo -n "Install presence related tables ?(y/n):"
694
+read INPUT
695
+if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
696
+then
697
+	presence_create $1
698
+fi
699
+
693 700
 echo -n "Install SERWEB tables ?(y/n):"
694 701
 read INPUT
695 702
 if [ "$INPUT" = "y" ] || [ "$INPUT" = "Y" ]
... ...
@@ -700,6 +749,129 @@ fi
700 700
 } # openser_create
701 701
 
702 702
 
703
+presence_create () # pars: <database name>
704
+{
705
+if [ $# -ne 1 ] ; then
706
+	echo "presence_create function takes one param"
707
+	exit 1
708
+fi
709
+
710
+GRANT_PRESENCE_CMD="
711
+	GRANT ALL PRIVILEGES ON TABLE 
712
+		active_watchers, active_watchers_id_seq, 
713
+		presentity, presentity_id_seq, 
714
+		watchers, watchers_id_seq, 
715
+		xcap_xml, xcap_xml_id_seq
716
+		TO $DBRWUSER; 
717
+	GRANT SELECT ON TABLE 
718
+		active_watchers, 
719
+		presentity, 
720
+		watchers, 
721
+		xcap_xml 
722
+		TO $DBROUSER;" 
723
+
724
+echo "creating presence tables into $1 ..."
725
+
726
+sql_query <<EOF
727
+$USE_CMD $1;
728
+
729
+INSERT INTO version VALUES ( 'presentity', '1');
730
+INSERT INTO version VALUES ( 'active_watchers', '1');
731
+INSERT INTO version VALUES ( 'watchers', '1');
732
+INSERT INTO version VALUES ( 'xcap_xml', '1');
733
+
734
+/*
735
+ * Table structure for table 'presentity'
736
+ * 
737
+ * used by presence module
738
+ */
739
+CREATE TABLE presentity (
740
+  id $AUTO_INCREMENT,
741
+  username varchar(64) NOT NULL,
742
+  domain varchar(124) NOT NULL,
743
+  event varchar(64) NOT NULL,
744
+  etag varchar(64) NOT NULL,
745
+  expires int NOT NULL,
746
+  received_time int NOT NULL,
747
+  body text NOT NULL,
748
+  UNIQUE (username, domain, event, etag)
749
+) $TABLE_TYPE;
750
+
751
+
752
+
753
+/*
754
+ * Table structure for table 'active_watchers'
755
+ * 
756
+ * used by presence module
757
+ */
758
+CREATE TABLE active_watchers (
759
+  id $AUTO_INCREMENT,
760
+  to_user varchar(64) NOT NULL,
761
+  to_domain varchar(128) NOT NULL,
762
+  from_user varchar(64) NOT NULL,
763
+  from_domain varchar(128) NOT NULL,
764
+  event varchar(64) NOT NULL default 'presence',
765
+  event_id varchar(64) NOT NULL,
766
+  to_tag varchar(128) NOT NULL,
767
+  from_tag varchar(128) NOT NULL,
768
+  callid varchar(128) NOT NULL,
769
+  cseq int NOT NULL,
770
+  contact varchar(128) NOT NULL,
771
+  record_route varchar(255) NULL,
772
+  expires int NOT NULL,
773
+  status varchar(32) NOT NULL default 'pending',
774
+  version int NOT NULL default '0',
775
+  UNIQUE (from_tag)
776
+) $TABLE_TYPE;
777
+
778
+
779
+
780
+/*
781
+ * Table structure for table 'watchers'
782
+ * 
783
+ * used by presence module
784
+ */
785
+CREATE TABLE watchers (
786
+  id $AUTO_INCREMENT,
787
+  p_user varchar(64) NOT NULL,
788
+  p_domain varchar(128) NOT NULL,
789
+  w_user varchar(64) NOT NULL,
790
+  w_domain varchar(128) NOT NULL,
791
+  subs_status varchar(64) NOT NULL,
792
+  reason varchar(64) NULL,
793
+  inserted_time int NOT NULL,
794
+  UNIQUE (p_user, p_domain, w_user, w_domain)
795
+) $TABLE_TYPE;
796
+
797
+
798
+
799
+/*
800
+ * Table structure for table 'xcap_xml'
801
+ * 
802
+ * used by presence module
803
+ */
804
+CREATE TABLE xcap_xml (
805
+  id $AUTO_INCREMENT,
806
+  username varchar(66) NOT NULL,
807
+  domain varchar(128) NOT NULL,
808
+  xcap text NOT NULL,
809
+  doc_type varchar(64) NOT NULL,
810
+  UNIQUE (username, domain, doc_type)
811
+) $TABLE_TYPE;
812
+
813
+
814
+
815
+$GRANT_PRESENCE_CMD
816
+
817
+EOF
818
+
819
+	if [ $? -eq 0 ] ; then
820
+		echo "...presence tables created"
821
+	fi
822
+
823
+}  # end presence_create
824
+
825
+
703 826
 serweb_create () # pars: <database name>
704 827
 {
705 828
 if [ $# -ne 1 ] ; then
... ...
@@ -708,7 +880,8 @@ if [ $# -ne 1 ] ; then
708 708
 fi
709 709
 
710 710
 GRANT_SERWEB_CMD="
711
-	GRANT ALL PRIVILEGES ON TABLE phonebook, pending, active_sessions,
711
+	GRANT ALL PRIVILEGES ON TABLE phonebook, phonebook_id_seq, 
712
+		pending, pending_id_seq, active_sessions,
712 713
 		server_monitoring, server_monitoring_agg,
713 714
 		usr_preferences_types, admin_privileges to $DBRWUSER; 
714 715
 	GRANT SELECT ON TABLE phonebook, pending, active_sessions,