/** Gets the index of the first occurence of any string of array <i>ss</i> ignoring case. */ public int indexOfIgnoreCase(String[] ss) { Parser par = new Parser(str, index); while (par.hasMore()) { if (par.startsWithIgnoreCase(ss)) return par.getPos(); else par.skipChar(); } return -1; }
/** Gets host of SipURL */ public String getHost() { char[] host_terminators = {':', ';', '?'}; Parser par = new Parser(url); int begin = par.indexOf('@'); // skip "sip:user@" if (begin < 0) begin = 4; // skip "sip:" else begin++; // skip "@" par.setPos(begin); int end = par.indexOf(host_terminators); if (end < 0) return url.substring(begin); else return url.substring(begin, end); }
/** Gets list of tokens (as Vector of Strings). */ public Vector getElements() { Vector elements = new Vector(); Parser par = new Parser(value); char[] delim = {','}; while (par.hasMore()) { String elem = par.getWord(delim).trim(); if (elem != null && elem.length() > 0) elements.addElement(elem); par.skipChar(); } return elements; }
/** Gets port of SipURL; returns -1 if port is not specidfied */ public int getPort() { char[] port_terminators = {';', '?'}; Parser par = new Parser(url, 4); // skip "sip:" int begin = par.indexOf(':'); if (begin < 0) return -1; else { begin++; par.setPos(begin); int end = par.indexOf(port_terminators); if (end < 0) return Integer.parseInt(url.substring(begin)); else return Integer.parseInt(url.substring(begin, end)); } }
/** Loads the database */ public void load() { BufferedReader in = null; changed = false; try { in = new BufferedReader(new FileReader(filename)); } catch (FileNotFoundException e) { System.err.println("WARNING: file \"" + filename + "\" not found: created new empty DB"); return; } String user = null; byte[] key = NULL_ARRAY; while (true) { String line = null; try { line = in.readLine(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } if (line == null) break; Parser par = new Parser(line); if (line.startsWith("#")) continue; if (line.startsWith("user")) { if (user != null) addUser(user, key); user = par.goTo('=').skipChar().getString(); key = NULL_ARRAY; continue; } if (line.startsWith("key")) { key = Base64.decode(par.goTo('=').skipChar().getString()); continue; } if (line.startsWith("passwd")) { key = par.goTo('=').skipChar().getString().getBytes(); continue; } } if (user != null) addUser(user, key); try { in.close(); } catch (Exception e) { e.printStackTrace(); } }
/** Removes specified parameter (if present) */ public void removeParameter(String name) { int index = url.indexOf(';'); if (index < 0) return; Parser par = new Parser(url, index); while (par.hasMore()) { int begin_param = par.getPos(); par.skipChar(); if (par.getWord(SipParser.param_separators).equals(name)) { String top = url.substring(0, begin_param); par.goToSkippingQuoted(';'); String bottom = ""; if (par.hasMore()) bottom = url.substring(par.getPos()); url = top.concat(bottom); return; } par.goTo(';'); } }
/** Gets the begin of next line */ public int indexOfNextLine() { Parser par = new Parser(str, index); par.goToNextLine(); int i = par.getPos(); return (i < str.length()) ? i : -1; }