/* $Id$
 * 
 * This file is a part of Amp2p.  Amp2p is Copyright 2004 Joseph
 * Curtis.  jocurtis@gmail.com
 *
 *
 *  Amp2p is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Amp2p 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
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Amp2p; if not, write to the Free Software Foundation,
 *  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/* A tool to help with debugging (or getting working) amp2p.  Send
 * amp2p messages.
 */

#include <sys/types.h>
#include <unistd.h>          
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <string.h>
#include <malloc.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/time.h> /* need? */
#include <sys/timeb.h>

#include "amp2p.h"

/* Dummy functions because I want them.
 * These are shitting me off!!
 */

int inc_sindex(int i){
  return 0;
}

int create_thread(void * foo, void * bar){
  return 0;
}

void exit_thread(void){
  return;
}

int search_playlist(char * foo, char ** bar){
  return 0;
}


int main(int argc, char * argv[]) {

  /* origin from to type length data
     to type data
  */

  struct msg m;

  if(argc != 4){
    printf("Usage: msgtool to type data\n");
    return(-1);
  }

  m.origin = m.from = local_addr();
  m.to = inet_addr(argv[1]);
  m.type = atoi(argv[2]);
  m.length = strlen(argv[3]);
  m.data = malloc(m.length+1);
  strcpy(m.data, argv[3]);

  //  printf("msgtool: %u, %u, %d, %s\n", ntohl(m.from), ntohl(m.to), m.type, m.data);

  if(m.type==PING){
    m.origin = m.from = inet_addr(argv[1]);
    ping(m.to);
  }
  else{
    send_msg(m);
  }

  return(0); 
}

