The very start of a small framework for social.
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Wed, 17 Jul 2013 21:14:18 +0000 (18:14 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Wed, 17 Jul 2013 21:14:18 +0000 (18:14 -0300)
Please share!

21 files changed:
AUTHORS [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
configure.ac [new file with mode: 0644]
include/sgp/channel.h [new file with mode: 0644]
include/sgp/ctx.h [new file with mode: 0644]
include/sgp/friend.h [new file with mode: 0644]
include/sgp/group.h [new file with mode: 0644]
include/sgp/msg.h [new file with mode: 0644]
include/sgp/send.h [new file with mode: 0644]
include/sgp/share.h [new file with mode: 0644]
src/Makefile.am [new file with mode: 0644]
src/channel.c [new file with mode: 0644]
src/friend.c [new file with mode: 0644]
src/group.c [new file with mode: 0644]
src/main.c [new file with mode: 0644]
src/msg.c [new file with mode: 0644]
src/send.c [new file with mode: 0644]
src/share.c [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..af437a6
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = src
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..c649e14
--- /dev/null
@@ -0,0 +1,6 @@
+AC_INIT(sgp,0.1,cascardo@cascardo.info)
+AM_INIT_AUTOMAKE(AC_PACKAGE_NAME,AC_PACKAGE_VERSION)
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_OUTPUT(Makefile)
+AC_OUTPUT(src/Makefile)
diff --git a/include/sgp/channel.h b/include/sgp/channel.h
new file mode 100644 (file)
index 0000000..8fe64c8
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _SGP_CHANNEL_H
+#define _SGP_CHANNEL_H
+
+#include <sgp/msg.h>
+
+struct sgp_channel;
+
+int sgp_channel_send(struct sgp_channel *, struct sgp_msg *);
+
+#endif
diff --git a/include/sgp/ctx.h b/include/sgp/ctx.h
new file mode 100644 (file)
index 0000000..2bb7f2c
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _SGP_CTX_H
+#define _SGP_CTX_H
+
+struct sgp_ctx;
+
+#endif
diff --git a/include/sgp/friend.h b/include/sgp/friend.h
new file mode 100644 (file)
index 0000000..7087f48
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _SGP_FRIEND_H
+#define _SGP_FRIEND_H
+
+#include <sgp/channel.h>
+
+struct sgp_friend;
+
+struct sgp_friend * sgp_friend_new(char *);
+
+struct sgp_channel * sgp_friend_get_channel(struct sgp_friend *);
+
+#endif
diff --git a/include/sgp/group.h b/include/sgp/group.h
new file mode 100644 (file)
index 0000000..26f940a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _SGP_GROUP_H
+#define _SGP_GROUP_H
+
+#include <stdlib.h> /* for NULL */
+#include <sgp/friend.h>
+
+struct sgp_group;
+
+struct sgp_group * sgp_group_new();
+int sgp_group_add_friend(struct sgp_group *, struct sgp_friend *);
+
+#define sgp_foreach_friend(group, friend, pfriend) \
+       for (pfriend = sgp_group_first(group), friend = pfriend ? *pfriend : NULL; \
+               pfriend != NULL; \
+               pfriend = sgp_group_next(group, pfriend), friend = pfriend ? *pfriend : NULL)
+
+struct sgp_friend ** sgp_group_first(struct sgp_group *);
+struct sgp_friend ** sgp_group_next(struct sgp_group *, struct sgp_friend **);
+
+#endif
diff --git a/include/sgp/msg.h b/include/sgp/msg.h
new file mode 100644 (file)
index 0000000..1071ee0
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _SGP_MSG_H
+#define _SGP_MSG_H
+
+struct sgp_msg;
+
+struct sgp_msg * sgp_msg_new(char *);
+void sgp_msg_destroy(struct sgp_msg *);
+
+#endif
diff --git a/include/sgp/send.h b/include/sgp/send.h
new file mode 100644 (file)
index 0000000..27520f2
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _SGP_SEND_H
+#define _SGP_SEND_H
+
+#include <sgp/friend.h>
+#include <sgp/msg.h>
+
+int sgp_send(struct sgp_friend *, struct sgp_msg *);
+
+#endif
diff --git a/include/sgp/share.h b/include/sgp/share.h
new file mode 100644 (file)
index 0000000..33c4c2a
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _SGP_SHARE_H
+#define _SGP_SHARE_H
+
+#include <sgp/group.h>
+#include <sgp/msg.h>
+
+int sgp_share(struct sgp_group *, struct sgp_msg *);
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..f41ffa1
--- /dev/null
@@ -0,0 +1,3 @@
+bin_PROGRAMS = sgp
+sgp_SOURCES = main.c channel.c friend.c group.c send.c share.c msg.c
+sgp_CFLAGS = -I../include/
diff --git a/src/channel.c b/src/channel.c
new file mode 100644 (file)
index 0000000..3aec1bf
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sgp/channel.h>
+#include <sgp/msg.h>
+
+struct sgp_channel {
+       int (*send) (void *, struct sgp_msg *);
+       void * data;
+};
+
+/*
+ * Send a message through a channel.
+ */
+int sgp_channel_send(struct sgp_channel *channel, struct sgp_msg *msg)
+{
+       return channel->send(channel->data, msg);
+}
diff --git a/src/friend.c b/src/friend.c
new file mode 100644 (file)
index 0000000..db5c457
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sgp/friend.h>
+#include <sgp/channel.h>
+#include <stdlib.h>
+
+struct sgp_friend {
+       struct sgp_channel *channel;
+};
+
+struct sgp_friend * sgp_friend_new(char *alias)
+{
+       struct sgp_friend *friend;
+       friend = malloc(sizeof(*friend));
+       friend->channel = NULL;
+       return friend;
+}
+
+/*
+ * Get the channel used for communication with a friend.
+ */
+struct sgp_channel * sgp_friend_get_channel(struct sgp_friend *friend)
+{
+       /*
+        * TODO: A friend may have multiple channels for contact. We
+        * should either implement this at the core (at sgp_send, for
+        * example), or create a channel that encapsulates that.
+        */
+       return friend->channel;
+}
diff --git a/src/group.c b/src/group.c
new file mode 100644 (file)
index 0000000..3566557
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sgp/group.h>
+#include <sgp/friend.h>
+#include <stdlib.h>
+
+struct sgp_group {
+       struct sgp_friend **friends;
+       int nr_friends;
+};
+
+struct sgp_group * sgp_group_new()
+{
+       struct sgp_group *group;
+       group = malloc(sizeof(*group));
+       group->nr_friends = 0;
+       group->friends = NULL;
+       return group;
+}
+
+int sgp_group_add_friend(struct sgp_group *group, struct sgp_friend *friend)
+{
+       return 0;
+}
+
+/*
+ * Get the channel used for communication with a friend.
+ */
+struct sgp_friend ** sgp_group_first(struct sgp_group *group)
+{
+       if (group->nr_friends > 0)
+               return &group->friends[0];
+       return NULL;
+}
+
+struct sgp_friend ** sgp_group_next(struct sgp_group *group,
+                                       struct sgp_friend **friend)
+{
+       int n;
+       n = (friend - group->friends) / sizeof(*friend);
+       if (group->nr_friends > n + 1)
+               return &group->friends[n+1];
+       return NULL;
+}
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..9ce1fb7
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sgp/share.h>
+
+int main(int argc, char **argv)
+{
+       struct sgp_group *group;
+       struct sgp_msg *msg;
+       struct sgp_friend *friend;
+       /* TODO: access a database here? */
+       group = sgp_group_new();
+       friend = sgp_friend_new("Thadeu Cascardo");
+       msg = sgp_msg_new("New message for you");
+       sgp_group_add_friend(group, friend);
+       sgp_share(group, msg);
+       return 0;
+}
diff --git a/src/msg.c b/src/msg.c
new file mode 100644 (file)
index 0000000..9a04735
--- /dev/null
+++ b/src/msg.c
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sgp/msg.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct sgp_msg {
+       char *subject;
+};
+
+struct sgp_msg * sgp_msg_new(char *subject)
+{
+       struct sgp_msg *msg;
+       msg = malloc(sizeof(*msg));
+       msg->subject = strdup(subject);
+       return msg;
+}
+
+void sgp_msg_destroy(struct sgp_msg *msg)
+{
+       free(msg->subject);
+       free(msg);
+}
diff --git a/src/send.c b/src/send.c
new file mode 100644 (file)
index 0000000..59ad6e1
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sgp/send.h>
+#include <sgp/friend.h>
+#include <sgp/msg.h>
+#include <sgp/channel.h>
+#include <errno.h>
+
+/*
+ * Send a message to a friend.
+ */
+int sgp_send(struct sgp_friend *friend, struct sgp_msg *msg)
+{
+       struct sgp_channel *channel;
+       /*
+        * TODO: if we are sharing with a whole group, should we tell
+        * our friend? Cc vs Bcc.
+        */
+       channel = sgp_friend_get_channel(friend);
+       if (!channel)
+               /* FIXME: find a better error structure */
+               return -ENODEV;
+       return sgp_channel_send(channel, msg);
+}
diff --git a/src/share.c b/src/share.c
new file mode 100644 (file)
index 0000000..4fd08cc
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sgp/share.h>
+#include <sgp/group.h>
+#include <sgp/friend.h>
+#include <sgp/msg.h>
+#include <sgp/send.h>
+
+/*
+ * Share message with a group of friends.
+ */
+int sgp_share(struct sgp_group *group, struct sgp_msg *msg)
+{
+       struct sgp_friend *friend;
+       struct sgp_friend **pfriend;
+       sgp_foreach_friend(group, friend, pfriend) {
+               /*
+                * TODO: mark message as sent if successfully sent and
+                * queue for another try if it was not possible.
+                */
+               sgp_send(friend, msg);
+       }
+       return 0;
+}