Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

- First round of refactoring

  • Loading branch information...
decke
decke committed May 10, 2012
1 parent 3ab40c2 commit ed0fdae57b55bce6affc5633f0e6f9d436344813
Showing with 336 additions and 175 deletions.
  1. +1 −1 Makefile
  2. +67 −0 client.h
  3. +51 −0 common.c
  4. +32 −0 common.h
  5. +30 −174 server.c
  6. +37 −0 server.h
  7. +118 −0 stomp.c
@@ -7,7 +7,7 @@ LOCALBASE?=/usr/local
CPPFLAGS=-I${LOCALBASE}/include -g -Wall
LDFLAGS=-L${LOCALBASE}/lib -L${LOCALBASE}/lib/event2

SRC = server.c
SRC = server.c common.c stomp.c
OBJS = ${SRC:.c=.o}

all: redqueue
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2011 Bernhard Froehlich <decke@bluelife.at>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Author's name may not be used endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _CLIENT_H_
#define _CLIENT_H_

#include <sys/queue.h>

/**
* A struct for client specific data, also includes
* pointer to create a list of clients.
*/
struct client {
/* The clients socket. */
int fd;

/* The bufferedevent for this client. */
struct bufferevent *buf_in;

/* The output buffer for this client. */
struct evbuffer *buf_out;

/* Plain request */
char *request;

/* Parsed Headers */
struct evkeyvalq *headers;

TAILQ_ENTRY(client) entries;
};

TAILQ_HEAD(, client) clients;


struct queue {
char *queuename;

TAILQ_HEAD(, client) subscribers;
TAILQ_ENTRY(queue) entries;
};

TAILQ_HEAD(, queue) queues;

#endif /* _CLIENT_H_ */
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2011 Bernhard Froehlich <decke@bluelife.at>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Author's name may not be used endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <string.h>
#include <sys/queue.h>

#include <event2/buffer.h>

#include "common.h"
#include "client.h"

int find_readers(char *queuename, struct evbuffer *evb)
{
struct queue *entry, *tmp_entry;
char buf[MAX_BUF];

*buf = '\0';
for (entry = TAILQ_FIRST(&queues); entry != NULL; entry = tmp_entry) {
tmp_entry = TAILQ_NEXT(entry, entries);
if (strncmp(queuename, entry->queuename, strlen(entry->queuename)) == 0){
evbuffer_add_printf(evb, "queue: %s", queuename);
//TAILQ_REMOVE(&readers, entry, entries);
return 1;
}
}
return 0;
}

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2011 Bernhard Froehlich <decke@bluelife.at>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Author's name may not be used endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _COMMON_H_
#define _COMMON_H_

#define MAX_BUF 16384

#endif /* _COMMON_H_ */

0 comments on commit ed0fdae

Please sign in to comment.
You can’t perform that action at this time.