#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "../global.h"
#include "shared_news_util.h"


void get_mime_type_from_extension(char *extension, char *mime_type)
{

  if (!strcmp (extension, "doc"))
    strncpy (mime_type, "application/msword", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "xls"))
    strncpy (mime_type, "application/msexcel", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "ppt") || !strcmp (extension, "pps"))
    strncpy (mime_type, "application/mspowerpoint", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "txt") || !strcmp (extension, "text") ||
	   !strcmp (extension, "cpp") || !strcmp (extension, "c")
           || !strcmp (extension, "java") )
      strncpy (mime_type, "text/plain", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "htm") || !strcmp (extension, "html"))
    strncpy (mime_type, "text/html", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "xml"))
    strncpy (mime_type, "text/xml", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "gif"))
    strncpy (mime_type, "image/gif", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "wav"))
    strncpy (mime_type, "audio/x-wav", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "au") || !strcmp (extension, "snd"))
    strncpy (mime_type, "audio/basic", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "jpeg") || !strcmp (extension, "jpg")
	   || !strcmp (extension, "jpe"))
    strncpy (mime_type, "image/jpeg", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "tiff") || !strcmp (extension, "tif"))
    strncpy (mime_type, "image/tiff", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "rtf"))
    strncpy (mime_type, "application/rtf", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "pdf"))
    strncpy (mime_type, "application/pdf", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "ra") || !strcmp (extension, "ram")
	   || !strcmp (extension, "rm"))
      strncpy (mime_type, "audio/x-pn-RealAudio", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "qt") || !strcmp (extension, "mov")
	   || !strcmp (extension, "moov"))
    strncpy (mime_type, "video/quicktime", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "xbm"))
    strncpy (mime_type, "image/x-xbitmap", MAX_MIME_TYPE + 1);
  else if (!strcmp (extension, "zip"))
    strncpy (mime_type, "application/zip", MAX_MIME_TYPE + 1);

  else if (!strcmp (extension, "dir"))
    strncpy (mime_type, "application/x-director", MAX_MIME_TYPE + 1);	/* Shockware Director */

  else if (!strcmp (extension, "dxr"))
    strncpy (mime_type, "application/x-director", MAX_MIME_TYPE + 1);	/* Shockware Director */

  else if (!strcmp (extension, "dcr"))
    strncpy (mime_type, "application/x-director", MAX_MIME_TYPE + 1);	/* Shockware Director */

  else if (!strcmp (extension, "asf"))
    strncpy (mime_type, "video/x-ms-asf", MAX_MIME_TYPE + 1);	/* Shockware Director */

  else if (!strcmp(extension, "mp3"))
    strncpy(mime_type, "audio/mpeg", MAX_MIME_TYPE + 1);

  else
    strncpy (mime_type, "application/octet-stream", MAX_MIME_TYPE + 1);




}



void
get_mime_type (const char *source_path, char *original_fname,
	       char *mime_type, int *is_realaudio)
{

  char extension[MAX_FILENAME + 1];

  get_extension (original_fname, extension);   /* shared_news_util.c */
  get_mime_type_from_extension(extension, mime_type);
  
  *is_realaudio = (!strcmp (extension, "ra") || !strcmp (extension, "ram") || !strcmp (extension, "rm"))? 1 : 0;

}
