• R/O
  • SSH
  • HTTPS

bchan: Commit


Commit MetaInfo

Revision669 (tree)
Time2015-03-19 01:57:52
Authorornse01

Log Message

replace form urlencode implemantation to bchanf common library's.

Change Summary

Incremental Difference

--- bchan/trunk/src/test_postres.c (revision 668)
+++ bchan/trunk/src/test_postres.c (revision 669)
@@ -1,7 +1,7 @@
11 /*
22 * test_postres.c
33 *
4- * Copyright (c) 2010-2012 project bchan
4+ * Copyright (c) 2010-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -504,135 +504,6 @@
504504 return test_genrequestbody_checkdata_update(testdata1, testdata1_len, testdata2, testdata2_len, board, strlen(board), thread, strlen(thread), time, expected, strlen(expected));
505505 }
506506
507-LOCAL UNITTEST_RESULT test_gennamemail_checkdata(UB *testdata, W testdata_len, UB *expected_name, W expected_name_len, UB *expected_mail, W expected_mail_len)
508-{
509- LINK test_lnk;
510- W fd, err;
511- postresdata_t *postres;
512- UB *name = NULL, *mail = NULL;
513- W name_len = 0, mail_len = 0;
514- UNITTEST_RESULT result;
515-
516- fd = test_postres_util_gen_file(&test_lnk);
517- if (fd < 0) {
518- return UNITTEST_RESULT_FAIL;
519- }
520- err = ins_rec(fd, testdata, testdata_len, RT_TADDATA, 0, 0);
521- if (err < 0) {
522- cls_fil(fd);
523- del_fil(NULL, &test_lnk, 0);
524- return UNITTEST_RESULT_FAIL;
525- }
526- cls_fil(fd);
527-
528- postres = postresdata_new();
529- if (postres == NULL) {
530- del_fil(NULL, &test_lnk, 0);
531- return UNITTEST_RESULT_FAIL;
532- }
533- err = postresdata_readfile(postres, (VLINK *)&test_lnk);
534- if (err < 0) {
535- postresdata_delete(postres);
536- del_fil(NULL, &test_lnk, 0);
537- return UNITTEST_RESULT_FAIL;
538- }
539- err = postresdata_gennamemail(postres, &name, &name_len, &mail, &mail_len);
540- if (err < 0) {
541- postresdata_delete(postres);
542- del_fil(NULL, &test_lnk, 0);
543- return UNITTEST_RESULT_FAIL;
544- }
545- postresdata_delete(postres);
546-
547- if (name_len != expected_name_len) {
548- printf("name length different\n");
549- result = UNITTEST_RESULT_FAIL;
550- } else {
551- if (strncmp(name, expected_name, expected_name_len) != 0) {
552- printf("name string different\n");
553- result = UNITTEST_RESULT_FAIL;
554- } else {
555- result = UNITTEST_RESULT_PASS;
556- }
557- }
558- if (mail_len != expected_mail_len) {
559- printf("mail length different\n");
560- result = UNITTEST_RESULT_FAIL;
561- } else {
562- if (strncmp(mail, expected_mail, expected_mail_len) != 0) {
563- printf("mail string different\n");
564- result = UNITTEST_RESULT_FAIL;
565- } else {
566- result = UNITTEST_RESULT_PASS;
567- }
568- }
569- if (result != UNITTEST_RESULT_PASS) {
570- printf("length: generated = %d, expected = %d\n", name_len, expected_name_len);
571- printf("string\n");
572- printf(" generated name: ");
573- SJSTRING_DP(name, name_len);
574- printf("\n");
575- printf(" expected name: ");
576- SJSTRING_DP(expected_name, expected_name_len);
577- printf("\n");
578- printf("length: generated = %d, expected = %d\n", mail_len, expected_mail_len);
579- printf("string\n");
580- printf(" generated mail: ");
581- SJSTRING_DP(mail, mail_len);
582- printf("\n");
583- printf(" expected mail: ");
584- SJSTRING_DP(expected_mail, expected_mail_len);
585- printf("\n");
586- }
587-
588- free(mail);
589- free(name);
590-
591- del_fil(NULL, &test_lnk, 0);
592-
593- return result;
594-}
595-
596-LOCAL UNITTEST_RESULT test_gennamemail_1()
597-{
598- UB *testdata = test_genrequestbody_testdata01;
599- W testdata_len = sizeof(test_genrequestbody_testdata01);
600- UB expected_name[] = "%82%8E%82%81%82%8D%82%85";
601- UB expected_mail[] = "%82%8D%82%81%82%89%82%8C";
602-
603- return test_gennamemail_checkdata(testdata, testdata_len, expected_name, strlen(expected_name), expected_mail, strlen(expected_mail));
604-}
605-
606-LOCAL UNITTEST_RESULT test_gennamemail_2()
607-{
608- UB *testdata = test_genrequestbody_testdata02;
609- W testdata_len = sizeof(test_genrequestbody_testdata02);
610- UB expected_name[] = "";
611- UB expected_mail[] = "%82%8D%82%81%82%89%82%8C";
612-
613- return test_gennamemail_checkdata(testdata, testdata_len, expected_name, strlen(expected_name), expected_mail, strlen(expected_mail));
614-}
615-
616-LOCAL UNITTEST_RESULT test_gennamemail_3()
617-{
618- UB *testdata = test_genrequestbody_testdata03;
619- W testdata_len = sizeof(test_genrequestbody_testdata03);
620- UB expected_name[] = "%82%8E%82%81%82%8D%82%85";
621- UB expected_mail[] = "";
622-
623- return test_gennamemail_checkdata(testdata, testdata_len, expected_name, strlen(expected_name), expected_mail, strlen(expected_mail));
624-}
625-
626-LOCAL UNITTEST_RESULT test_gennamemail_4()
627-{
628- UB *testdata = test_genrequestbody_testdata04;
629- W testdata_len = sizeof(test_genrequestbody_testdata04);
630- UB expected_name[] = "";
631- UB expected_mail[] = "";
632-
633- return test_gennamemail_checkdata(testdata, testdata_len, expected_name, strlen(expected_name), expected_mail, strlen(expected_mail));
634-}
635-
636507 EXPORT VOID test_postres_main(unittest_driver_t *driver)
637508 {
638509 UNITTEST_DRIVER_REGIST(driver, test_genrequestbody_1);
@@ -641,8 +512,4 @@
641512 UNITTEST_DRIVER_REGIST(driver, test_genrequestbody_4);
642513 UNITTEST_DRIVER_REGIST(driver, test_genrequestbody_5);
643514 UNITTEST_DRIVER_REGIST(driver, test_genrequestbody_6);
644- UNITTEST_DRIVER_REGIST(driver, test_gennamemail_1);
645- UNITTEST_DRIVER_REGIST(driver, test_gennamemail_2);
646- UNITTEST_DRIVER_REGIST(driver, test_gennamemail_3);
647- UNITTEST_DRIVER_REGIST(driver, test_gennamemail_4);
648515 }
--- bchan/trunk/src/postres.c (revision 668)
+++ bchan/trunk/src/postres.c (revision 669)
@@ -1,7 +1,7 @@
11 /*
22 * postres.c
33 *
4- * Copyright (c) 2009-2011 project bchan
4+ * Copyright (c) 2009-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -35,6 +35,8 @@
3535 #include <btron/hmi.h>
3636 #include <btron/tf.h>
3737
38+#include <coding/htmlform_urlencoder.h>
39+
3840 #include "postres.h"
3941 #include "sjisstring.h"
4042 #include "tadimf.h"
@@ -211,7 +213,7 @@
211213 return err;
212214 }
213215
214- err = sjstring_appendurlencodestring(dest, dlen, buf, buf_len);
216+ err = sjstring_appendasciistring(dest, dlen, buf, buf_len);
215217 free(buf);
216218
217219 return err;
@@ -330,130 +332,69 @@
330332 return sjstring_appendasciistring(dest, dest_len, str, len);
331333 }
332334
335+#define POST_FIELDS (7)
336+
333337 struct postresdata_genbodycontext_t_ {
334338 postresdata_t *post;
335- UB *board;
336- W board_len;
337- UB *thread;
338- W thread_len;
339- STIME time;
340- enum {
341- POSTRESDATA_GENBODYCONTEXT_STATE_NAME_BBS,
342- POSTRESDATA_GENBODYCONTEXT_STATE_BOARD,
343- POSTRESDATA_GENBODYCONTEXT_STATE_NAME_KEY,
344- POSTRESDATA_GENBODYCONTEXT_STATE_THREAD,
345- POSTRESDATA_GENBODYCONTEXT_STATE_NAME_TIME,
346- POSTRESDATA_GENBODYCONTEXT_STATE_TIME,
347- POSTRESDATA_GENBODYCONTEXT_STATE_NAME_FROM,
348- POSTRESDATA_GENBODYCONTEXT_STATE_FROM,
349- POSTRESDATA_GENBODYCONTEXT_STATE_NAME_MAIL,
350- POSTRESDATA_GENBODYCONTEXT_STATE_MAIL,
351- POSTRESDATA_GENBODYCONTEXT_STATE_NAME_MESSAGE,
352- POSTRESDATA_GENBODYCONTEXT_STATE_MESSAGE,
353- POSTRESDATA_GENBODYCONTEXT_STATE_NAME_SUBMIT,
354- POSTRESDATA_GENBODYCONTEXT_STATE_END
355- } state;
356339 UB timebuf[10];
340+ htmlform_field fields[POST_FIELDS];
341+ htmlform_urlencoder_t encoder;
357342 } ;
358343 typedef struct postresdata_genbodycontext_t_ postresdata_genbodycontext_t;
359344
360-LOCAL UB name_bbs[] = "bbs=";
361-LOCAL UB name_key[] = "&key=";
362-LOCAL UB name_time[] = "&time=";
363-LOCAL UB name_FROM[] = "&FROM=";
364-LOCAL UB name_mail[] = "&mail=";
365-LOCAL UB name_MESSAGE[] = "&MESSAGE=";
366-LOCAL UB name_submit[] = "&submit=%8F%91%82%AB%8D%9E%82%DE";
345+LOCAL UB name_bbs[] = "bbs";
346+LOCAL UB name_key[] = "key";
347+LOCAL UB name_time[] = "time";
348+LOCAL UB name_FROM[] = "FROM";
349+LOCAL UB name_mail[] = "mail";
350+LOCAL UB name_MESSAGE[] = "MESSAGE";
351+LOCAL UB name_submit[] = "submit";
352+LOCAL UB value_submit[] = { 0x8F, 0x91, 0x82, 0xAB, 0x8D, 0x9E, 0x82, 0xDE };
367353
368354 LOCAL Bool postresdata_genbodycontext_next(postresdata_genbodycontext_t *ctx, UB **str, W *len)
369355 {
370- switch (ctx->state) {
371- case POSTRESDATA_GENBODYCONTEXT_STATE_NAME_BBS:
372- *str = name_bbs;
373- *len = strlen(name_bbs);
374- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_BOARD;
375- return True;
376- case POSTRESDATA_GENBODYCONTEXT_STATE_BOARD:
377- *str = ctx->board;
378- *len = ctx->board_len;
379- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_NAME_KEY;
380- return True;
381- case POSTRESDATA_GENBODYCONTEXT_STATE_NAME_KEY:
382- *str = name_key;
383- *len = strlen(name_key);
384- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_THREAD;
385- return True;
386- case POSTRESDATA_GENBODYCONTEXT_STATE_THREAD:
387- *str = ctx->thread;
388- *len = ctx->thread_len;
389- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_NAME_TIME;
390- return True;
391- case POSTRESDATA_GENBODYCONTEXT_STATE_NAME_TIME:
392- *str = name_time;
393- *len = strlen(name_time);
394- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_TIME;
395- return True;
396- case POSTRESDATA_GENBODYCONTEXT_STATE_TIME:
397- *str = ctx->timebuf;
398- *len = sjstring_writeUWstring(ctx->timebuf, ctx->time + 473385600);
399- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_NAME_FROM;
400- return True;
401- case POSTRESDATA_GENBODYCONTEXT_STATE_NAME_FROM:
402- *str = name_FROM;
403- *len = strlen(name_FROM);
404- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_FROM;
405- return True;
406- case POSTRESDATA_GENBODYCONTEXT_STATE_FROM:
407- *str = ctx->post->asc_from;
408- *len = ctx->post->asc_from_len;
409- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_NAME_MAIL;
410- return True;
411- case POSTRESDATA_GENBODYCONTEXT_STATE_NAME_MAIL:
412- *str = name_mail;
413- *len = strlen(name_mail);
414- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_MAIL;
415- return True;
416- case POSTRESDATA_GENBODYCONTEXT_STATE_MAIL:
417- *str = ctx->post->asc_mail;
418- *len = ctx->post->asc_mail_len;
419- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_NAME_MESSAGE;
420- return True;
421- case POSTRESDATA_GENBODYCONTEXT_STATE_NAME_MESSAGE:
422- *str = name_MESSAGE;
423- *len = strlen(name_MESSAGE);
424- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_MESSAGE;
425- return True;
426- case POSTRESDATA_GENBODYCONTEXT_STATE_MESSAGE:
427- *str = ctx->post->asc_message;
428- *len = ctx->post->asc_message_len;
429- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_NAME_SUBMIT;
430- return True;
431- case POSTRESDATA_GENBODYCONTEXT_STATE_NAME_SUBMIT:
432- *str = name_submit;
433- *len = strlen(name_submit);
434- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_END;
435- return True;
436- case POSTRESDATA_GENBODYCONTEXT_STATE_END:
437- default:
438- }
439- *str = NULL;
440- *len = 0;
441- return False;
356+ return htmlform_urlencoder_next(&ctx->encoder, str, len);
442357 }
443358
444359 LOCAL VOID postresdata_genbodycontext_initialize(postresdata_genbodycontext_t *ctx, postresdata_t *post, UB *board, W board_len, UB *thread, W thread_len, STIME time)
445360 {
446361 ctx->post = post;
447- ctx->board = board;
448- ctx->board_len = board_len;
449- ctx->thread = thread;
450- ctx->thread_len = thread_len;
451- ctx->time = time;
452- ctx->state = POSTRESDATA_GENBODYCONTEXT_STATE_NAME_BBS;
362+
363+ ctx->fields[0].name = name_bbs;
364+ ctx->fields[0].name_len = strlen(name_bbs);
365+ ctx->fields[0].value = board;
366+ ctx->fields[0].value_len = board_len;
367+ ctx->fields[1].name = name_key;
368+ ctx->fields[1].name_len = strlen(name_key);
369+ ctx->fields[1].value = thread;
370+ ctx->fields[1].value_len = thread_len;
371+ ctx->fields[2].name = name_time;
372+ ctx->fields[2].name_len = strlen(name_time);
373+ ctx->fields[2].value = ctx->timebuf;
374+ ctx->fields[2].value_len = sjstring_writeUWstring(ctx->timebuf, time + 473385600);
375+ ctx->fields[3].name = name_FROM;
376+ ctx->fields[3].name_len = strlen(name_FROM);
377+ ctx->fields[3].value = ctx->post->asc_from;
378+ ctx->fields[3].value_len = ctx->post->asc_from_len;
379+ ctx->fields[4].name = name_mail;
380+ ctx->fields[4].name_len = strlen(name_mail);
381+ ctx->fields[4].value = ctx->post->asc_mail;
382+ ctx->fields[4].value_len = ctx->post->asc_mail_len;
383+ ctx->fields[5].name = name_MESSAGE;
384+ ctx->fields[5].name_len = strlen(name_MESSAGE);
385+ ctx->fields[5].value = ctx->post->asc_message;
386+ ctx->fields[5].value_len = ctx->post->asc_message_len;
387+ ctx->fields[6].name = name_submit;
388+ ctx->fields[6].name_len = strlen(name_submit);
389+ ctx->fields[6].value = value_submit;
390+ ctx->fields[6].value_len = strlen(value_submit);
391+
392+ htmlform_urlencoder_initialize(&ctx->encoder, ctx->fields, POST_FIELDS);
453393 }
454394
455395 LOCAL VOID postresdata_genbodycontext_finalize(postresdata_genbodycontext_t *ctx)
456396 {
397+ htmlform_urlencoder_finalize(&ctx->encoder);
457398 }
458399
459400 EXPORT W postresdata_genrequestbody(postresdata_t *post, UB *board, W board_len, UB *thread, W thread_len, STIME time, UB **body, W *body_len)
@@ -498,44 +439,6 @@
498439 return 0;
499440 }
500441
501-EXPORT W postresdata_gennamemail(postresdata_t *post, UB **name, W *name_len, UB **mail, W *mail_len)
502-{
503- UB *buf_name = NULL, *buf_mail = NULL;
504- W err, buf_name_len = 0, buf_mail_len = 0;
505-
506- buf_name = malloc(sizeof(UB));
507- if (buf_name == NULL) {
508- return -1;
509- }
510- buf_name[0] = '\0';
511- buf_mail = malloc(sizeof(UB));
512- if (buf_mail == NULL) {
513- free(buf_name);
514- return -1;
515- }
516- buf_mail[0] = '\0';
517-
518- err = postresdata_appendasciistring(&buf_name, &buf_name_len, post->asc_from, post->asc_from_len);
519- if (err < 0) {
520- free(buf_mail);
521- free(buf_name);
522- return err;
523- }
524- err = postresdata_appendasciistring(&buf_mail, &buf_mail_len, post->asc_mail, post->asc_mail_len);
525- if (err < 0) {
526- free(buf_mail);
527- free(buf_name);
528- return err;
529- }
530-
531- *name = buf_name;
532- *name_len = buf_name_len;
533- *mail = buf_mail;
534- *mail_len = buf_mail_len;
535-
536- return 0;
537-}
538-
539442 EXPORT postresdata_t* postresdata_new()
540443 {
541444 postresdata_t *post;
--- bchan/trunk/src/postres.h (revision 668)
+++ bchan/trunk/src/postres.h (revision 669)
@@ -1,7 +1,7 @@
11 /*
22 * postres.h
33 *
4- * Copyright (c) 2009-2011 project bchan
4+ * Copyright (c) 2009-2015 project bchan
55 *
66 * This software is provided 'as-is', without any express or implied
77 * warranty. In no event will the authors be held liable for any damages
@@ -36,7 +36,6 @@
3636 IMPORT VOID postresdata_delete(postresdata_t *post);
3737 IMPORT W postresdata_readfile(postresdata_t *post, VLINK *vlnk);
3838 IMPORT W postresdata_genrequestbody(postresdata_t *post, UB *board, W board_len, UB *thread, W thread_len, STIME time, UB **body, W *body_len);
39-IMPORT W postresdata_gennamemail(postresdata_t *post, UB **name, W *name_len, UB **mail, W *mail_len);
4039 IMPORT TC* postresdata_getfromstring(postresdata_t *post);
4140 IMPORT W postresdata_getfromstringlen(postresdata_t *post);
4241 IMPORT TC* postresdata_getmailstring(postresdata_t *post);
Show on old repository browser