Thank you Juha for your replies!

>From RFC3856:
A Presence Event Package for the Session Initiation Protocol (SIP)

6.11.  State Agents

   RFC 3265 [2] requires each package to consider the role of state
   agents in the package, and if they are used, to specify how
   authentication and authorization are done.

   State agents are core to this package.  Whenever the PA is not
   co-located with the PUA for the presentity, the PA is acting as a
   state agent.  It collects presence state from the PUA, and aggregates
   it into a presence document.  Because there can be multiple PUA, a
   centralized state agent is needed to perform this aggregation.  That
   is why state agents are fundamental to presence.  Indeed, they have a
   specific term that describes them - a presence server.

Seems the presence server needs to aggregate statuses from different PUAs for the same presentity into a single presence document, if I understand it correctly? Anyway it is not what happens currently with Kamailio 4.0.3 unless I'm missing anything.

Cheers,
Yufei

On 08/10/13 11:00, sr-users-request@lists.sip-router.org wrote:
Message: 2
Date: Mon, 7 Oct 2013 13:31:17 +0300
From: Juha Heinanen <jh@tutpro.com>
To: "Kamailio \(SER\) - Users Mailing List"
	<sr-users@lists.sip-router.org>
Subject: Re: [SR-Users] Presence: Duplicate entry
	'username-domain-presence-*#-OFFLINE-#*' for key 'presentity_idx' when
	multiple clients register using the same credentials
Message-ID: <21074.36213.575240.614265@siika.tutpro.com>
Content-Type: text/plain; charset=us-ascii

Yufei Tao writes:

> When a client (S) subscribes to this contact (username@domain) whose
> credentials are used by two clients, (S) gets NOTIFYs containing
> statuses from either of the username@domain contacts in alternation. But
> all these NOTIFYs have the same call-id.
> 
> I've tried remove the constraint 'CONSTRAINT presentity_idx UNIQUE
> (username, domain, event, etag)' from the presentity table and the
> errors have gone away. Just wondering if this is something that *should*
> be done to cope with the situation where multiple presentities use the
> same credentials.
before knowing how to answer to that, i would like to know what presence
rfcs say about this situation, i.e., is current kamailio presence
implementation somehow broken when an aor (= presentity) has several
active contacts.

should notify give status of both contacts separately or should presence
server try somehow to combine status of the contacts into a single
notify?  what does it mean if one contact tells that it is offline and
another online?  should presence server send only one notify telling
that the presentity is online (since it is if one contact tells so)?

-- juha

On 05/10/13 11:00, sr-users-request@lists.sip-router.org wrote:
Hi

I use kamailio 4.0.3 with presence. I sometimes get these errors:

Oct  4 09:26:24 server /usr/sbin/kamailio[1292]: ERROR: presence
[publish.c:171]: msg_presentity_clean(): Marking presentity
Oct  4 09:26:34 server /usr/sbin/kamailio[1292]: ERROR: db_mysql
[km_dbase.c:122]: db_mysql_submit_query(): driver error on query:
Duplicate entry 'username-domain-presence-*#-OFFLINE-#*' for key
'presentity_idx'
Oct  4 09:26:34 server /usr/sbin/kamailio[1292]: ERROR: <core>
[db_query.c:337]: db_do_update(): error while submitting query
Oct  4 09:26:34 server /usr/sbin/kamailio[1292]: ERROR: presence
[presentity.c:1281]: mark_presentity_for_delete(): unsuccessful sql
update operation

This is when multiple SIP clients are registered using the same
credentials, they each have a presentity entry, with the same username
and domain but different etags, which is fine. But when they expire, the
presentity.etag will be filled with '*#-OFFLINE-#*', and when both
expire at about the same time, kamailio tries to fill both with the same
'*#-OFFLINE-#*' etag. Because presentity table has a 'CONSTRAINT
presentity_idx UNIQUE (username, domain, event, etag)', this gives the
errors.

Should the constraint be removed to cope with this situation?

Thank you!
Yufei

--
Yufei Tao
Red Embedded

This E-mail and any attachments hereto are strictly confidential and intended solely for the addressee. If you are not the intended addressee please notify the sender by return and delete the message.

You must not disclose, forward or copy this E-mail or attachments to any third party without the prior consent of the sender.

Red Embedded Design, Company Number 06688253 Registered in England: The Waterfront, Salts Mill Rd, Saltaire, BD17 7EZ