void create_canonical_request(List *headers, char *payload, char **canonical_request) { if (NULL == headers || NULL == payload) { puts("Invalid headers or payload list"); return; } char *header_names_line = "connection;content-length;content-type;host;user-agent;x-amz-date;x-amz-target"; char *hash_payload; hash_sha256(payload, strlen(payload), &hash_payload); if (NULL == hash_payload) { puts("Failed to generate hash payload"); return; } List *canonical_request_lines = (List *)calloc(1, sizeof(List)); add_new_item_with_data(canonical_request_lines, "POST", 4); add_new_item_with_data(canonical_request_lines, "/", 1); add_new_item_with_data(canonical_request_lines, "", 0); listcat(canonical_request_lines, headers); add_new_item_with_data(canonical_request_lines, "", 0); add_new_item_with_data(canonical_request_lines, header_names_line, strlen(header_names_line)); add_new_item_with_data(canonical_request_lines, hash_payload, 2*32); *canonical_request = join_all_lines(canonical_request_lines, "\n"); free_list(canonical_request_lines); }
////////////////////////////////////////////////////////////////////// // // unit-rmqueue.c - unit test to evaluate queue remove functionality. // // prerequisites: to successfully run this unit test, both the // mkqueue() and rmqueue() functions must be fully // operational. // // list manipulation is performed by provided // support functions (src/support/) // int main() { ////////////////////////////////////////////////////////////////// // // Declare unit test variables // Queue *qtmp = NULL; List *ltmp = NULL; Node *ntmp = NULL; int testno = 0; int i = 0; code_t result = 0; ulli queue_size = 7; ////////////////////////////////////////////////////////////////// // // Display unit test header // fprintf(stdout, "===========================================\n"); fprintf(stdout, "UNIT TEST: queue library rmqueue() function\n"); fprintf(stdout, "===========================================\n"); ////////////////////////////////////////////////////////////////// // // First test: Evaluate NULL pointer // result = rmqueue(NULL); fprintf(stdout, "Test %d: Running rmqueue() on NULL pointer ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_ERROR | DLQ_INVALID); fprintf(stdout, "\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Second test: Evaluate NULL queue // result = rmqueue(&qtmp); fprintf(stdout, "Test %d: Running rmqueue() on NULL queue ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_ERROR | DLQ_NULL); fprintf(stdout, "\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Actually create a new (EMPTY) queue, and call rmqueue() on it // mkqueue(&qtmp, queue_size); fprintf(stdout, "(Before) contents of queue -> data:\n\t"); listcat(qtmp -> data); fprintf(stdout, "\n"); result = rmqueue(&qtmp); fprintf(stdout, "(After) contents of queue -> data:\n\t"); if (qtmp == NULL) listcat(NULL); else listcat(qtmp -> data); fprintf(stdout, "\n"); ////////////////////////////////////////////////////////////////// // // Third test: Verify rmqueue() status code(s) // fprintf(stdout, "Test %d: Checking rmqueue() status on EMPTY queue ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_SUCCESS | DLQ_NULL | DLL_NULL | DLL_SUCCESS); fprintf(stdout, "\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Fourth test: verify that queue is now NULL // fprintf(stdout, "Test %d: Checking queue ...\n", testno++); if (qtmp == NULL) fprintf(stdout, " you have: NULL queue (SUCCESS)\n"); else if (qtmp -> data == NULL) fprintf(stdout, " you have: Queue still exists (ERROR)\n"); else fprintf(stdout, " you have: ERROR state\n"); fprintf(stdout, "should be: NULL queue (SUCCESS)\n\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Create another queue, and populate it (one node), and then // run rmqueue() on it // qtmp = NULL; mkqueue(&qtmp, queue_size-queue_size); ltmp = qtmp -> data; for (i = 0; i < 1; i++) { ntmp = NULL; mknode(&ntmp, i); catnode(<mp, ltmp -> last, ntmp); } qtmp -> data = ltmp; qtmp -> front = qtmp -> data -> first; qtmp -> back = qtmp -> data -> last; fprintf(stdout, "(Before) contents of queue -> data:\n\t"); listcat(qtmp -> data); fprintf(stdout, "\n"); result = rmqueue(&qtmp); fprintf(stdout, "(After) contents of queue -> data:\n\t"); if (qtmp == NULL) listcat(NULL); else listcat(qtmp -> data); fprintf(stdout, "\n"); ////////////////////////////////////////////////////////////////// // // Fifth test: Verify rmqueue() status code(s) // fprintf(stdout, "Test %d: Checking rmqueue() status on EMPTY queue ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_SUCCESS | DLQ_NULL | DLL_NULL | DLL_SUCCESS); fprintf(stdout, "\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Sixth test: Verify that queue is now NULL // fprintf(stdout, "Test %d: Checking queue ...\n", testno++); if (qtmp == NULL) fprintf(stdout, " you have: NULL queue (SUCCESS)\n"); else if (qtmp -> data == NULL) fprintf(stdout, " you have: Queue still exists (ERROR)\n"); else fprintf(stdout, " you have: ERROR state\n"); fprintf(stdout, "should be: NULL queue (SUCCESS)\n\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Create another queue, and populate it (two nodes), and then // run rmqueue() on it // qtmp = NULL; mkqueue(&qtmp, queue_size-queue_size); ltmp = qtmp -> data; for (i = 0; i < 2; i++) { ntmp = NULL; mknode(&ntmp, i); catnode(<mp, ltmp -> last, ntmp); } qtmp -> data = ltmp; qtmp -> front = qtmp -> data -> first; qtmp -> back = qtmp -> data -> last; fprintf(stdout, "(Before) contents of queue -> data:\n\t"); listcat(qtmp -> data); fprintf(stdout, "\n"); result = rmqueue(&qtmp); fprintf(stdout, "(After) contents of queue -> data:\n\t"); if (qtmp == NULL) listcat(NULL); else listcat(qtmp -> data); fprintf(stdout, "\n"); ////////////////////////////////////////////////////////////////// // // Seventh test: Verify rmqueue() status code(s) // fprintf(stdout, "Test %d: Checking rmqueue() status on EMPTY queue ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_SUCCESS | DLQ_NULL | DLL_NULL | DLL_SUCCESS); fprintf(stdout, "\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Eighth test: Verify that queue is now NULL // fprintf(stdout, "Test %d: Checking queue ...\n", testno++); if (qtmp == NULL) fprintf(stdout, " you have: NULL queue (SUCCESS)\n"); else if (qtmp -> data == NULL) fprintf(stdout, " you have: Queue still exists (ERROR)\n"); else fprintf(stdout, " you have: ERROR state\n"); fprintf(stdout, "should be: NULL queue (SUCCESS)\n\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Create another queue, and populate it (many nodes), and then // run rmqueue() on it // mkqueue(&qtmp, queue_size-queue_size); ltmp = qtmp -> data; for (i = 0; i < queue_size; i++) { ntmp = NULL; mknode(&ntmp, i); catnode(<mp, ltmp -> last, ntmp); } qtmp -> data = ltmp; qtmp -> front = qtmp -> data -> first; qtmp -> back = qtmp -> data -> last; fprintf(stdout, "(Before) contents of queue -> data:\n\t"); listcat(qtmp -> data); fprintf(stdout, "\n"); result = rmqueue(&qtmp); fprintf(stdout, "(After) contents of queue -> data:\n\t"); if (qtmp == NULL) listcat(NULL); else listcat(qtmp -> data); fprintf(stdout, "\n"); ////////////////////////////////////////////////////////////////// // // Ninth test: Verify rmqueue() status code(s) // fprintf(stdout, "Test %d: Checking rmqueue() status on EMPTY queue ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_SUCCESS | DLQ_NULL | DLL_NULL | DLL_SUCCESS); fprintf(stdout, "\n"); fflush (stdout); ////////////////////////////////////////////////////////////////// // // Tenth test: Verify that queue is now NULL // fprintf(stdout, "Test %d: Checking queue ...\n", testno++); if (qtmp == NULL) fprintf(stdout, " you have: NULL queue (SUCCESS)\n"); else if (qtmp -> data == NULL) fprintf(stdout, " you have: Queue still exists (ERROR)\n"); else fprintf(stdout, " you have: ERROR state\n"); fprintf(stdout, "should be: NULL queue (SUCCESS)\n\n"); fflush (stdout); fprintf(stdout, "===========================================\n\n"); return(0); }
int main() { Queue *qtmp = NULL; Node *ntmp = NULL; int i = 0; int data[] = { 2, 4, 8, 16, 32, 64 }; int testno = 0; code_t result = 0; fprintf(stdout, "UNIT TEST: queue library purge() function\n"); fprintf(stdout, "=========================================\n"); fprintf(stdout, "Test %d: Checking NULL case ...\n", testno++); result = purge(NULL); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_INVALID | DLQ_ERROR); fflush (stdout); fprintf(stdout, "\nTest %d: Running purge() on NULL queue ...\n", testno++); result = purge(&qtmp); if (qtmp == NULL) fprintf(stdout, " you have: NULL queue\n"); else fprintf(stdout, " you have: non-NULL queue (problem)\n"); fprintf(stdout, "should be: NULL queue\n"); fflush (stdout); fprintf(stdout, "\nTest %d: Checking results ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_NULL | DLQ_ERROR); fflush (stdout); mkqueue(&qtmp, 0); fprintf(stdout, "\nTest %d: Running purge() on EMPTY queue ...\n", testno++); result = purge(&qtmp); if (qtmp == NULL) fprintf(stdout, " you have: NULL queue (problem)\n"); else if ((qtmp -> front == NULL) && (qtmp -> back == NULL)) { fprintf(stdout, " you have: EMPTY queue\n"); } else fprintf(stdout, " you have: non-NULL yet non-EMPTY queue (problem)\n"); fprintf(stdout, "should be: EMPTY queue\n"); fflush (stdout); fprintf(stdout, "\nTest %d: Checking results ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_EMPTY | DLQ_SUCCESS); fflush (stdout); for (i = 0; i < 6; i++) { ntmp = NULL; mknode (&ntmp, data[i]); catnode(&(qtmp -> data), qtmp -> data -> last, ntmp); } qtmp -> front = qtmp -> data -> first; qtmp -> back = qtmp -> data -> last; fprintf(stdout, "\nPopulated queue:\n"); listcat(qtmp -> data); fprintf(stdout, "\nPopulated queue (reversed):\n"); listtac(qtmp -> data); fprintf(stdout, "\nTest %d: Running purge() on populated queue ...\n", testno++); result = purge(&qtmp); if (qtmp == NULL) fprintf(stdout, " you have: NULL queue (problem)\n"); else if ((qtmp -> front == NULL) && (qtmp -> back == NULL)) { fprintf(stdout, " you have: EMPTY queue\n"); } else fprintf(stdout, " you have: non-NULL yet non-EMPTY queue (problem)\n"); fprintf(stdout, "should be: EMPTY queue\n"); fflush (stdout); fprintf(stdout, "\nTest %d: Checking results ...\n", testno++); fprintf(stdout, " you have: "); lscodes(result); fprintf(stdout, "should be: "); lscodes(DLQ_EMPTY | DLQ_SUCCESS | DLL_EMPTY | DLL_SUCCESS); fflush (stdout); fprintf(stdout, "\nFinal state of queue:\n"); listcat(qtmp -> data); fprintf(stdout, "\nFinal state of queue (reversed):\n"); listtac(qtmp -> data); return(0); }