From owner-p4-projects@FreeBSD.ORG Sun Jul 1 10:41:29 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 6DA8816A421; Sun, 1 Jul 2007 10:41:29 +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 4489816A400 for ; Sun, 1 Jul 2007 10:41:29 +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 36E5313C44B for ; Sun, 1 Jul 2007 10:41:29 +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 l61AfTgS000606 for ; Sun, 1 Jul 2007 10:41:29 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l61AfSqJ000594 for perforce@freebsd.org; Sun, 1 Jul 2007 10:41:28 GMT (envelope-from andrew@freebsd.org) Date: Sun, 1 Jul 2007 10:41:28 GMT Message-Id: <200707011041.l61AfSqJ000594@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 122632 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, 01 Jul 2007 10:41:29 -0000 http://perforce.freebsd.org/chv.cgi?CH=122632 Change 122632 by andrew@andrew_hermies on 2007/07/01 10:41:23 Start to give the error responses a number based on their type Use the new facund_response_code in facund_response_new Add facund_response_set_id to set the id of the call this response is for Handle the case when the response has no id set Affected files ... .. //depot/projects/soc2007/andrew-update/lib/facund_response.c#2 edit .. //depot/projects/soc2007/andrew-update/lib/facund_response.h#2 edit Differences ... ==== //depot/projects/soc2007/andrew-update/lib/facund_response.c#2 (text+ko) ==== @@ -35,7 +35,7 @@ struct facund_response { char *resp_id; /* The id of the call */ - int resp_code; /* The return code of the response. + facund_response_code resp_code; /* The return code of the response. * 0=good, not 0=bad */ char *resp_msg; /* The error message or NULL * for the default */ @@ -48,8 +48,8 @@ * Creates a new response object to send to the client */ struct facund_response * -facund_response_new(const char *id, int code, const char *message, - struct facund_object *obj) +facund_response_new(const char *id, facund_response_code code, + const char *message, struct facund_object *obj) { struct facund_response *resp; @@ -57,7 +57,9 @@ if (resp == NULL) return NULL; - resp->resp_id = strdup(id); + if (id != NULL) { + resp->resp_id = strdup(id); + } resp->resp_code = code; resp->resp_msg = strdup(message); resp->resp_return = obj; @@ -69,6 +71,16 @@ return resp; } +int +facund_response_set_id(struct facund_response *resp, const char *id) +{ + if (resp == NULL || id == NULL) { + return -1; + } + + return -1; +} + /* * Gets a string to send to the client */ @@ -80,11 +92,22 @@ if (resp->resp_string == NULL) { const char *data; + char *str; data = facund_object_xml_string(resp->resp_return); - asprintf(&resp->resp_string, "%s", resp->resp_id, - resp->resp_code, resp->resp_msg, (data != NULL ? data :"")); + asprintf(&resp->resp_string, "resp_id != NULL) { + str = resp->resp_string; + asprintf(&resp->resp_string, "%s id=\"%s\"", str, + resp->resp_id); + free(str); + } + str = resp->resp_string; + asprintf(&resp->resp_string, "%s code=\"%d\" message=\"%s\">" + "%s", str, resp->resp_code, resp->resp_msg, + (data != NULL ? data :"")); + free(str); } return resp->resp_string; } ==== //depot/projects/soc2007/andrew-update/lib/facund_response.h#2 (text+ko) ==== @@ -28,11 +28,31 @@ #ifndef FACUND_RESPONSE_H #define FACUND_RESPONSE_H +typedef enum _facund_response_code { + RESP_GOOD = 0, + + RESP_UNKNOWN_ELEMENT = 100, /* The element is unknown */ + RESP_WRONG_CHILD_ELEMENT, /* The element can't be here */ + + RESP_UNKNOWN_ATTRIBUTE = 200, + RESP_NO_ATTRIBUTE, + RESP_REPEATED_ATTRIBUTE, + + RESP_UNKNOWN_CALL = 300, /* There is no call with this name */ + + /* These are used in the data elements */ + RESP_EMPTY_VALUE = 400, /* The data had no value */ + RESP_INCORECT_DATA, /* The data has incorrectly + * formatted data */ +} facund_response_code; + struct facund_response; struct facund_object; -struct facund_response *facund_response_new(const char *, int, const char *, - struct facund_object *); +struct facund_response *facund_response_new(const char *, facund_response_code, + const char *, struct facund_object *); +int facund_response_set_id(struct facund_response *, + const char *); const char *facund_response_string(struct facund_response *); void facund_response_free(struct facund_response *);