
org.mobicents.protocols.mgcp.parser.params.RequestedEventHandler Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.mobicents.protocols.mgcp.parser.params;
import java.text.ParseException;
import java.util.ArrayList;
import org.mobicents.protocols.mgcp.parser.StringFunctions;
import org.mobicents.protocols.mgcp.parser.SplitDetails;
import jain.protocol.ip.mgcp.message.parms.RequestedEvent;
public class RequestedEventHandler
{
public static RequestedEvent decode(byte[] value,int offset,int length) throws ParseException
{
int startIndex=offset;
while(value[startIndex]==StringFunctions.SPACE_BYTE)
startIndex++;
int endIndex=offset+length-1;
while(value[endIndex]==StringFunctions.SPACE_BYTE)
endIndex--;
if(value[startIndex]==StringFunctions.OPEN_BRACKET_BYTE)
throw new ParseException("Unknown value for Requested Event: " + new String(value,offset,length), 0);
if(value[endIndex]==StringFunctions.CLOSE_BRACKET_BYTE)
{
endIndex--;
while(value[endIndex]==StringFunctions.SPACE_BYTE)
endIndex--;
int i=startIndex;
int lastEventNameIndex=startIndex;
for(;i<=endIndex;i++)
if(value[i]==StringFunctions.OPEN_BRACKET_BYTE)
break;
else if(value[i]!=StringFunctions.SPACE_BYTE)
lastEventNameIndex=i;
if(i==endIndex+1)
throw new ParseException("Unknown value for Requested Event: " + new String(value,offset,length), 0);
i++;
while(i<=endIndex && value[i]==StringFunctions.SPACE_BYTE)
i++;
int firstBracketIndex=i;
int middleBracketCloser=i;
int level=1;
for(;i<=endIndex;i++)
{
if(value[i]==StringFunctions.OPEN_BRACKET_BYTE)
{
level++;
middleBracketCloser=i;
}
else if(value[i]==StringFunctions.CLOSE_BRACKET_BYTE)
{
level--;
if(level==0)
break;
middleBracketCloser=i;
}
else if(value[i]!=StringFunctions.SPACE_BYTE)
middleBracketCloser=i;
}
switch(level)
{
case 0:
i++;
for(;i result=new ArrayList();
int currIndex=offset;
int startIndex=offset;
int i=0;
while(value[startIndex]==StringFunctions.SPACE_BYTE && i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy