2 * Copyright (c) 2016-2018 S. Gilles <sgilles@math.umd.edu>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 #include <curl/curl.h>
27 #include <yajl_parse.h>
32 int main(int argc
, char **argv
)
40 long long target_ll
= 0;
42 uint_fast8_t purge_arg
= 0;
45 struct curl_httppost
*post
= 0;
46 struct curl_httppost
*postend
= 0;
50 setlocale(LC_ALL
, "");
52 while ((opt
= getopt(argc
, argv
, "c:g:t:p")) != -1) {
73 fprintf(stderr
, "course-id is mandatory\n");
80 fprintf(stderr
, "one of -t, -p is mandatory\n");
82 } else if (target_arg
&&
84 fprintf(stderr
, "both -t and -p provided, ignoring -p\n");
88 curl_global_init(CURL_GLOBAL_DEFAULT
);
90 if (!(url_base
= get_url_base())) {
93 /* Error should have already been printed */
97 if (!(auth_token
= get_auth_token())) {
100 /* Error should have already been printed */
105 target_ll
= strtoll(target_arg
, 0, 0);
106 len
= snprintf(0, 0, "%lld", target_ll
);
109 ret
= errno
= EOVERFLOW
;
114 if (!(target
= malloc(len
+ 1))) {
120 sprintf(target
, "%lld", target_ll
);
122 if (curl_formadd(&post
, &postend
, CURLFORM_PTRNAME
,
123 "move_assignments_to", CURLFORM_PTRCONTENTS
,
127 perror(L("curl_formadd"));
132 len
= snprintf(0, 0, "%s/api/v1/courses/%s/assignment_groups/%s",
133 url_base
, course_id
, group_id
);
136 ret
= errno
= EOVERFLOW
;
141 if (!(built_uri
= malloc(len
+ 1))) {
147 sprintf(built_uri
, "%s/api/v1/courses/%s/assignment_groups/%s",
148 url_base
, course_id
, group_id
);
150 if ((ret
= send_and_id_scan(built_uri
, auth_token
, post
, "DELETE",
156 printf("%s\n", deleted_id
);
167 curl_global_cleanup();