Android Open Source - shareplay Server






From Project

Back to project page shareplay.

License

The source code is released under:

Copyright (c) 2014, Benjamin Damer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project shareplay listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.afqa123.shareplay.impl;
/*from ww w  . jav  a2s.c o  m*/
import java.net.Inet4Address;
import java.util.Date;
import java.util.Map;

import javax.jmdns.ServiceInfo;

import android.database.Cursor;

import com.afqa123.shareplay.common.Base64;
import com.afqa123.shareplay.common.DBHelper;

public class Server {

  public static final String FLAG_DMAP_VERSION = "DMAP Version";
  public static final String FLAG_DAAP_VERSION = "DAAP Version";
  public static final String FLAG_AUTHENTICATION = "Authentication";
  public static final String FLAG_LOGIN_REQUIRED = "Login Required";
  public static final String FLAG_TIMEOUT_INTERVAL = "Timeout Interval";
  public static final String FLAG_AUTO_LOGOUT = "Auto Logout";
  public static final String FLAG_UPDATE = "Update";
  public static final String FLAG_PERSISTENT_IDS = "Persistent IDs";
  public static final String FLAG_EXTENSIONS = "Extensions";
  public static final String FLAG_BROWSING = "Browsing";
  public static final String FLAG_QUERIES = "Queries";
  public static final String FLAG_INDEXING = "Indexing";
  public static final String FLAG_RESOLVE = "Resolve";
  
  private Long _id;
  private String _name;
  private String _address;
  private String _host;
  private int _port;
  private int _revision;
  private boolean _online;
  private Date _lastDiscovered;
  private int _databaseCount;
  private boolean _stale;
  private String _passwordHash;
  private Map<String,Object> _flags;
  
  public Server() {

  }
  
  public static Server createFromCursor(final Cursor c) {
    Server result = new Server();
    
    result._id = c.getLong(c.getColumnIndex(DBHelper.COL_ID));
    result._name = c.getString(c.getColumnIndex(DBHelper.COL_NAME));
    result._address = c.getString(c.getColumnIndex(DBHelper.COL_ADDRESS));
    result._host = c.getString(c.getColumnIndex(DBHelper.COL_HOST));
    result._port = c.getInt(c.getColumnIndex(DBHelper.COL_PORT));
    result._revision = c.getInt(c.getColumnIndex(DBHelper.COL_REVISION));
    result._lastDiscovered = DBHelper.DB2Date(c.getString(c.getColumnIndex(DBHelper.COL_DISCOVERED)));
    result._passwordHash = c.getString(c.getColumnIndex(DBHelper.COL_PASSWORD_HASH));
    
    return result;
  }
  
  public static Server createFromInfo(final ServiceInfo info) {
    Server result = new Server();
    
    result._name = info.getName();
    result._host = info.getServer();
    
    Inet4Address a[] = info.getInet4Addresses();
    result._address = a[0].toString();
    // clean up address
    if (result._address.startsWith("/")) {
      result._address = result._address.substring(1);
    }
    result._port = info.getPort();
    result._lastDiscovered = new Date();
    result._online = true;
      
    return result;
  }
  
  public Long getId() {
    return _id;
  }
  
  public void setId(final Long id) {
    _id = id;
  }
  
  public String getName() {
    return _name;
  }

  public void setName(final String name) {
    _name = name;
  }

  public String getAddress() {
    return _address;
  }
  
  public void setAddress(final String address) {
    _address = address;
  }
  
  public String getHost() {
    return _host;
  }

  public void setHost(final String host) {
    _host = host;
  }

  public int getPort() {
    return _port;
  }

  public void setPort(final int port) {
    _port = port;
  }

  public int getRevision() {
    return _revision;
  }
  
  public void setRevision(final int revision) {
    _stale = (revision > _revision);
    this._revision = revision;
  }

  public boolean isOnline() {
    return _online;
  }
  
  public void setOnline(final boolean online) {
    _online = online;    
  }
  
  public Date getLastDiscovered() {
    return _lastDiscovered;
  }
  
  public void setLastDiscovered(final Date lastDiscovered) {
    _lastDiscovered = lastDiscovered;
  }
  
  public Map<String, Object> getFlags() {
    return _flags;
  }

  public void setFlags(Map<String, Object> flags) {
    _flags = flags;
  }

  public int getDatabaseCount() {
    return _databaseCount;
  }

  public void setDatabaseCount(final int databaseCount) {
    _databaseCount = databaseCount;
  }

  public boolean isStale() {
    return _stale;
  }
  
  public void setStale(boolean stale) {
    _stale = stale;
  }
  
  @Override
  public String toString() {
    return "http://" + _host + ":" + _port;
  }
  
  @Override
  public boolean equals(Object o) {
    if (!(o instanceof Server))
      return false;

    if (o == this)
      return true;

    Server s = (Server)o;
    if (!_name.equals(s.getName()) ||
      !_host.equals(s.getHost())) 
      return false;
    
    return true;
  }
  
  public boolean requiresAuthorization() {
    if (_flags != null && _flags.containsKey(FLAG_AUTHENTICATION)) {
      return (Boolean)_flags.get(FLAG_AUTHENTICATION);
    }
    
    return false;
  }
  
  public String getPasswordHash() {
    return _passwordHash;
  }
  
  public void setPasswordHash(final String passwordHash) {
    _passwordHash = passwordHash;
  }

  public void setPassword(final String password) {
    if (password == null || password.trim().length() == 0) {
      _passwordHash = null;
    } else {
      // This is actually username:password, but DAAP ignores the username
      final String auth = ":" + password;
      _passwordHash = Base64.encodeBytes(auth.getBytes());
    }
  }
}




Java Source Code List

com.afqa123.log.DefaultLogger.java
com.afqa123.log.FileLogger.java
com.afqa123.log.LoggerFactory.java
com.afqa123.log.Logger.java
com.afqa123.log.NullLogger.java
com.afqa123.shareplay.DialogFactory.java
com.afqa123.shareplay.MediaPlayerService.java
com.afqa123.shareplay.SelectionActivity.java
com.afqa123.shareplay.SharePlayActivity.java
com.afqa123.shareplay.common.AuthorizationException.java
com.afqa123.shareplay.common.Base64.java
com.afqa123.shareplay.common.Constants.java
com.afqa123.shareplay.common.CustomFeedback.java
com.afqa123.shareplay.common.DAAPException.java
com.afqa123.shareplay.common.DBHelper.java
com.afqa123.shareplay.common.Feedback.java
com.afqa123.shareplay.common.Filename.java
com.afqa123.shareplay.common.ListWrapper.java
com.afqa123.shareplay.common.StoppableThread.java
com.afqa123.shareplay.common.StreamProxy.java
com.afqa123.shareplay.data.ContentCode.java
com.afqa123.shareplay.data.Item.java
com.afqa123.shareplay.data.Playlist.java
com.afqa123.shareplay.impl.Client.java
com.afqa123.shareplay.impl.DatabaseCatalog.java
com.afqa123.shareplay.impl.ServerProvider.java
com.afqa123.shareplay.impl.Server.java
com.afqa123.shareplay.interfaces.Catalog.java
com.afqa123.shareplay.interfaces.IClient.java
com.afqa123.shareplay.interfaces.IServerProvider.java