ContactHeader ch=new ContactHeader(location_service.getUserContactNameAddress(user,url));
ch.setExpires(expires);
v.addElement(ch);
}
}
if (v.size()>0) resp.setContacts(new MultipleHeader(v));
return resp;
}
// else
Vector contacts=msg.getContacts().getHeaders();
int result=200;
Message resp=MessageFactory.createResponse(msg,result,SipResponses.reasonOf(result),null);
ContactHeader contact_0=new ContactHeader((Header)contacts.elementAt(0));
if (contact_0.isStar())
{ printLog("DEBUG: ContactHeader is star",LogLevel.LOW);
Vector resp_contacts=new Vector();
for (Enumeration e=location_service.getUserContactURLs(user); e.hasMoreElements();)
{ String url=(String)(e.nextElement());
NameAddress name_address=location_service.getUserContactNameAddress(user,url);
// update db
location_service.removeUserContact(user,url);
printLog("contact removed: "+url,LogLevel.LOW);
if (exp_secs>0)
{ Date exp_date=new Date(System.currentTimeMillis()+((long)exp_secs)*1000);
location_service.addUserContact(user,name_address,exp_date);
//DateFormat df=new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",Locale.ITALIAN);
//printLog("contact added: "+url+"; expire: "+df.format(location_service.getUserContactExpire(user,url)),LogLevel.LOW);
printLog("contact added: "+url+"; expire: "+DateFormat.formatEEEddMMM(location_service.getUserContactExpirationDate(user,url)),LogLevel.LOW);
}
ContactHeader contact_i=new ContactHeader(name_address.getAddress());
contact_i.setExpires(exp_secs);
resp_contacts.addElement(contact_i);
}
if (resp_contacts.size()>0) resp.setContacts(new MultipleHeader(resp_contacts));
}
else
{ Vector resp_contacts=new Vector();
for (int i=0; i<contacts.size(); i++)
{ ContactHeader contact_i=new ContactHeader((Header)contacts.elementAt(i));
NameAddress name_address=contact_i.getNameAddress();
String url=name_address.getAddress().toString();
int exp_secs_i=exp_secs;
if (contact_i.hasExpires())
{ exp_secs_i=contact_i.getExpires();
}
// limit the expire value
if (exp_secs_i<0) exp_secs_i=0;
else
if (exp_secs_i>server_profile.expires) exp_secs_i=server_profile.expires;
// update db
location_service.removeUserContact(user,url);
if (exp_secs_i>0)
{ Date exp_date=new Date(System.currentTimeMillis()+((long)exp_secs)*1000);
location_service.addUserContact(user,name_address,exp_date);
printLog("registration of user "+user+" updated",LogLevel.HIGH);
}
contact_i.setExpires(exp_secs_i);
resp_contacts.addElement(contact_i);
}
if (resp_contacts.size()>0) resp.setContacts(new MultipleHeader(resp_contacts));
}
location_service.sync();
return resp;
}