From owner-p4-projects@FreeBSD.ORG Sun Jun 17 04:15:34 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 06F6016A46E; Sun, 17 Jun 2007 04:15:34 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7D02A16A474 for ; Sun, 17 Jun 2007 04:15:33 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 6CDE313C48A for ; Sun, 17 Jun 2007 04:15:33 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l5H4FXqa022743 for ; Sun, 17 Jun 2007 04:15:33 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l5H4FWvM022733 for perforce@freebsd.org; Sun, 17 Jun 2007 04:15:32 GMT (envelope-from andrew@freebsd.org) Date: Sun, 17 Jun 2007 04:15:32 GMT Message-Id: <200706170415.l5H4FWvM022733@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 121821 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jun 2007 04:15:34 -0000 http://perforce.freebsd.org/chv.cgi?CH=121821 Change 121821 by andrew@andrew_hermies on 2007/06/17 04:15:16 Start to allow calls to be made to the backend. All it does is print the Name, ID and arguments of the call. There is error checking but it dosn't send a response to the front end indicating the error. Affected files ... .. //depot/projects/soc2007/andrew-update/lib/facund_server.c#4 edit Differences ... ==== //depot/projects/soc2007/andrew-update/lib/facund_server.c#4 (text+ko) ==== @@ -25,17 +25,22 @@ * */ +#include #include #include #include #include "facund_connection.h" +#include "facund_object.h" #include "facund_private.h" #define BUF_SIZE 128 +static void facund_server_call(struct facund_conn *, const char *,const char *, + struct facund_object *); static void facund_server_start_tag(void *, const XML_Char *, const XML_Char**); static void facund_server_end_tag(void *, const XML_Char *); +static void facund_server_text(void *, const XML_Char *, int); /* * Waits for a client to connect and send the start message @@ -54,8 +59,9 @@ } XML_SetUserData(conn->parser, conn); - XML_SetStartElementHandler(conn->parser, facund_server_start_tag); - XML_SetEndElementHandler(conn->parser, facund_server_end_tag); + XML_SetElementHandler(conn->parser, facund_server_start_tag, + facund_server_end_tag); + XML_SetCharacterDataHandler(conn->parser, facund_server_text); str = ""; facund_send(conn, str, strlen(str)); @@ -104,17 +110,79 @@ } static void +facund_server_call(struct facund_conn *conn __unused, const char *name, const char *id, struct facund_object *arg) +{ + printf("Call: %s\nID: %s\nArg:\n", name, id); + facund_object_print(arg); + putchar('\n'); +} + +static void facund_server_start_tag(void *data, const XML_Char *name, - const XML_Char **attrs __unused) + const XML_Char **attrs) { struct facund_conn *conn; - //char str[1024]; + char str[1024]; printf("> %s\n", name); conn = data; - //snprintf(str, 1024, "", name); - //facund_send(conn, str, strlen(str)); + if (conn->current_call[0] == '\0' && strcmp(name, "call") == 0) { + unsigned int i; + const char *call_name, *id; + if (attrs == NULL) { + /* TODO: Return an error */ + return; + } + call_name = id = NULL; + for (i = 0; attrs[i] != NULL && attrs[i+1] != NULL; i += 2) { + if (strcmp(attrs[i], "name") == 0) { + if (call_name != NULL) { + /* TODO: Return an error */ + return; + } + call_name = attrs[i]; + } else if (strcmp(attrs[i], "id") == 0) { + if (id != NULL) { + /* TODO: Return an error */ + return; + } + id = attrs[i]; + } else { + /* TODO: Return an error */ + return; + } + } + strlcpy(conn->current_call, call_name, + sizeof(conn->current_call)); + strlcpy(conn->call_id, id, sizeof(conn->call_id)); + } else if (strcmp(name, "data") == 0) { + struct facund_object *obj; + + if (attrs == NULL) { + /* TODO: Return an error */ + return; + } + obj = NULL; + + if (strcmp(attrs[0], "type") == 0 && attrs[1] != NULL && + attrs[2] == NULL) { + obj = facund_object_new_from_typestr(attrs[1]); + } + + if (obj == NULL) { + /* TODO: Return an error */ + return; + } + + if (conn->call_arg != NULL) { + facund_object_array_append(conn->call_arg, obj); + } + conn->call_arg = obj; + } else { + snprintf(str, 1024, "", name); + facund_send(conn, str, strlen(str)); + } } static void @@ -126,11 +194,52 @@ printf("< %s\n", name); conn = data; - if (strcmp(name, "facund-client") == 0) { + if (strcmp(name, "call") == 0) { + facund_server_call(conn, conn->current_call, conn->call_id, + conn->call_arg); + conn->current_call[0] = '\0'; + conn->call_id[0] = '\0'; + /* TODO: Free the call_arg */ + conn->call_arg = NULL; + } else if (strcmp(name, "data") == 0) { + /* + * Set the argument to the item's parent + * if it has one. ie. it's in an array + */ + if (conn->call_arg->obj_parent != NULL) { + conn->call_arg = conn->call_arg->obj_parent; + } + } else if (strcmp(name, "facund-client") == 0) { snprintf(str, 1024, ""); facund_send(conn, str, strlen(str)); - } else { - snprintf(str, 1024, "", name); - facund_send(conn, str, strlen(str)); + } +} + +static void +facund_server_text(void *data, const XML_Char *str, int len) +{ + struct facund_conn *conn; + char *text; + + conn = (struct facund_conn *)data; + if (conn->call_arg == NULL) { + return; + } else if (conn->call_arg->obj_assigned == 1) { + /* TODO: Return an error */ + return; + } else if (conn->call_arg->obj_type == FACUND_ARRAY) { + /* Arrays must not have any text within them */ + /* TODO: Return an error */ + return; + } + + text = malloc((len + 1) * sizeof(char)); + if (text == NULL) { + /* TODO: Return an error */ + return; } + strlcpy(text, str, len + 1); + facund_object_set_from_str(conn->call_arg, text); + + free(text); }