Date: Sun, 1 Jul 2007 10:41:28 GMT From: Andrew Turner <andrew@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 122632 for review Message-ID: <200707011041.l61AfSqJ000594@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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, "<response id=\"%s\" code=\"%d\" " - "message=\"%s\">%s</response>", resp->resp_id, - resp->resp_code, resp->resp_msg, (data != NULL ? data :"")); + asprintf(&resp->resp_string, "<response"); + + if (resp->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</response>", 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 *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707011041.l61AfSqJ000594>