- struct json_object *content, *rp, *error, *sid, *rq;
- char *tmp;
-
- if (session_url)
- free(session_url);
-
- tmp = url_normalize(url);
- session_url = malloc(strlen(tmp) + strlen("/api/") + 1);
- strcpy(session_url, tmp);
- strcat(session_url, "/api/");
- free(tmp);
-
-
- rq = create_op("login");
- json_object_object_add(rq, "user", json_object_new_string(user));
- json_object_object_add(rq,
- "password",
- json_object_new_string(password));
-
- rp = post_json_object(session_url, rq);
- json_object_put(rq);
-
- content = json_object_object_get(rp, "content");
- if (!content) {
- fprintf(stderr, "Login failed: no content\n");
- return ;
- }
-
- error = json_object_object_get(content, "error");
- if (error) {
- fprintf(stderr, "Login failed\n");
- return ;
- }
-
- sid = json_object_object_get(content, "session_id");
-
- if (session_id) {
- free(session_id);
- session_id = NULL;
- }
-
- session_id = strdup(json_object_get_string(sid));
-
- printf("Session id: %s\n", session_id);