예제 #1
0
파일: ns.c 프로젝트: Doap/transports
void mt_ns_msg(mpacket mp, session s)
{
    xmlnode msg, oob;
    char *body, *ctype, *ptr;
    /* message body spool*/
    pool p = pool_new();
    spool sp = spool_new(p);      

    if (s->ti->inbox_headlines == 0)
        return;

    ctype = strchr(mt_packet_data(mp,5),':') + 2;
    body = mt_packet_data(mp,mp->count - 1);

    /* this message is a Hotmail inbox notification */
    if ((strncmp(ctype,"text/x-msmsgsinitialemailnotification",37) != 0) &&
        (strncmp(ctype,"text/x-msmsgsemailnotification",30) != 0))
        return;
   
    /* Fede <*****@*****.**> */
    /* cut off the junk at the end */
    if ((ptr = strstr(body,"Inbox-URL")) != NULL) {
       *ptr = '\0';
       spool_add(sp,body);   
    } else {       
       if ((ptr = strstr(body,"From:")) != NULL) {
          char *p = strchr(ptr, '\r');	  
	  *p = '\0';
	  spooler(sp,"Mail from: ", ptr + 6,sp);
	  body = p + 1;
       }
       if ((ptr = strstr(body,"From-Addr:")) != NULL) {
          *strchr(ptr, '\r') = '\0';
	  spooler(sp," <",ptr + 11,">",sp);
       }       
    }
    
    msg = xmlnode_new_tag("message");
    xmlnode_put_attrib(msg,"to",jid_full(s->id));
    xmlnode_put_attrib(msg,"from",s->host);
    xmlnode_put_attrib(msg,"type","headline");

    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"subject"),"Hotmail",-1);
    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),spool_print(sp),-1);

    oob = xmlnode_insert_tag(msg,"x");
    xmlnode_put_attrib(oob,"xmlns","jabber:x:oob");
    xmlnode_insert_cdata(xmlnode_insert_tag(oob,"url"),"http://www.hotmail.com/cgi-bin/folders",-1);
    xmlnode_insert_cdata(xmlnode_insert_tag(oob,"desc"),"Login to your Hotmail e-mail account",-1);

    mt_deliver(s->ti,msg);
   
    pool_free(p);
}
예제 #2
0
파일: xmlnode.c 프로젝트: bcy/muc
static void _xmlnode_tag2str(spool s, xmlnode node, int flag)
{
    xmlnode tmp;

    if(flag==0 || flag==1)
    {
	    spooler(s,"<",xmlnode_get_name(node),s);
	    tmp = xmlnode_get_firstattrib(node);
	    while(tmp) {
	        spooler(s," ",xmlnode_get_name(tmp),"='",strescape(xmlnode_pool(node),xmlnode_get_data(tmp)),"'",s);
	        tmp = xmlnode_get_nextsibling(tmp);
	    }
	    if(flag==0)
	        spool_add(s,"/>");
	    else
	        spool_add(s,">");
    }
    else
    {
	    spooler(s,"</",xmlnode_get_name(node),">",s);
    }
}
예제 #3
0
파일: spooler.c 프로젝트: smartstudy/uwsgi
pid_t spooler_start(struct uwsgi_spooler *uspool) {

    int i;

    pid_t pid = uwsgi_fork("uWSGI spooler");
    if (pid < 0) {
        uwsgi_error("fork()");
        exit(1);
    }
    else if (pid == 0) {
        // USR1 will be used to wake up the spooler
        uwsgi_unix_signal(SIGUSR1, spooler_wakeup);
        uwsgi.mywid = -1;
        uwsgi.mypid = getpid();
        uspool->pid = uwsgi.mypid;
        // avoid race conditions !!!
        uwsgi.i_am_a_spooler = uspool;

        uwsgi_fixup_fds(0, 0, NULL);
        uwsgi_close_all_sockets();

        for (i = 0; i < 256; i++) {
            if (uwsgi.p[i]->post_fork) {
                uwsgi.p[i]->post_fork();
            }
        }

        uwsgi.signal_socket = uwsgi.shared->spooler_signal_pipe[1];

        for (i = 0; i < 256; i++) {
            if (uwsgi.p[i]->spooler_init) {
                uwsgi.p[i]->spooler_init();
            }
        }

        for (i = 0; i < uwsgi.gp_cnt; i++) {
            if (uwsgi.gp[i]->spooler_init) {
                uwsgi.gp[i]->spooler_init();
            }
        }

        spooler(uspool);
    }
    else if (pid > 0) {
        uwsgi_log("spawned the uWSGI spooler on dir %s with pid %d\n", uspool->dir, pid);
    }

    return pid;
}
예제 #4
0
파일: jid.c 프로젝트: named-data/muc
char *jid_full(jid id)
{
    spool s;

    if(id == NULL)
        return NULL;

    /* use cached copy */
    if(id->full != NULL)
        return id->full;

    s = spool_new(id->p);

    if(id->user != NULL)
        spooler(s, id->user,"@",s);

    spool_add(s, id->server);

    if(id->resource != NULL)
        spooler(s, "/",id->resource,s);

    id->full = spool_print(s);
    return id->full;
}
예제 #5
0
파일: spooler.c 프로젝트: chain710/uwsgi
void uwsgi_spooler_run() {
	int i;
	struct uwsgi_spooler *uspool = uwsgi.i_am_a_spooler;
	uwsgi.signal_socket = uwsgi.shared->spooler_signal_pipe[1];

                for (i = 0; i < 256; i++) {
                        if (uwsgi.p[i]->spooler_init) {
                                uwsgi.p[i]->spooler_init();
                        }
                }

                for (i = 0; i < uwsgi.gp_cnt; i++) {
                        if (uwsgi.gp[i]->spooler_init) {
                                uwsgi.gp[i]->spooler_init();
                        }
                }

                spooler(uspool);
}
예제 #6
0
파일: conference_room.c 프로젝트: bcy/muc
void con_room_log_new(cnr room)
{
  char *filename;
  char *curdate;
  char *dirname;
  char datePart[5];
  struct stat fileinfo;
  time_t now = time(NULL);
  int type;
  pool p;
  spool sp;

  if(room == NULL || !room->master->logsEnabled) 
  {
    log_warn(NAME, "[%s] Aborting - NULL room", FZONE);
    return;
  }

  p = pool_heap(1024);
  type = room->logformat;
  dirname = jid_full(room->id);
  sp = spool_new(p);

  if(room->master->logdir)
  {
    spooler(sp, room->master->logdir, "/", dirname, sp);
  }
  else
  {
    spooler(sp, "./", dirname, sp);
  }

  filename = spool_print(sp);

  if(stat(filename,&fileinfo) < 0 && mkdir(filename, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0)
  {
    log_warn(NAME, "[%s] ERR: unable to open log directory >%s<", FZONE, filename);
    return;
  }

  curdate = dateget(now);

  if (room->master->flatLogs) {

    spooler(sp, "/", curdate, sp);

  }
  else {

    strftime(datePart, 5, "%Y", localtime(&now));
    
    spooler(sp, "/", datePart, sp);
    filename = spool_print(sp);
    if(stat(filename,&fileinfo) < 0 && mkdir(filename, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0)
    {
      log_warn(NAME, "[%s] ERR: unable to open log directory >%s<", FZONE, filename);
      return;
    }

    strftime(datePart, 5, "%m", localtime(&now));
    
    spooler(sp, "/", datePart, sp);
    filename = spool_print(sp);
    if(stat(filename,&fileinfo) < 0 && mkdir(filename, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0)
    {
      log_warn(NAME, "[%s] ERR: unable to open log directory >%s<", FZONE, filename);
      return;
    }

    strftime(datePart, 5, "%d", localtime(&now));
    
    spooler(sp, "/", datePart, sp);


  }

  if(type == LOG_XML)
    spool_add(sp, ".xml");
  else if(type == LOG_XHTML)
    spool_add(sp, ".html");
  else
    spool_add(sp, ".txt");


  filename = spool_print(sp);

  if(stat(filename,&fileinfo) < 0)
  {
    log_debug(NAME, "[%s] New logfile >%s<", FZONE, filename);

    room->logfile = fopen(filename, "a");

    if(type == LOG_XHTML && room->logfile != NULL)
    {
      fprintf(room->logfile, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n<title>Logs for %s, %s</title>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n", jid_full(room->id), curdate);
     if (room->master->stylesheet!=NULL)
       fprintf(room->logfile, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n",room->master->stylesheet);
     fprintf(room->logfile, "</head><body>\n<p class=\"logs\">\n");

      fflush(room->logfile);
    }
  }
  else
  {
    room->logfile = fopen(filename, "a");
  }


  if(room->logfile == NULL)
    log_warn(NAME, "[%s] ERR: unable to open log file >%s<", FZONE, filename);
  else
    log_debug(NAME, "[%s] Opened logfile >%s<", FZONE, filename);

  pool_free(p);
  free(curdate);
  return;
}