CVS: refdb/src noteshandler.c,1.7,1.8
Markus Hoenicka <[email protected]>
| Newsgroups | gmane.text.refdb.devel |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/refdb/refdb/src
In directory sc8-pr-cvs1:/tmp/cvs-serv1341/src
Modified Files:
noteshandler.c
Log Message:
cater for new xnote:date attribute; remove handling for date, year, month, day elements; use content instead of note element; handle content_type and content_xmllang attributes
Index: noteshandler.c
===================================================================
RCS file: /cvsroot/refdb/refdb/src/noteshandler.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -U2 -r1.7 -r1.8
--- noteshandler.c 4 Dec 2003 00:33:36 -0000 1.7
+++ noteshandler.c 21 Dec 2003 23:10:14 -0000 1.8
@@ -66,4 +66,5 @@
const char* id = NULL;
const char* key = NULL;
+ const char* date = NULL;
char* new_msgpool;
char sql_command[1024] = "";
@@ -104,4 +105,7 @@
/* reset a few variables relevant to entries */
ptr_andata->create_new = 1;
+ *(ptr_andata->date_buffer) = '\0';
+ *(ptr_andata->content_type) = '\0';
+ *(ptr_andata->content_xmllang) = '\0';
/* isolate attributes */
@@ -116,4 +120,7 @@
key = ptr_attr[i+1];
}
+ else if (!strcmp(ptr_attr[i], "date")) {
+ date = ptr_attr[i+1];
+ }
}
@@ -132,7 +139,47 @@
}
- /* set date to current time in case no date is specified */
- time(&the_time);
- strftime(ptr_andata->date_buffer, 12, "%Y-%m-%d", gmtime(&the_time));
+ if (date && strlen(date) == 10) {
+ /* try to parse date according to YYYY-MM-DD */
+ int year;
+ int month;
+ int day;
+ char my_date[11];
+
+ /* get a copy that we can modify. length is checked above */
+ strcpy(my_date, date);
+
+ if (my_date[4] == '-') {
+ my_date[4] = '\0';
+ year = atoi(my_date);
+
+ if (year >= 1900 && year <= 2036) {
+ if (my_date[7] == '-') {
+ my_date[7] = '\0';
+ month = atoi(my_date+5);
+
+ if (month > 0 && month < 13) {
+ day = atoi(my_date+8);
+
+ if (day > 0 && day < 32) {
+ strcpy(ptr_andata->date_buffer, date);
+ strcpy(ptr_andata->year, my_date);
+ }
+ /* else: day out of range */
+ }
+ /* else: month out of range */
+ }
+ /* else: invalid month */
+ }
+ /* else: year out of range */
+ }
+ /* else: invalid year */
+ }
+
+ if (!*(ptr_andata->date_buffer)) {
+ /* set date to current time in case no date is specified */
+ time(&the_time);
+ strftime(ptr_andata->date_buffer, 12, "%Y-%m-%d", gmtime(&the_time));
+ strftime(ptr_andata->year, 5, "%Y", gmtime(&the_time));
+ }
/* see whether id or key already exist in the database */
@@ -292,5 +339,5 @@
/* reset all values in t_note, keep key, use new type */
- sprintf(sql_command, "UPDATE t_note SET note_title=NULL, note_note=NULL WHERE note_id="ULLSPEC, (unsigned long long)(ptr_andata->n_note_id));
+ sprintf(sql_command, "UPDATE t_note SET note_title=NULL, note_content=NULL WHERE note_id="ULLSPEC, (unsigned long long)(ptr_andata->n_note_id));
LOG_PRINT(LOG_DEBUG, sql_command);
@@ -416,11 +463,5 @@
}
}
- else if (!strcmp(el, "date")) {
- *(ptr_andata->year) = '\0';
- *(ptr_andata->month) = '\0';
- *(ptr_andata->day) = '\0';
- *(ptr_andata->date_buffer) = '\0';
- }
- else if (!strcmp(el, "note")) {
+ else if (!strcmp(el, "content")) {
ptr_andata->notepool_len = ELVALUE_LENGTH;
ptr_andata->notepool = (char*)malloc(ELVALUE_LENGTH);
@@ -431,7 +472,18 @@
*(ptr_andata->notepool) = '\0';
}
+
+ for (i = 0; ptr_attr[i]; i += 2) {
+ if (!strcmp(ptr_attr[i], "type")) {
+ strncpy(ptr_andata->content_type, ptr_attr[i+1], 255);
+ ptr_andata->content_type[255] = '\0';
+ }
+ else if (!strcmp(ptr_attr[i], "xml:lang")) {
+ strncpy(ptr_andata->content_xmllang, ptr_attr[i+1], 255);
+ ptr_andata->content_xmllang[255] = '\0';
+ }
+ }
}
else {
- if (is_descendant_of(ptr_andata->ptr_first, "note")) {
+ if (is_descendant_of(ptr_andata->ptr_first, "content")) {
char* new_notepool;
char attribute_buf[EL_LENGTH];
@@ -592,52 +644,4 @@
/* ------------------------------------------------------------ */
- else if (!strcmp(el, "date")) {
- sprintf(ptr_andata->date_buffer, "%s-%s-%s", ptr_andata->year, ptr_andata->month, ptr_andata->day);
-/* result = set_notesdata_field("date", ptr_andata->date_buffer, ptr_andata->conn, ptr_andata->driver, ptr_andata->n_note_id); */
- }
- /* ------------------------------------------------------------ */
- else if (!strcmp(el, "year")) {
- strncpy(ptr_andata->year, (ptr_andata->ptr_first)->ptr_elvalue, 4);
- (ptr_andata->year)[4] = '\0';
- }
- /* ------------------------------------------------------------ */
- else if (!strcmp(el, "month")) {
- size_t len;
-
- len = strlen((ptr_andata->ptr_first)->ptr_elvalue);
-
- if (len > 1) {
- strncpy(ptr_andata->month, (ptr_andata->ptr_first)->ptr_elvalue, 2);
- (ptr_andata->month)[2] = '\0';
- }
- else if (len == 1) {
- (ptr_andata->month)[0] = '0';
- (ptr_andata->month)[1] = (ptr_andata->ptr_first)->ptr_elvalue[0];
- (ptr_andata->month)[2] = '\0';
- }
- else {
- strcpy(ptr_andata->month, "00");
- }
- }
- /* ------------------------------------------------------------ */
- else if (!strcmp(el, "day")) {
- size_t len;
-
- len = strlen((ptr_andata->ptr_first)->ptr_elvalue);
-
- if (len > 1) {
- strncpy(ptr_andata->day, (ptr_andata->ptr_first)->ptr_elvalue, 2);
- (ptr_andata->day)[2] = '\0';
- }
- else if (len == 1) {
- (ptr_andata->day)[0] = '0';
- (ptr_andata->day)[1] = (ptr_andata->ptr_first)->ptr_elvalue[1];
- (ptr_andata->day)[2] = '\0';
- }
- else {
- strcpy(ptr_andata->day, "00");
- }
- }
- /* ------------------------------------------------------------ */
else if (!strcmp(el, "link") && ptr_andata->replace_note != 2) {
char* type;
@@ -664,10 +668,10 @@
}
/* ------------------------------------------------------------ */
- else if (!strcmp(el, "note")) {
+ else if (!strcmp(el, "content")) {
if (ptr_andata->ptr_first->ptr_elvalue && *ptr_andata->ptr_first->ptr_elvalue) {
- result = set_notesdata_field("note", ptr_andata->ptr_first->ptr_elvalue, ptr_andata->conn, ptr_andata->driver, ptr_andata->n_note_id);
+ result = set_notesdata_field("content", ptr_andata->ptr_first->ptr_elvalue, ptr_andata->conn, ptr_andata->driver, ptr_andata->n_note_id);
}
else {
- result = set_notesdata_field("note", ptr_andata->notepool, ptr_andata->conn, ptr_andata->driver, ptr_andata->n_note_id);
+ result = set_notesdata_field("content", ptr_andata->notepool, ptr_andata->conn, ptr_andata->driver, ptr_andata->n_note_id);
free(ptr_andata->notepool);
ptr_andata->notepool = NULL;
@@ -687,6 +691,6 @@
}
else if (result == 2) {
- LOG_PRINT(LOG_WARNING, "update N1 failed");
- if ((new_msgpool = mstrcat(ptr_andata->msgpool, "update N1 failed\n", &(ptr_andata->msgpool_len), 0)) == NULL) {
+ LOG_PRINT(LOG_WARNING, "update note failed");
+ if ((new_msgpool = mstrcat(ptr_andata->msgpool, "update note failed\n", &(ptr_andata->msgpool_len), 0)) == NULL) {
(ptr_andata->nmem_error)++;
return;
@@ -699,4 +703,36 @@
}
/* else: all fine */
+
+ if (*(ptr_andata->content_type)) {
+ result = set_notesdata_field("content_type", ptr_andata->content_type, ptr_andata->conn, ptr_andata->driver, ptr_andata->n_note_id);
+
+ if (result == 1) {
+ if ((new_msgpool = mstrcat(ptr_andata->msgpool, outomem_n.text, &(ptr_andata->msgpool_len), 0)) == NULL) {
+ (ptr_andata->nmem_error)++;
+ return;
+ }
+ else {
+ ptr_andata->msgpool = new_msgpool;
+ }
+ (ptr_andata->ndb_error)++;
+ return;
+ }
+ }
+
+ if (*(ptr_andata->content_xmllang)) {
+ result = set_notesdata_field("content_xmllang", ptr_andata->content_xmllang, ptr_andata->conn, ptr_andata->driver, ptr_andata->n_note_id);
+
+ if (result == 1) {
+ if ((new_msgpool = mstrcat(ptr_andata->msgpool, outomem_n.text, &(ptr_andata->msgpool_len), 0)) == NULL) {
+ (ptr_andata->nmem_error)++;
+ return;
+ }
+ else {
+ ptr_andata->msgpool = new_msgpool;
+ }
+ (ptr_andata->ndb_error)++;
+ return;
+ }
+ }
}
@@ -845,5 +881,5 @@
}
else {
- if (is_descendant_of(ptr_andata->ptr_first, "note")) {
+ if (is_descendant_of(ptr_andata->ptr_first, "content")) {
char* new_notepool;
new_notepool = mstrcat(ptr_andata->notepool, (ptr_andata->ptr_first)->ptr_elvalue, &(ptr_andata->notepool_len), 0);
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click