3131#include "azure_blob_uri.h"
3232#include "azure_blob_http.h"
3333
34- flb_sds_t azb_block_blob_blocklist_uri (struct flb_azure_blob * ctx , char * name )
34+ flb_sds_t azb_block_blob_blocklist_uri (struct flb_azure_blob * ctx ,
35+ const char * path_prefix ,
36+ char * name )
3537{
3638 flb_sds_t uri ;
39+ const char * effective_path ;
3740
3841 uri = azb_uri_container (ctx );
3942 if (!uri ) {
4043 return NULL ;
4144 }
4245
43- if (ctx -> path ) {
46+ effective_path = (path_prefix && path_prefix [0 ] != '\0' ) ? path_prefix : ctx -> path ;
47+
48+ if (effective_path && effective_path [0 ] != '\0' ) {
4449 flb_sds_printf (& uri , "/%s/%s?comp=blocklist" ,
45- ctx -> path , name );
50+ effective_path , name );
4651 }
4752 else {
4853 flb_sds_printf (& uri , "/%s?comp=blocklist" , name );
@@ -55,13 +60,18 @@ flb_sds_t azb_block_blob_blocklist_uri(struct flb_azure_blob *ctx, char *name)
5560 return uri ;
5661}
5762
58- flb_sds_t azb_block_blob_uri (struct flb_azure_blob * ctx , char * name ,
59- char * blockid , uint64_t ms , char * random_str )
63+ flb_sds_t azb_block_blob_uri (struct flb_azure_blob * ctx ,
64+ const char * path_prefix ,
65+ char * name ,
66+ char * blockid ,
67+ uint64_t ms ,
68+ char * random_str )
6069{
6170 int len ;
6271 flb_sds_t uri ;
6372 char * ext ;
6473 char * encoded_blockid ;
74+ const char * effective_path ;
6575
6676 len = strlen (blockid );
6777 encoded_blockid = azb_uri_encode (blockid , len );
@@ -82,14 +92,16 @@ flb_sds_t azb_block_blob_uri(struct flb_azure_blob *ctx, char *name,
8292 ext = "" ;
8393 }
8494
85- if (ctx -> path ) {
95+ effective_path = (path_prefix && path_prefix [0 ] != '\0' ) ? path_prefix : ctx -> path ;
96+
97+ if (effective_path && effective_path [0 ] != '\0' ) {
8698 if (ms > 0 ) {
8799 flb_sds_printf (& uri , "/%s/%s.%s.%" PRIu64 "%s?blockid=%s&comp=block" ,
88- ctx -> path , name , random_str , ms , ext , encoded_blockid );
100+ effective_path , name , random_str , ms , ext , encoded_blockid );
89101 }
90102 else {
91103 flb_sds_printf (& uri , "/%s/%s.%s%s?blockid=%s&comp=block" ,
92- ctx -> path , name , random_str , ext , encoded_blockid );
104+ effective_path , name , random_str , ext , encoded_blockid );
93105 }
94106 }
95107 else {
@@ -112,10 +124,14 @@ flb_sds_t azb_block_blob_uri(struct flb_azure_blob *ctx, char *name,
112124}
113125
114126flb_sds_t azb_block_blob_uri_commit (struct flb_azure_blob * ctx ,
115- char * tag , uint64_t ms , char * str )
127+ const char * path_prefix ,
128+ char * tag ,
129+ uint64_t ms ,
130+ char * str )
116131{
117132 char * ext ;
118133 flb_sds_t uri ;
134+ const char * effective_path ;
119135
120136 uri = azb_uri_container (ctx );
121137 if (!uri ) {
@@ -129,9 +145,13 @@ flb_sds_t azb_block_blob_uri_commit(struct flb_azure_blob *ctx,
129145 ext = "" ;
130146 }
131147
132- if (ctx -> path ) {
133- flb_sds_printf (& uri , "/%s/%s.%s.%" PRIu64 "%s?comp=blocklist" , ctx -> path , tag , str ,
134- ms , ext );
148+ effective_path = (path_prefix && path_prefix [0 ] != '\0' ) ? path_prefix : ctx -> path ;
149+
150+ if (effective_path && effective_path [0 ] != '\0' ) {
151+ flb_sds_printf (& uri ,
152+ "/%s/%s.%s.%" PRIu64 "%s?comp=blocklist" ,
153+ effective_path , tag , str ,
154+ ms , ext );
135155 }
136156 else {
137157 flb_sds_printf (& uri , "/%s.%s.%" PRIu64 "%s?comp=blocklist" , tag , str , ms , ext );
@@ -331,14 +351,19 @@ int azb_block_blob_put_block_list(struct flb_azure_blob *ctx, flb_sds_t uri, flb
331351}
332352
333353/* Commit a single block */
334- int azb_block_blob_commit_block (struct flb_azure_blob * ctx , char * blockid , char * tag , uint64_t ms , char * str )
354+ int azb_block_blob_commit_block (struct flb_azure_blob * ctx ,
355+ const char * path_prefix ,
356+ char * blockid ,
357+ char * tag ,
358+ uint64_t ms ,
359+ char * str )
335360{
336361 int ret ;
337362 flb_sds_t uri = NULL ;
338363 flb_sds_t payload ;
339364
340365 /* Compose commit URI */
341- uri = azb_block_blob_uri_commit (ctx , tag , ms , str );
366+ uri = azb_block_blob_uri_commit (ctx , path_prefix , tag , ms , str );
342367 if (!uri ) {
343368 return FLB_ERROR ;
344369 }
@@ -419,7 +444,7 @@ int azb_block_blob_commit_file_parts(struct flb_azure_blob *ctx, uint64_t file_i
419444 cfl_sds_cat_safe (& payload , "</BlockList>" , 12 );
420445 flb_utils_split_free (list );
421446
422- uri = azb_block_blob_blocklist_uri (ctx , path );
447+ uri = azb_block_blob_blocklist_uri (ctx , NULL , path );
423448 if (!uri ) {
424449 flb_sds_destroy (payload );
425450 return -1 ;
0 commit comments