--- /dev/null
+SUBDIRS = src
--- /dev/null
+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)
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
--- /dev/null
+bin_PROGRAMS = sgp
+sgp_SOURCES = main.c channel.c friend.c group.c send.c share.c msg.c
+sgp_CFLAGS = -I../include/
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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;
+}